-
-
Notifications
You must be signed in to change notification settings - Fork 264
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] Add action for choosing a variant as the price reference
- This can be very handy for the website if we want to use not the cheapest variant as the default displayed price. It also reorders the attribute values such that when opening a product on the website, it immediately shows the reference variant.
- Loading branch information
Showing
2 changed files
with
21 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<odoo> | ||
<record model="ir.actions.server" id="set_price_reference"> | ||
<field name="name">Set price reference</field> | ||
<field name="model_id" ref="model_product_product"/> | ||
<field name="state">code</field> | ||
<field name="binding_model_id" ref="model_product_product"/> | ||
<field name="binding_type">action</field> | ||
<field name="code"> | ||
if len(records) > len(records.mapped("product_tmpl_id")): | ||
raise UserError("You can only set one variant as the price reference of a product.") | ||
for r in records.with_context(skip_update_fix_price=True): | ||
r.product_tmpl_id.write({"list_price": r.fix_price}) | ||
new_seq = min(r.product_tmpl_id.attribute_line_ids.mapped("value_ids.sequence") or [r.fix_price]) | ||
r.mapped("product_template_variant_value_ids.product_attribute_value_id").write({"sequence": new_seq - 1}) | ||
</field> | ||
</record> | ||
</odoo> |