diff --git a/website_sale_product_minimal_price/README.rst b/website_sale_product_minimal_price/README.rst new file mode 100644 index 0000000000..a3785b9696 --- /dev/null +++ b/website_sale_product_minimal_price/README.rst @@ -0,0 +1,87 @@ +================================== +Website Sale Product Minimal Price +================================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |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 + :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 + :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 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +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. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +#. Go to backend and set a product with variants and extra price by attribute + value or define a distinct prices in public price list for this variant. +#. Go to Website Shop. +#. You will see that in main products view appears the text "From " with + minimal price if the product has a distinct prices by attribute. +#. Click on product, the price displayed is the minimal variant price. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Tecnativa + +Contributors +~~~~~~~~~~~~ + +* `Tecnativa `_: + + * Sergio Teruel + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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 `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/website_sale_product_minimal_price/__init__.py b/website_sale_product_minimal_price/__init__.py new file mode 100644 index 0000000000..3275ac2adf --- /dev/null +++ b/website_sale_product_minimal_price/__init__.py @@ -0,0 +1,2 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from . import models diff --git a/website_sale_product_minimal_price/__manifest__.py b/website_sale_product_minimal_price/__manifest__.py new file mode 100644 index 0000000000..fbfba46aa5 --- /dev/null +++ b/website_sale_product_minimal_price/__manifest__.py @@ -0,0 +1,24 @@ +# Copyright 2019 Tecnativa - Sergio Teruel +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + 'name': 'Website Sale Product Minimal Price', + 'summary': 'Display minimal price for products that has variants', + 'version': '11.0.1.0.0', + 'development_status': 'Beta', + 'category': 'Website', + 'website': 'https://github.com/OCA/e-commerce', + 'author': 'Tecnativa, Odoo Community Association (OCA)', + 'license': 'AGPL-3', + 'application': False, + 'installable': True, + 'depends': [ + 'website_sale', + ], + 'data': [ + 'views/assets.xml', + 'views/templates.xml', + ], + 'demo': [ + 'data/demo.xml', + ], +} diff --git a/website_sale_product_minimal_price/data/demo.xml b/website_sale_product_minimal_price/data/demo.xml new file mode 100644 index 0000000000..a21fe954fd --- /dev/null +++ b/website_sale_product_minimal_price/data/demo.xml @@ -0,0 +1,49 @@ + + + + + + + Test attribute + + + + Test v1 + + + + Test v2 + + + + My product test with various prices + 20.0 + consu + + + + + + + + + + + + + + + + + + + 5.0 + + + + + 10.0 + + + diff --git a/website_sale_product_minimal_price/i18n/es.po b/website_sale_product_minimal_price/i18n/es.po new file mode 100644 index 0000000000..db2e5e2335 --- /dev/null +++ b/website_sale_product_minimal_price/i18n/es.po @@ -0,0 +1,57 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * website_sale_product_minimal_price +# +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" +"Last-Translator: \n" +"Language-Team: \n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"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 +msgid "From " +msgstr "Desde " + +#. 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" + +#. 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" + +#. 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" + +#. 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" diff --git a/website_sale_product_minimal_price/i18n/website_sale_product_minimal_price.pot b/website_sale_product_minimal_price/i18n/website_sale_product_minimal_price.pot new file mode 100644 index 0000000000..be41c4a889 --- /dev/null +++ b/website_sale_product_minimal_price/i18n/website_sale_product_minimal_price.pot @@ -0,0 +1,54 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * website_sale_product_minimal_price +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 11.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: website_sale_product_minimal_price +#: model:ir.ui.view,arch_db:website_sale_product_minimal_price.products_item +msgid "From " +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" +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 "" + diff --git a/website_sale_product_minimal_price/models/__init__.py b/website_sale_product_minimal_price/models/__init__.py new file mode 100644 index 0000000000..e8fa8f6bf1 --- /dev/null +++ b/website_sale_product_minimal_price/models/__init__.py @@ -0,0 +1 @@ +from . import product_template diff --git a/website_sale_product_minimal_price/models/product_template.py b/website_sale_product_minimal_price/models/product_template.py new file mode 100644 index 0000000000..5e19bf9d20 --- /dev/null +++ b/website_sale_product_minimal_price/models/product_template.py @@ -0,0 +1,29 @@ +# Copyright 2019 Tecnativa - Sergio Teruel +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import fields, models + + +class ProductTemplate(models.Model): + _inherit = 'product.template' + + has_distinct_variant_price = fields.Boolean( + compute='_compute_has_distinct_variant_price', + string='Has variants with distinct extra', + ) + + def _compute_has_distinct_variant_price(self): + for template in self: + if template.product_variant_count > 1: + prices = template.product_variant_ids.mapped('website_price') + 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 diff --git a/website_sale_product_minimal_price/readme/CONTRIBUTORS.rst b/website_sale_product_minimal_price/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..3bfad993cb --- /dev/null +++ b/website_sale_product_minimal_price/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Tecnativa `_: + + * Sergio Teruel diff --git a/website_sale_product_minimal_price/readme/DESCRIPTION.rst b/website_sale_product_minimal_price/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..09c47abbba --- /dev/null +++ b/website_sale_product_minimal_price/readme/DESCRIPTION.rst @@ -0,0 +1,3 @@ +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. diff --git a/website_sale_product_minimal_price/readme/USAGE.rst b/website_sale_product_minimal_price/readme/USAGE.rst new file mode 100644 index 0000000000..5e5e861d43 --- /dev/null +++ b/website_sale_product_minimal_price/readme/USAGE.rst @@ -0,0 +1,6 @@ +#. Go to backend and set a product with variants and extra price by attribute + value or define a distinct prices in public price list for this variant. +#. Go to Website Shop. +#. You will see that in main products view appears the text "From " with + minimal price if the product has a distinct prices by attribute. +#. Click on product, the price displayed is the minimal variant price. diff --git a/website_sale_product_minimal_price/static/description/icon.png b/website_sale_product_minimal_price/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/website_sale_product_minimal_price/static/description/icon.png differ diff --git a/website_sale_product_minimal_price/static/description/index.html b/website_sale_product_minimal_price/static/description/index.html new file mode 100644 index 0000000000..7a7887680c --- /dev/null +++ b/website_sale_product_minimal_price/static/description/index.html @@ -0,0 +1,439 @@ + + + + + + +Website Sale Product Minimal Price + + + +
+

