Skip to content

Commit

Permalink
[IMP] sync' pay 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 4b4e762 commit 45a614f
Show file tree
Hide file tree
Showing 2 changed files with 62 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
61 changes: 61 additions & 0 deletions l10n_br_account_nfe/models/account_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# 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):
self.ensure_one()
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")),
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

Check warning on line 28 in l10n_br_account_nfe/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_account_nfe/models/account_move.py#L28

Added line #L28 was not covered by tests

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

Check warning on line 31 in l10n_br_account_nfe/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_account_nfe/models/account_move.py#L31

Added line #L31 was not covered by tests
else:
create_method = self.env["account.move.line"].create

Check warning on line 33 in l10n_br_account_nfe/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_account_nfe/models/account_move.py#L33

Added line #L33 was not covered by tests

if self.is_sale_document(include_receipts=True) and self.partner_id:
dup_account = (

Check warning on line 36 in l10n_br_account_nfe/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_account_nfe/models/account_move.py#L36

Added line #L36 was not covered by tests
self.partner_id.commercial_partner_id.property_account_receivable_id
)
else:
dup_account = (

Check warning on line 40 in l10n_br_account_nfe/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_account_nfe/models/account_move.py#L40

Added line #L40 was not covered by tests
self.partner_id.commercial_partner_id.property_account_payable_id
)

for dup in self.nfe40_dup:
create_method(

Check warning on line 45 in l10n_br_account_nfe/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_account_nfe/models/account_move.py#L45

Added line #L45 was not covered by tests
{
"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": dup_account.id,
"partner_id": self.partner_id.id,
"exclude_from_invoice_tab": True,
}
)
else:
return super()._recompute_payment_terms_lines()

0 comments on commit 45a614f

Please sign in to comment.