From 88396c2c8e3235edc3e696cdf5cba2afc1b3efb5 Mon Sep 17 00:00:00 2001 From: Giovanni Date: Tue, 24 May 2022 11:56:20 +0200 Subject: [PATCH 1/2] * l10n_it_reverse_charge, fix set rc flag --- l10n_it_reverse_charge/models/account_move.py | 34 +++++-------------- .../readme/CONTRIBUTORS.rst | 4 +++ 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/l10n_it_reverse_charge/models/account_move.py b/l10n_it_reverse_charge/models/account_move.py index 465f9a37a64e..59a83e1f0cf1 100644 --- a/l10n_it_reverse_charge/models/account_move.py +++ b/l10n_it_reverse_charge/models/account_move.py @@ -11,17 +11,15 @@ class AccountMoveLine(models.Model): _inherit = "account.move.line" - def _set_rc_flag(self, invoice): - self.ensure_one() - if invoice.is_purchase_document(): - fposition = invoice.fiscal_position_id - self.rc = bool(fposition.rc_type_id) - - rc = fields.Boolean("RC") - - @api.onchange("tax_ids") - def onchange_rc_tax_ids(self): - self._set_rc_flag(self.move_id) + @api.depends("move_id", "move_id.fiscal_position_id", "tax_ids") + def _compute_rc_flag(self): + for line in self.filtered(lambda r: not r.exclude_from_invoice_tab): + if line.move_id.is_purchase_document(): + line.rc = bool(line.move_id.fiscal_position_id.rc_type_id) + + rc = fields.Boolean( + "RC", compute="_compute_rc_flag", store=True, readonly=False, default=False + ) class AccountMove(models.Model): @@ -46,20 +44,6 @@ class AccountMove(models.Model): readonly=True, ) - @api.onchange("fiscal_position_id") - def onchange_rc_fiscal_position_id(self): - for line in self.invoice_line_ids: - line._set_rc_flag(self) - - @api.onchange("partner_id", "company_id") - def _onchange_partner_id(self): - res = super(AccountMove, self)._onchange_partner_id() - # In some cases (like creating the invoice from PO), - # fiscal position's onchange is triggered - # before than being changed by this method. - self.onchange_rc_fiscal_position_id() - return res - def rc_inv_line_vals(self, line): return { "product_id": line.product_id.id, diff --git a/l10n_it_reverse_charge/readme/CONTRIBUTORS.rst b/l10n_it_reverse_charge/readme/CONTRIBUTORS.rst index 7f152fa0d7d9..07c7c4444687 100644 --- a/l10n_it_reverse_charge/readme/CONTRIBUTORS.rst +++ b/l10n_it_reverse_charge/readme/CONTRIBUTORS.rst @@ -1,3 +1,7 @@ * Davide Corio * Alex Comba * Lorenzo Battistini `_: + + * Giovanni Serra From 05ccd55f208deca2c9c11166902052789b7a8412 Mon Sep 17 00:00:00 2001 From: Giovanni Date: Tue, 24 May 2022 15:07:46 +0200 Subject: [PATCH 2/2] * l10n_it_fatturapa_in_rc, fix set rc flag --- l10n_it_fatturapa_in_rc/models/account_invoice.py | 14 ++++++++++---- l10n_it_fatturapa_in_rc/readme/CONTRIBUTORS.rst | 4 ++++ l10n_it_reverse_charge/models/account_move.py | 8 +++++++- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/l10n_it_fatturapa_in_rc/models/account_invoice.py b/l10n_it_fatturapa_in_rc/models/account_invoice.py index 59fd055771a1..7dacb8b46120 100644 --- a/l10n_it_fatturapa_in_rc/models/account_invoice.py +++ b/l10n_it_fatturapa_in_rc/models/account_invoice.py @@ -1,17 +1,23 @@ -from odoo import _, models +from odoo import _, api, models from odoo.tools import float_compare class InvoiceLine(models.Model): _inherit = "account.move.line" - def _set_rc_flag(self, invoice): - self.ensure_one() + @api.depends( + "move_id", + "move_id.move_type", + "move_id.fiscal_position_id", + "move_id.fiscal_position_id.rc_type_id", + "tax_ids", + ) + def _compute_rc_flag(self): if "fatturapa.attachment.in" in self.env.context.get("active_model", []): # this means we are importing an e-invoice, # so RC flag is already set, where needed return - return super(InvoiceLine, self)._set_rc_flag(invoice) + super()._compute_rc_flag() class Invoice(models.Model): diff --git a/l10n_it_fatturapa_in_rc/readme/CONTRIBUTORS.rst b/l10n_it_fatturapa_in_rc/readme/CONTRIBUTORS.rst index ea72e0dcd84b..9e1c095f22b4 100644 --- a/l10n_it_fatturapa_in_rc/readme/CONTRIBUTORS.rst +++ b/l10n_it_fatturapa_in_rc/readme/CONTRIBUTORS.rst @@ -1,3 +1,7 @@ * Sergio Corato * Lorenzo Battistini * Marco Colombo + +* `Ooops `_: + + * Giovanni Serra diff --git a/l10n_it_reverse_charge/models/account_move.py b/l10n_it_reverse_charge/models/account_move.py index 59a83e1f0cf1..6e4ec76a2cc4 100644 --- a/l10n_it_reverse_charge/models/account_move.py +++ b/l10n_it_reverse_charge/models/account_move.py @@ -11,7 +11,13 @@ class AccountMoveLine(models.Model): _inherit = "account.move.line" - @api.depends("move_id", "move_id.fiscal_position_id", "tax_ids") + @api.depends( + "move_id", + "move_id.move_type", + "move_id.fiscal_position_id", + "move_id.fiscal_position_id.rc_type_id", + "tax_ids", + ) def _compute_rc_flag(self): for line in self.filtered(lambda r: not r.exclude_from_invoice_tab): if line.move_id.is_purchase_document():