[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) <len@odoo.com>
This commit is contained in:
Nans Lefebvre
2019-06-03 13:30:42 +00:00
parent 58d414ec1c
commit ff4f3922a9
+3 -3
View File
@@ -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'):