From c6d7ccfc22fd5f6c644af8b34ffa65f684149718 Mon Sep 17 00:00:00 2001 From: Emanuel Cino Date: Tue, 20 Jun 2023 07:56:04 +0200 Subject: [PATCH] [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. --- product_variant_sale_price/__manifest__.py | 5 ++++- .../data/server_actions.xml | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 product_variant_sale_price/data/server_actions.xml 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}) + + +