From a441e89c9fdeed9dfe92da10689c3cc981fead50 Mon Sep 17 00:00:00 2001 From: Nans Lefebvre Date: Thu, 11 Apr 2019 08:11:11 +0000 Subject: [PATCH] [FIX] purchase: update reference onchange of purchase_id Commit 1be873d removed the modification of the reference field from the _onchange_origin. The reasoning was that since this is an onchange on invoice_line_ids, it was applied too often, which annoyed users in the case they overwrote that field. However when using the "Autocomplete" field (purchase_id), then the user expects values to by modified. Before, it worked by setting the origin field, which trickled down to the reference. Since that commit removed this, we re-add it explicitly in that case. opw 1962364 closes odoo/odoo#32656 Signed-off-by: Nans Lefebvre (len) --- addons/purchase/models/account_invoice.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/addons/purchase/models/account_invoice.py b/addons/purchase/models/account_invoice.py index e7e801429d1..6d5cdcdd7ec 100644 --- a/addons/purchase/models/account_invoice.py +++ b/addons/purchase/models/account_invoice.py @@ -79,6 +79,11 @@ class AccountInvoice(models.Model): if not self.partner_id: 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 + new_lines = self.env['account.invoice.line'] for line in self.purchase_id.order_line - self.invoice_line_ids.mapped('purchase_line_id'): data = self._prepare_invoice_line_from_po_line(line)