Skip to content

Commit

Permalink
[IMP] Add action for choosing a variant as the price reference
Browse files Browse the repository at this point in the history
- 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
ecino committed Jun 20, 2023
1 parent 943ffb7 commit c6d7ccf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
5 changes: 4 additions & 1 deletion product_variant_sale_price/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"license": "AGPL-3",
"installable": True,
"depends": ["account", "sale"],
"data": ["views/product_views.xml"],
"data": [
"data/server_actions.xml",
"views/product_views.xml"
],
"post_init_hook": "set_sale_price_on_variant",
}
17 changes: 17 additions & 0 deletions product_variant_sale_price/data/server_actions.xml
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>

0 comments on commit c6d7ccf

Please sign in to comment.