Skip to content

Commit

Permalink
[MIG] website_sale_product_minimal_price: Migration to v12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sergio-teruel committed Dec 11, 2019
1 parent 7d4a3f8 commit 71d323a
Show file tree
Hide file tree
Showing 10 changed files with 171 additions and 140 deletions.
22 changes: 15 additions & 7 deletions website_sale_product_minimal_price/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ Website Sale Product Minimal Price
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
:alt: Production/Stable
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fe--commerce-lightgray.png?logo=github
:target: https://github.com/OCA/e-commerce/tree/11.0/website_sale_product_minimal_price
:target: https://github.com/OCA/e-commerce/tree/12.0/website_sale_product_minimal_price
:alt: OCA/e-commerce
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/e-commerce-11-0/e-commerce-11-0-website_sale_product_minimal_price
:target: https://translation.odoo-community.org/projects/e-commerce-12-0/e-commerce-12-0-website_sale_product_minimal_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/113/11.0
:target: https://runbot.odoo-community.org/runbot/113/12.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -50,7 +50,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/e-commerce/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/e-commerce/issues/new?body=module:%20website_sale_product_minimal_price%0Aversion:%2011.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/e-commerce/issues/new?body=module:%20website_sale_product_minimal_price%0Aversion:%2012.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 Down Expand Up @@ -82,6 +82,14 @@ 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/e-commerce <https://github.com/OCA/e-commerce/tree/11.0/website_sale_product_minimal_price>`_ project on GitHub.
.. |maintainer-sergio-teruel| image:: https://github.com/sergio-teruel.png?size=40px
:target: https://github.com/sergio-teruel
:alt: sergio-teruel

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-sergio-teruel|

