Skip to content

[FIX] purchase_request: bind name before use in onchange_product_id - #3136

Open
mav-adhoc wants to merge 1 commit into
OCA:18.0from
adhoc-dev:18.0-fix-purchase_request-onchange-unbound-name
Open

[FIX] purchase_request: bind name before use in onchange_product_id#3136
mav-adhoc wants to merge 1 commit into
OCA:18.0from
adhoc-dev:18.0-fix-purchase_request-onchange-unbound-name

Conversation

@mav-adhoc

Copy link
Copy Markdown
Contributor

Bug

onchange_product_id on the make-purchase-order wizard item raised
UnboundLocalError: cannot access local variable 'name' when
keep_description was set.

name was only assigned inside if not self.keep_description:, so when
keep_description is True it stayed unbound and was then read:

  • on the supplier-info branch, f"[...] {p_name if p_name else name}",
    when the matched product.supplierinfo had no product_name;
  • and by the final if name: guard when there was no supplier info and
    the product had no internal reference.

Fix

Always bind name: keep the description already provided on the wizard
line when keep_description is set, otherwise fall back to the product
name. Behaviour for keep_description = False is unchanged.

Test

Added test_onchange_product_id_keep_description: a product without an
internal reference plus a product.supplierinfo with an empty
product_name, keep_description=True, then calls the onchange. It
raises UnboundLocalError on the previous code and passes with the fix.

@mav-adhoc
mav-adhoc force-pushed the 18.0-fix-purchase_request-onchange-unbound-name branch 3 times, most recently from 4a6ff3d to 96b5060 Compare July 24, 2026 16:48
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.
@mav-adhoc
mav-adhoc force-pushed the 18.0-fix-purchase_request-onchange-unbound-name branch from 96b5060 to ff730eb Compare July 24, 2026 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants