Skip to content

Commit

Permalink
[MIG] product_variant_sale_price: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ecino committed Jun 5, 2023
1 parent 83f2b58 commit bfccc61
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 60 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Available addons
addon | version | maintainers | summary
--- | --- | --- | ---
[product_variant_default_code](product_variant_default_code/) | 16.0.1.0.2 | [![Kev-Roche](https://github.com/Kev-Roche.png?size=30px)](https://github.com/Kev-Roche) | Product Variant Default Code
[product_variant_sale_price](product_variant_sale_price/) | 16.0.1.0.0 | | Allows to write fixed prices in product variants

[//]: # (end addons)

Expand Down
20 changes: 11 additions & 9 deletions product_variant_sale_price/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ Product Variant Sale Price
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fproduct--variant-lightgray.png?logo=github
:target: https://github.com/OCA/product-variant/tree/15.0/product_variant_sale_price
:target: https://github.com/OCA/product-variant/tree/16.0/product_variant_sale_price
:alt: OCA/product-variant
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/product-variant-15-0/product-variant-15-0-product_variant_sale_price
:target: https://translation.odoo-community.org/projects/product-variant-16-0/product-variant-16-0-product_variant_sale_price
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/137/15.0
:alt: Try me on Runbot
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/product-variant&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module allows to handle sale price at product variant level
(product.product) instead of product level (product.template), which is the
default.

This module also hides sale price at product template level when has more than
one variant.
It replaces the extra price configuration with a fix price that can be modified on each variant independently, which
allows setting absolute prices instead of relative ones.

**Table of contents**

Expand All @@ -43,7 +43,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/product-variant/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/product-variant/issues/new?body=module:%20product_variant_sale_price%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/product-variant/issues/new?body=module:%20product_variant_sale_price%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand All @@ -63,6 +63,8 @@ Contributors
* Alex Comba <[email protected]>
* Fabien Bourgeois <[email protected]>
* Vicent Cubells <[email protected]>
* RabbitJon-S73 <[email protected]>
* Emanuel Cino <[email protected]>

Maintainers
~~~~~~~~~~~
Expand All @@ -77,6 +79,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/product-variant <https://github.com/OCA/product-variant/tree/15.0/product_variant_sale_price>`_ project on GitHub.
This module is part of the `OCA/product-variant <https://github.com/OCA/product-variant/tree/16.0/product_variant_sale_price>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
31 changes: 15 additions & 16 deletions product_variant_sale_price/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ def _update_fix_price(self, vals):
if "list_price" in vals:
self.mapped("product_variant_ids").write({"fix_price": vals["list_price"]})

@api.model
@api.model_create_multi
def create(self, vals):
product_tmpl = super().create(vals)
product_tmpl._update_fix_price(vals)
return product_tmpl
records = super().create(vals)
for i, product_tmpl in enumerate(records):
single_vals = vals[i] if isinstance(vals, list) else vals
product_tmpl._update_fix_price(single_vals)
return records

def write(self, vals):
res = super().write(vals)
Expand All @@ -34,27 +36,25 @@ def _compute_lst_price(self):
uom_model = self.env["uom.uom"]
for product in self:
price = product.fix_price or product.list_price
if "uom" in self.env.context:
price = product.uom_id._compute_price(
price, uom_model.browse(self.env.context["uom"])
)
if self.env.context.get("uom"):
context_uom = uom_model.browse(self.env.context["uom"])
price = product.uom_id._compute_price(price, context_uom)
product.lst_price = price

def _compute_list_price(self):
uom_model = self.env["uom.uom"]
for product in self:
price = product.fix_price or product.product_tmpl_id.list_price
if "uom" in self.env.context:
price = product.uom_id._compute_price(
price, uom_model.browse(self.env.context["uom"])
)
if self.env.context.get("uom"):
context_uom = uom_model.browse(self.env.context["uom"])
price = product.uom_id._compute_price(price, context_uom)
product.list_price = price

def _inverse_product_lst_price(self):
uom_model = self.env["uom.uom"]
for product in self:
vals = {}
if "uom" in self.env.context:
if self.env.context.get("uom"):
vals["fix_price"] = product.uom_id._compute_price(
product.lst_price, uom_model.browse(self.env.context["uom"])
)
Expand All @@ -63,9 +63,8 @@ def _inverse_product_lst_price(self):
if product.product_variant_count == 1:
product.product_tmpl_id.list_price = vals["fix_price"]
else:
fix_prices = product.product_tmpl_id.mapped(
"product_variant_ids.fix_price"
)
other_products = product.product_tmpl_id.product_variant_ids - product
fix_prices = other_products.mapped("fix_price") + [product.lst_price]
# for consistency with price shown in the shop
product.product_tmpl_id.with_context(
skip_update_fix_price=True
Expand Down
2 changes: 2 additions & 0 deletions product_variant_sale_price/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
* Alex Comba <[email protected]>
* Fabien Bourgeois <[email protected]>
* Vicent Cubells <[email protected]>
* RabbitJon-S73 <[email protected]>
* Emanuel Cino <[email protected]>
4 changes: 2 additions & 2 deletions product_variant_sale_price/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ This module allows to handle sale price at product variant level
(product.product) instead of product level (product.template), which is the
default.

This module also hides sale price at product template level when has more than
one variant.
It replaces the extra price configuration with a fix price that can be modified on each variant independently, which
allows setting absolute prices instead of relative ones.
14 changes: 8 additions & 6 deletions product_variant_sale_price/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
<title>Product Variant Sale Price</title>
<style type="text/css">

Expand Down Expand Up @@ -367,12 +367,12 @@ <h1 class="title">Product Variant Sale Price</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/product-variant/tree/15.0/product_variant_sale_price"><img alt="OCA/product-variant" src="https://img.shields.io/badge/github-OCA%2Fproduct--variant-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/product-variant-15-0/product-variant-15-0-product_variant_sale_price"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/137/15.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/product-variant/tree/16.0/product_variant_sale_price"><img alt="OCA/product-variant" src="https://img.shields.io/badge/github-OCA%2Fproduct--variant-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/product-variant-16-0/product-variant-16-0-product_variant_sale_price"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/webui/builds.html?repo=OCA/product-variant&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module allows to handle sale price at product variant level
(product.product) instead of product level (product.template), which is the
default.</p>
<p>This module also hides sale price at product template level when has more than
one variant.</p>
<p>It replaces the extra price configuration with a fix price that can be modified on each variant independently, which
allows setting absolute prices instead of relative ones.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
Expand All @@ -390,7 +390,7 @@ <h1><a class="toc-backref" href="#id1">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/product-variant/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/product-variant/issues/new?body=module:%20product_variant_sale_price%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/product-variant/issues/new?body=module:%20product_variant_sale_price%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand All @@ -409,6 +409,8 @@ <h2><a class="toc-backref" href="#id4">Contributors</a></h2>
<li>Alex Comba &lt;<a class="reference external" href="mailto:alex.comba&#64;agilebg.com">alex.comba&#64;agilebg.com</a>&gt;</li>
<li>Fabien Bourgeois &lt;<a class="reference external" href="mailto:fabien&#64;yaltik.com">fabien&#64;yaltik.com</a>&gt;</li>
<li>Vicent Cubells &lt;<a class="reference external" href="mailto:info&#64;obertix.net">info&#64;obertix.net</a>&gt;</li>
<li>RabbitJon-S73 &lt;<a class="reference external" href="mailto:roger&#64;studio73.es">roger&#64;studio73.es</a>&gt;</li>
<li>Emanuel Cino &lt;<a class="reference external" href="mailto:ecino&#64;compassion.ch">ecino&#64;compassion.ch</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand All @@ -418,7 +420,7 @@ <h2><a class="toc-backref" href="#id5">Maintainers</a></h2>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/product-variant/tree/15.0/product_variant_sale_price">OCA/product-variant</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/product-variant/tree/16.0/product_variant_sale_price">OCA/product-variant</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
6 changes: 3 additions & 3 deletions product_variant_sale_price/tests/test_product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ def test_post_init_hook(self):
)

# Flush the records to DB before direct SQL
self.product_blue.flush()
self.product_red.flush()
self.product_template.product_variant_ids.flush_model()
self.product_blue.product_template_attribute_value_ids.flush_model()

set_sale_price_on_variant(self.cr, None, self.product_template.id)
self.product_template.product_variant_ids.invalidate_cache()
self.product_template.product_variant_ids.invalidate_recordset()
self.assertEqual(
self.product_template.list_price + 100.00, self.product_blue.lst_price
)
Expand Down
64 changes: 40 additions & 24 deletions product_variant_sale_price/views/product_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,53 @@
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view" />
<field name="arch" type="xml">
<xpath expr="//field[@name='list_price']" position="attributes">
<attribute name="attrs">{'invisible': [
('product_variant_count', '>', 1)
]}</attribute>
</xpath>
<field name="list_price" position="after">
<div
name="fix_price_tooltip"
attrs="{'invisible': ['|', ('product_variant_count', '=', 1), ('is_product_variant', '=', True)]}"
>
<span
class="text-muted fst-italic"
>Setting the price here will update all variants.</span>
</div>
</field>
</field>
</record>
<record id="product_normal_form_view_default_check" model="ir.ui.view">
<record id="product_variant_easy_edit_price_view" model="ir.ui.view">
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_normal_form_view" />
<field name="inherit_id" ref="product.product_variant_easy_edit_view" />
<field name="arch" type="xml">
<xpath expr="//field[@name='uom_id']" position="after">
<field
name="fix_price"
attrs="{'invisible': [('product_variant_count', '=', 1)]}"
/>
</xpath>
<!-- Make the field editable -->
<field name="lst_price" position="attributes">
<attribute name="attrs" />
</field>
</field>
</record>
<record id="product_variant_easy_edit_price_view" model="ir.ui.view">
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_variant_easy_edit_view" />
<!-- Hide price extra fields, as they are no longer useful -->
<record id="product_template_attribute_value_view_tree" model="ir.ui.view">
<field name="name">product.template.attribute.value.tree.hide.extra</field>
<field name="model">product.template.attribute.value</field>
<field
name="inherit_id"
ref="product.product_template_attribute_value_view_tree"
/>
<field name="arch" type="xml">
<field name="price_extra" position="attributes">
<attribute name="invisible">1</attribute>
</field>
</field>
</record>
<record id="product_template_attribute_value_view_form" model="ir.ui.view">
<field name="name">product.template.attribute.value.form.hide.extra</field>
<field name="model">product.template.attribute.value</field>
<field
name="inherit_id"
ref="product.product_template_attribute_value_view_form"
/>
<field name="arch" type="xml">
<xpath expr="//field[@name='standard_price']" position="before">
<field
name="fix_price"
attrs="{'invisible': [('product_variant_count', '=', 1)]}"
widget='monetary'
options="{'currency_field': 'currency_id', 'field_digits': True}"
/>
</xpath>
<field name="price_extra" position="attributes">
<attribute name="invisible">1</attribute>
</field>
</field>
</record>
</odoo>

0 comments on commit bfccc61

Please sign in to comment.