From adad192cc0018ce6838feb2a954044ee0b623841 Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Fri, 19 Jan 2018 12:02:04 +0100 Subject: [PATCH 1/2] [FIX] account: reconciliation on payment terms The case: create an invoice of 2000 euros. Payment terms have been configured as: 1) fixed amount 150, 0 days after invoice date. 2) fixed amount 200, 10 days after invoice date. 3) fixed amount 200, 20 days after invoice date. 4) balance, 30 days after invoice date Before this commit, when issuing a payment of 150 at day 0, that payment got reconciled with the balance line. After this commit, the payment is reconciled with the right payment term line OPW 805006 --- addons/account/models/account_move.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index a31acf43e84..a3c37846348 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -799,7 +799,7 @@ class AccountMoveLine(models.Model): elif self._context.get('skip_full_reconcile_check') == 'amount_currency_only': field = 'amount_residual_currency' #target the pair of move in self that are the oldest - sorted_moves = sorted(self, key=lambda a: a.date) + sorted_moves = sorted(self, key=lambda a: a.date_maturity or a.date) debit = credit = False for aml in sorted_moves: if credit and debit: From d29c2dbbddb2e7407e714b0bb11ffdf6fa317672 Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Mon, 22 Jan 2018 16:19:23 +0100 Subject: [PATCH 2/2] [FIX] account: no payment terms on refund In the case where: create an invoice with payment terms that contains at least 2 term lines Validate create a refund by clicking cancel and reconcile Before this commit, the refund move lines were wrongly created and reconciled with the invoice's move lines After this commit, since payment terms are irrelevant on refunds, we set it to false and the problem doesn't raise OPW 804752 --- addons/account/models/account_invoice.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index 5b09af3be43..f653941e7b6 100644 --- a/addons/account/models/account_invoice.py +++ b/addons/account/models/account_invoice.py @@ -985,6 +985,7 @@ class AccountInvoice(models.Model): values['state'] = 'draft' values['number'] = False values['origin'] = invoice.number + values['payment_term_id'] = False if date: values['date'] = date @@ -1365,6 +1366,7 @@ class AccountPaymentTerm(models.Model): def compute(self, value, date_ref=False): date_ref = date_ref or fields.Date.today() amount = value + sign = value < 0 and -1 or 1 result = [] if self.env.context.get('currency_id'): currency = self.env['res.currency'].browse(self.env.context['currency_id']) @@ -1373,7 +1375,7 @@ class AccountPaymentTerm(models.Model): prec = currency.decimal_places for line in self.line_ids: if line.value == 'fixed': - amt = round(line.value_amount, prec) + amt = sign * round(line.value_amount, prec) elif line.value == 'percent': amt = round(value * (line.value_amount / 100.0), prec) elif line.value == 'balance':