Website Sale Product Minimal Price

+ + +

Beta License: AGPL-3 OCA/e-commerce Translate me on Weblate Try me on Runbot

+

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.

+

Table of contents

+ +
+

Usage

+
    +
  1. Go to backend and set a product with variants and extra price by attribute +value or define a distinct prices in public price list for this variant.
  2. +
  3. Go to Website Shop.
  4. +
  5. You will see that in main products view appears the text “From ” with +minimal price if the product has a distinct prices by attribute.
  6. +
  7. Click on product, the price displayed is the minimal variant price.
  8. +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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 project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/website_sale_product_minimal_price/static/src/js/website_sale_product_minimal_price_tour.js b/website_sale_product_minimal_price/static/src/js/website_sale_product_minimal_price_tour.js new file mode 100644 index 0000000000..72a56fe11d --- /dev/null +++ b/website_sale_product_minimal_price/static/src/js/website_sale_product_minimal_price_tour.js @@ -0,0 +1,31 @@ +/* Copyright 2019 Sergio Teruel + * License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */ + +odoo.define("website_sale_product_minimal_price.tour", function (require) { + "use strict"; + + var tour = require("web_tour.tour"); + var base = require("web_editor.base"); + + var steps = [ + { + trigger: "a:contains('My product test')", + extra_trigger: ".product_price:has(span:contains('From '))", + }, + { + trigger: "a[href='/shop']", + extra_trigger: ".js_attribute_value:eq(0):has(span:contains('Test v1'))", + }, + ]; + tour.register("website_sale_product_minimal_price", + { + url: "/shop", + test: true, + wait_for: base.ready(), + }, + steps + ); + return { + steps: steps, + }; +}); diff --git a/website_sale_product_minimal_price/tests/__init__.py b/website_sale_product_minimal_price/tests/__init__.py new file mode 100644 index 0000000000..3feff797da --- /dev/null +++ b/website_sale_product_minimal_price/tests/__init__.py @@ -0,0 +1 @@ +from . import test_website_sale_product_minimal_price diff --git a/website_sale_product_minimal_price/tests/test_website_sale_product_minimal_price.py b/website_sale_product_minimal_price/tests/test_website_sale_product_minimal_price.py new file mode 100644 index 0000000000..bcaf4d6b07 --- /dev/null +++ b/website_sale_product_minimal_price/tests/test_website_sale_product_minimal_price.py @@ -0,0 +1,18 @@ +# Copyright 2019 Tecnativa - Sergio Teruel +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo.tests.common import HttpCase + + +class WebsiteSaleProductMinimalPriceHttpCase(HttpCase): + + def test_ui_website(self): + """Test frontend tour.""" + tour = ( + "odoo.__DEBUG__.services['web_tour.tour']", + "website_sale_product_minimal_price", + ) + self.phantom_js( + url_path="/", + code="%s.run('%s')" % tour, + ready="%s.tours['%s'].ready" % tour, + ) diff --git a/website_sale_product_minimal_price/views/assets.xml b/website_sale_product_minimal_price/views/assets.xml new file mode 100644 index 0000000000..e3da2ba84f --- /dev/null +++ b/website_sale_product_minimal_price/views/assets.xml @@ -0,0 +1,9 @@ + + +