Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0] [fix] l10n_it_reverse_charge, l10n_it_fatturapa_in_rc - rc flag in move line #2813

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions l10n_it_fatturapa_in_rc/models/account_invoice.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
4 changes: 4 additions & 0 deletions l10n_it_fatturapa_in_rc/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* Sergio Corato <info@efatto.it>
* Lorenzo Battistini <https://github.com/eLBati>
* Marco Colombo <https://github.com/TheMule71>

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

* Giovanni Serra <giovanni@gslab.it>
38 changes: 14 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,21 @@
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.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():
line.rc = bool(line.move_id.fiscal_position_id.rc_type_id)

@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, default=False
)


class AccountMove(models.Model):
Expand All @@ -46,20 +50,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>