From d29c2dbbddb2e7407e714b0bb11ffdf6fa317672 Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Mon, 22 Jan 2018 16:19:23 +0100 Subject: [PATCH] [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':