From ff730eb118ff0cd2d4f1eee97e5c4737ecc1b45f Mon Sep 17 00:00:00 2001 From: mav-adhoc Date: Thu, 23 Jul 2026 19:34:14 +0000 Subject: [PATCH] [FIX] purchase_request: bind name before use in onchange_product_id When keep_description was set, the local variable `name` was only assigned inside the `if not self.keep_description` branch, leaving it unbound. It was then read on the supplier info branch (and by the final `if name:` guard), raising UnboundLocalError as soon as the matched product.supplierinfo had no product_name (or there was no supplier info and the product had no internal reference). Always bind `name`: when keep_description is set keep the description already provided on the wizard line, otherwise fall back to the product name. --- .../wizard/purchase_request_line_make_purchase_order.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/purchase_request/wizard/purchase_request_line_make_purchase_order.py b/purchase_request/wizard/purchase_request_line_make_purchase_order.py index bc4949a8022..89ed2e05794 100644 --- a/purchase_request/wizard/purchase_request_line_make_purchase_order.py +++ b/purchase_request/wizard/purchase_request_line_make_purchase_order.py @@ -383,8 +383,9 @@ class PurchaseRequestLineMakePurchaseOrderItem(models.TransientModel): @api.onchange("product_id") def onchange_product_id(self): if self.product_id: - if not self.keep_description: - name = self.product_id.name + # Always bind ``name`` to avoid UnboundLocalError when + # ``keep_description`` is set. + name = self.name if self.keep_description else self.product_id.name code = self.product_id.code sup_info_id = self.env["product.supplierinfo"].search( [