This module is part of the `OCA/e-commerce <https://github.com/OCA/e-commerce/tree/12.0/website_sale_product_minimal_price>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
8 changes: 3 additions & 5 deletions website_sale_product_minimal_price/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
{
'name': 'Website Sale Product Minimal Price',
'summary': 'Display minimal price for products that has variants',
'version': '11.0.1.0.0',
'development_status': 'Beta',
'version': '12.0.1.0.0',
'development_status': 'Production/Stable',
'maintainers': ['sergio-teruel'],
'category': 'Website',
'website': 'https://github.com/OCA/e-commerce',
'author': 'Tecnativa, Odoo Community Association (OCA)',
Expand All @@ -18,7 +19,4 @@
'views/assets.xml',
'views/templates.xml',
],
'demo': [
'data/demo.xml',
],
}
49 changes: 0 additions & 49 deletions website_sale_product_minimal_price/data/demo.xml

This file was deleted.

43 changes: 16 additions & 27 deletions website_sale_product_minimal_price/i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 11.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-05-07 14:11+0000\n"
"PO-Revision-Date: 2019-05-07 16:13+0200\n"
"POT-Creation-Date: 2019-12-11 23:22+0000\n"
"PO-Revision-Date: 2019-12-12 00:24+0100\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: es\n"
Expand All @@ -18,40 +18,29 @@ msgstr ""
"X-Generator: Poedit 2.0.6\n"

#. module: website_sale_product_minimal_price
#: model:ir.ui.view,arch_db:website_sale_product_minimal_price.products_item
#: model_terms:ir.ui.view,arch_db:website_sale_product_minimal_price.products_item
msgid "<span>From </span>"
msgstr "<span>Desde </span>"

#. module: website_sale_product_minimal_price
#: model:ir.model.fields,field_description:website_sale_product_minimal_price.field_product_product_has_distinct_variant_price
#: model:ir.model.fields,field_description:website_sale_product_minimal_price.field_product_template_has_distinct_variant_price
msgid "Has variants with distinct extra"
msgstr ""

#. module: website_sale_product_minimal_price
#: model:product.product,name:website_sale_product_minimal_price.product_product_test_1
#: model:product.product,name:website_sale_product_minimal_price.product_product_test_2
#: model:product.template,name:website_sale_product_minimal_price.product_product_test_1_product_template
#: model:product.template,name:website_sale_product_minimal_price.product_product_test_2_product_template
msgid "My product test with various prices"
msgstr "Mi producto de test con varios precios"
#: model:ir.model.fields,field_description:website_sale_product_minimal_price.field_product_product__has_distinct_variant_price
#: model:ir.model.fields,field_description:website_sale_product_minimal_price.field_product_template__has_distinct_variant_price
msgid "Has variants with distinct price extra"
msgstr "Tiene variantes con diferentes precios extra"

#. module: website_sale_product_minimal_price
#: model:ir.model,name:website_sale_product_minimal_price.model_product_template
msgid "Product Template"
msgstr "Plantilla de producto"

#. module: website_sale_product_minimal_price
#: model:product.attribute,name:website_sale_product_minimal_price.product_attribute_test
msgid "Test attribute"
msgstr "Atributo de prueba"
#~ msgid "My product test with various prices"
#~ msgstr "Mi producto de test con varios precios"

#. module: website_sale_product_minimal_price
#: model:product.attribute.value,name:website_sale_product_minimal_price.product_attribute_value_test_1
msgid "Test v1"
msgstr "Valor 1 de test"
#~ msgid "Test attribute"
#~ msgstr "Atributo de prueba"

#. module: website_sale_product_minimal_price
#: model:product.attribute.value,name:website_sale_product_minimal_price.product_attribute_value_test_2
msgid "Test v2"
msgstr "Valor 2 de test"
#~ msgid "Test v1"
#~ msgstr "Valor 1 de test"

#~ msgid "Test v2"
#~ msgstr "Valor 2 de test"
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 11.0\n"
"Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-12-11 23:22+0000\n"
"PO-Revision-Date: 2019-12-11 23:22+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
Expand All @@ -14,41 +16,18 @@ msgstr ""
"Plural-Forms: \n"

#. module: website_sale_product_minimal_price
#: model:ir.ui.view,arch_db:website_sale_product_minimal_price.products_item
#: model_terms:ir.ui.view,arch_db:website_sale_product_minimal_price.products_item
msgid "<span>From </span>"
msgstr ""

#. module: website_sale_product_minimal_price
#: model:ir.model.fields,field_description:website_sale_product_minimal_price.field_product_product_has_distinct_variant_price
#: model:ir.model.fields,field_description:website_sale_product_minimal_price.field_product_template_has_distinct_variant_price
msgid "Has variants with distinct extra"
msgstr ""

#. module: website_sale_product_minimal_price
#: model:product.product,name:website_sale_product_minimal_price.product_product_test_1
#: model:product.product,name:website_sale_product_minimal_price.product_product_test_2
#: model:product.template,name:website_sale_product_minimal_price.product_product_test_1_product_template
#: model:product.template,name:website_sale_product_minimal_price.product_product_test_2_product_template
msgid "My product test with various prices"
#: model:ir.model.fields,field_description:website_sale_product_minimal_price.field_product_product__has_distinct_variant_price
#: model:ir.model.fields,field_description:website_sale_product_minimal_price.field_product_template__has_distinct_variant_price
msgid "Has variants with distinct price extra"
msgstr ""

#. module: website_sale_product_minimal_price
#: model:ir.model,name:website_sale_product_minimal_price.model_product_template
msgid "Product Template"
msgstr ""

#. module: website_sale_product_minimal_price
#: model:product.attribute,name:website_sale_product_minimal_price.product_attribute_test
msgid "Test attribute"
msgstr ""

#. module: website_sale_product_minimal_price
#: model:product.attribute.value,name:website_sale_product_minimal_price.product_attribute_value_test_1
msgid "Test v1"
msgstr ""

#. module: website_sale_product_minimal_price
#: model:product.attribute.value,name:website_sale_product_minimal_price.product_attribute_value_test_2
msgid "Test v2"
msgstr ""

61 changes: 51 additions & 10 deletions website_sale_product_minimal_price/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ProductTemplate(models.Model):

has_distinct_variant_price = fields.Boolean(
compute='_compute_has_distinct_variant_price',
string='Has variants with distinct extra',
string='Has variants with distinct price extra',
)

def _compute_has_distinct_variant_price(self):
Expand All @@ -18,12 +18,53 @@ def _compute_has_distinct_variant_price(self):
if len(prices) > 1:
template.has_distinct_variant_price = True

def _website_price(self):
templates = self.filtered(lambda x: x.product_variant_count > 1)
super(ProductTemplate, self - templates)._website_price()
for product in templates:
variant = product.product_variant_ids.sorted(
key=lambda p: p.website_price)[:1]
product.website_price = variant.website_price
product.website_public_price = variant.website_public_price
product.website_price_difference = variant.website_price_difference
def _get_combination_info(
self, combination=False, product_id=False, add_qty=1, pricelist=False,
parent_combination=False, only_template=False):
"""
Update product template prices for products items view in website shop
render with cheaper variant prices.
"""
combination_info = super()._get_combination_info(
combination=combination, product_id=product_id, add_qty=add_qty,
pricelist=pricelist, parent_combination=parent_combination,
only_template=only_template)

if (only_template and self.env.context.get('website_id') and
self.product_variant_count > 1):
cheaper_variant = self.product_variant_ids.sorted(
key=lambda p: p.price_extra)[:1]

res = cheaper_variant._get_combination_info_variant()

combination_info.update({
'price': res.get('price'),
'list_price': res.get('list_price'),
'has_discounted_price': res.get('has_discounted_price'),
})
return combination_info

def _get_first_possible_combination(
self, parent_combination=None, necessary_values=None):
"""
Get the cheaper product combination for the product for website view.
We only take into account attributes that generate variants and
products with more than one variant.
"""
combination = super()._get_first_possible_combination(
parent_combination=parent_combination,
necessary_values=necessary_values
)
if (self.env.context.get('website_id') and
self.product_variant_count > 1):
ptav_obj = self.env['product.template.attribute.value']
pav = self.product_variant_ids.sorted(
'lst_price')[:1].attribute_value_ids
cheaper_combination = ptav_obj.search([
('product_tmpl_id', '=', self.id),
('product_attribute_value_id', 'in', pav.ids),
])
variant_combination = combination.filtered(
lambda x: x.attribute_id.create_variant == 'always')
return cheaper_combination + (combination - variant_combination)
return combination
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Website Sale Product Minimal 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/e-commerce/tree/11.0/website_sale_product_minimal_price"><img alt="OCA/e-commerce" src="https://img.shields.io/badge/github-OCA%2Fe--commerce-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/e-commerce-11-0/e-commerce-11-0-website_sale_product_minimal_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/113/11.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" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.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/e-commerce/tree/12.0/website_sale_product_minimal_price"><img alt="OCA/e-commerce" src="https://img.shields.io/badge/github-OCA%2Fe--commerce-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/e-commerce-12-0/e-commerce-12-0-website_sale_product_minimal_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/113/12.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module extends the functionality of website sale module to allow to
display the minimal price in ‘/shop’ view when product has distinct variants
price and set order by minimal price in product’s view.</p>
Expand Down Expand Up @@ -400,7 +400,7 @@ <h1><a class="toc-backref" href="#id2">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/e-commerce/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/e-commerce/issues/new?body=module:%20website_sale_product_minimal_price%0Aversion:%2011.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/e-commerce/issues/new?body=module:%20website_sale_product_minimal_price%0Aversion:%2012.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 Down Expand Up @@ -430,7 +430,9 @@ <h2><a class="toc-backref" href="#id6">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/e-commerce/tree/11.0/website_sale_product_minimal_price">OCA/e-commerce</a> project on GitHub.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external" href="https://github.com/sergio-teruel"><img alt="sergio-teruel" src="https://github.com/sergio-teruel.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/e-commerce/tree/12.0/website_sale_product_minimal_price">OCA/e-commerce</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
Loading

0 comments on commit 71d323a

Please sign in to comment.