diff --git a/product_variant_sale_price/__manifest__.py b/product_variant_sale_price/__manifest__.py index 43baf374d..2abfa5a4c 100644 --- a/product_variant_sale_price/__manifest__.py +++ b/product_variant_sale_price/__manifest__.py @@ -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", } diff --git a/product_variant_sale_price/data/server_actions.xml b/product_variant_sale_price/data/server_actions.xml new file mode 100644 index 000000000..39992d6ed --- /dev/null +++ b/product_variant_sale_price/data/server_actions.xml @@ -0,0 +1,17 @@ + + + Set price reference + + code + + action + +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}) + + +