Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MIG][12.0] website_sale_product_minimal_price: Migration to v12.0 #320

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions website_sale_product_minimal_price/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
==================================
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-Production%2FStable-green.png
:target: https://odoo-community.org/page/development-status
: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/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-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/12.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 <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:%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.

Credits
=======

Authors
~~~~~~~

* Tecnativa

Contributors
~~~~~~~~~~~~

* `Tecnativa <https://www.tecnativa.com>`_:

* Sergio Teruel <sergio.teruel@tecnativa.com>

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.

.. |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.
2 changes: 2 additions & 0 deletions website_sale_product_minimal_price/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import models
22 changes: 22 additions & 0 deletions website_sale_product_minimal_price/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 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': '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)',
'license': 'AGPL-3',
'application': False,
'installable': True,
'depends': [
'website_sale',
],
'data': [
'views/assets.xml',
'views/templates.xml',
],
}
46 changes: 46 additions & 0 deletions website_sale_product_minimal_price/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# 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-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"
"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_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 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"

#~ msgid "My product test with various prices"
#~ msgstr "Mi producto de test con varios precios"

#~ msgid "Test attribute"
#~ msgstr "Atributo de prueba"

#~ 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
@@ -0,0 +1,33 @@
# 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 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"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: website_sale_product_minimal_price
#: 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 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 ""

1 change: 1 addition & 0 deletions website_sale_product_minimal_price/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import product_template
70 changes: 70 additions & 0 deletions website_sale_product_minimal_price/models/product_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# 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 price 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 _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
3 changes: 3 additions & 0 deletions website_sale_product_minimal_price/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* `Tecnativa <https://www.tecnativa.com>`_:

* Sergio Teruel <sergio.teruel@tecnativa.com>
3 changes: 3 additions & 0 deletions website_sale_product_minimal_price/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -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.
6 changes: 6 additions & 0 deletions website_sale_product_minimal_price/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading