Skip to content

Commit

Permalink
* l10n_it_reverse_charge, fix set rc flag
Browse files Browse the repository at this point in the history
  • Loading branch information
GSLabIt committed May 24, 2022
1 parent 5f20297 commit 0283785
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 24 deletions.
30 changes: 6 additions & 24 deletions l10n_it_reverse_charge/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,13 @@
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)
@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")

@api.onchange("tax_ids")
def onchange_rc_tax_ids(self):
self._set_rc_flag(self.move_id)
rc = fields.Boolean("RC", compute="_compute_rc_flag", store=True, readonly=False)


class AccountMove(models.Model):
Expand All @@ -46,20 +42,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,
Expand Down
4 changes: 4 additions & 0 deletions l10n_it_reverse_charge/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* Davide Corio
* Alex Comba <alex.comba@agilebg.com>
* Lorenzo Battistini <lorenzo.battistini@agilebg.com

* `Ooops <https://www.ooops404.com>`_:

* Giovanni Serra <giovanni@gslab.it>

0 comments on commit 0283785

Please sign in to comment.