Skip to content

Commit

Permalink
[IMP] sync' payment terms with NFe dups when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
rvalyi committed Nov 9, 2023
1 parent 8f4086c commit 6ac7899
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions l10n_br_account_nfe/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from . import account_payment_mode
from . import account_move_line
from . import account_move
from . import document
from . import leiauteNFe
53 changes: 53 additions & 0 deletions l10n_br_account_nfe/models/account_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright 2023 Akretion (Raphaẽl Valyi <[email protected]>)
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from odoo import models
from odoo.tools import float_compare


class AccountMove(models.Model):
_inherit = "account.move"

def _recompute_payment_terms_lines(self):
if (
self.imported_document
and self.nfe40_dup
and float_compare(
sum(self.invoice_line_ids.mapped("debit")),
sum(self.nfe40_dup.mapped("nfe40_vDup")),
# self.fiscal_document_id.amount_total,
2,
)
== 0 # only trigger when all NFe lines are added
):

# just like in the original method, remove old terms:
existing_terms_lines = self.line_ids.filtered(
lambda line: line.account_id.user_type_id.type
in ("receivable", "payable")
)
self.line_ids -= existing_terms_lines

if self != self._origin: # is it a draft move?
create_method = self.env["account.move.line"].new
else:
create_method = self.env["account.move.line"].create

for dup in self.nfe40_dup:
create_method(
{
"move_id": self.id,
"name": dup.nfe40_nDup,
"debit": 0.0,
"credit": dup.nfe40_vDup,
"quantity": 1.0,
"amount_currency": -dup.nfe40_vDup,
"date_maturity": dup.nfe40_dVenc,
"currency_id": self.currency_id.id,
"account_id": self.partner_id.property_account_payable_id.id,
"partner_id": self.partner_id.id,
"exclude_from_invoice_tab": True,
}
)
else:
return super()._recompute_payment_terms_lines()

0 comments on commit 6ac7899

Please sign in to comment.