From ff4f3922a9dd018fee7c855894fc27f588dd6dcd Mon Sep 17 00:00:00 2001 From: Nans Lefebvre Date: Mon, 3 Jun 2019 13:26:24 +0000 Subject: [PATCH] [FIX] purchase: fix reference update at onchange Add two PO with references 'XY' and 'Z' to a vendor bill. The reference is computed as 'XY, Z' (with ', ' as separator). Add a PO with reference 'X', the reference becomes 'X' instead of 'XY, Z, X'. There are two variables that may not be defined (vendor_ref and self.reference), and specifically the case where a reference is the prefix of another one is not correctly dealt with. opw 2005825 closes odoo/odoo#33841 Signed-off-by: Nans Lefebvre (len) --- addons/purchase/models/account_invoice.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/purchase/models/account_invoice.py b/addons/purchase/models/account_invoice.py index 151465498a6..946723fa524 100644 --- a/addons/purchase/models/account_invoice.py +++ b/addons/purchase/models/account_invoice.py @@ -80,9 +80,9 @@ class AccountInvoice(models.Model): self.partner_id = self.purchase_id.partner_id.id vendor_ref = self.purchase_id.partner_ref - if vendor_ref: - self.reference = ", ".join([self.reference, vendor_ref]) if ( - self.reference and vendor_ref not in self.reference) else vendor_ref + if vendor_ref and (not self.reference or ( + vendor_ref + ", " not in self.reference and not self.reference.endswith(vendor_ref))): + self.reference = ", ".join([self.reference, vendor_ref]) if self.reference else vendor_ref new_lines = self.env['account.invoice.line'] for line in self.purchase_id.order_line - self.invoice_line_ids.mapped('purchase_line_id'):