Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] product_pricelist_alternative
Browse files Browse the repository at this point in the history
santostelmo committed Mar 19, 2024
1 parent 28db8a2 commit f99e03a
Showing 17 changed files with 945 additions and 0 deletions.
80 changes: 80 additions & 0 deletions product_pricelist_alternative/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
=============================
Product Pricelist Alternative
=============================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:d20a66d534d1bf7ae7e1f62db19cc35972345fab662fc9627c2c4c2f34556dc8
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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%2Fproduct--attribute-lightgray.png?logo=github
:target: https://github.com/OCA/product-attribute/tree/16.0/product_pricelist_alternative
:alt: OCA/product-attribute
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/product-attribute-16-0/product-attribute-16-0-product_pricelist_alternative
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/product-attribute&target_branch=16.0
:alt: Try me on Runboat

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

It allows you to define alternative price lists to a reference price list.
As a general rule, the price of a given product is obtained from the minimum between its reference price list and the alternative price lists.

However, if the product's reference price has been calculated on the basis of a price rule in which the "Consider Alternative = Do not consider" field is selected, the alternative price lists will not be taken into account.

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/product-attribute/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/product-attribute/issues/new?body=module:%20product_pricelist_alternative%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.

Credits
=======

Authors
~~~~~~~

* Camptocamp

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

* Telmo Santos <telmo.santos@camptocamp.com>
* Akim Juillerat <akim.juillerat@camptocamp.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.

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

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions product_pricelist_alternative/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
22 changes: 22 additions & 0 deletions product_pricelist_alternative/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2024 Camptocamp (<https://www.camptocamp.com>).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
"name": "Product Pricelist Alternative",
"version": "16.0.1.0.0",
"development_status": "Beta",
"category": "Product",
"summary": "Calculate product price based on alternative pricelists",
"author": "Camptocamp, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/product-attribute",
"license": "AGPL-3",
"depends": [
"product",
],
"data": [
"views/product_pricelist_item_view.xml",
"views/product_pricelist_view.xml",
],
"installable": True,
"auto_install": False,
}
56 changes: 56 additions & 0 deletions product_pricelist_alternative/i10n/fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * product_pricelist_alternative
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-03-19 06:16+0000\n"
"PO-Revision-Date: 2024-03-19 06:16+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: product_pricelist_alternative
#: model_terms:ir.ui.view,arch_db:product_pricelist_alternative.product_pricelist_view
msgid "Alternative Pricelists"
msgstr "Listes de prix alternatives"

#. module: product_pricelist_alternative
#: model:ir.model.fields,field_description:product_pricelist_alternative.field_product_pricelist__alternative_pricelist_ids
msgid "Alternative pricelists"
msgstr "Listes de prix alternatives"

#. module: product_pricelist_alternative
#: model:ir.model.fields,field_description:product_pricelist_alternative.field_product_pricelist_item__consider_alternative
msgid "Consider Alternative"
msgstr "Considérer Alternative"

#. module: product_pricelist_alternative
#: model:ir.model.fields.selection,name:product_pricelist_alternative.selection__product_pricelist_item__consider_alternative__do_not_consider
msgid "Do not consider"
msgstr "Ne pas prendre en considération"

#. module: product_pricelist_alternative
#: model:ir.model.fields,field_description:product_pricelist_alternative.field_product_pricelist__is_alternative_to_pricelist_ids
msgid "Is alternative to pricelists"
msgstr "Alternative aux listes de prix"

#. module: product_pricelist_alternative
#: model:ir.model,name:product_pricelist_alternative.model_product_pricelist
msgid "Pricelist"
msgstr "Liste de prix"

#. module: product_pricelist_alternative
#: model:ir.model,name:product_pricelist_alternative.model_product_pricelist_item
msgid "Pricelist Rule"
msgstr "Règle des prix"

#. module: product_pricelist_alternative
#: model:ir.model.fields.selection,name:product_pricelist_alternative.selection__product_pricelist_item__consider_alternative__use_lower_price
msgid "Use lower price"
msgstr "Utiliser le prix le plus bas"
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * product_pricelist_alternative
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-03-19 06:16+0000\n"
"PO-Revision-Date: 2024-03-19 06:16+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: product_pricelist_alternative
#: model_terms:ir.ui.view,arch_db:product_pricelist_alternative.product_pricelist_view
msgid "Alternative Pricelists"
msgstr ""

#. module: product_pricelist_alternative
#: model:ir.model.fields,field_description:product_pricelist_alternative.field_product_pricelist__alternative_pricelist_ids
msgid "Alternative pricelists"
msgstr ""

#. module: product_pricelist_alternative
#: model:ir.model.fields,field_description:product_pricelist_alternative.field_product_pricelist_item__consider_alternative
msgid "Consider Alternative"
msgstr ""

#. module: product_pricelist_alternative
#: model:ir.model.fields.selection,name:product_pricelist_alternative.selection__product_pricelist_item__consider_alternative__do_not_consider
msgid "Do not consider"
msgstr ""

#. module: product_pricelist_alternative
#: model:ir.model.fields,field_description:product_pricelist_alternative.field_product_pricelist__is_alternative_to_pricelist_ids
msgid "Is alternative to pricelists"
msgstr ""

#. module: product_pricelist_alternative
#: model:ir.model,name:product_pricelist_alternative.model_product_pricelist
msgid "Pricelist"
msgstr ""

#. module: product_pricelist_alternative
#: model:ir.model,name:product_pricelist_alternative.model_product_pricelist_item
msgid "Pricelist Rule"
msgstr ""

#. module: product_pricelist_alternative
#: model:ir.model.fields.selection,name:product_pricelist_alternative.selection__product_pricelist_item__consider_alternative__use_lower_price
msgid "Use lower price"
msgstr ""
2 changes: 2 additions & 0 deletions product_pricelist_alternative/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import product_pricelist
from . import product_pricelist_item
50 changes: 50 additions & 0 deletions product_pricelist_alternative/models/product_pricelist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright 2024 Camptocamp (<https://www.camptocamp.com>).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import _, api, fields, models


class Pricelist(models.Model):
_inherit = "product.pricelist"

alternative_pricelist_ids = fields.Many2many(
comodel_name="product.pricelist",
string="Alternative pricelists",
relation="alternative_pricelist_rel",
column1="origin_id",
column2="alternative_id",
domain="[('id', '!=', id)]",
)
is_alternative_to_pricelist_ids = fields.Many2many(
comodel_name="product.pricelist",
string="Is alternative to pricelists",
relation="alternative_pricelist_rel",
column1="alternative_id",
column2="origin_id",
)
is_alternative_to_pricelist_count = fields.Integer(
compute="_compute_is_alternative_to_pricelist_count"
)

@api.depends("is_alternative_to_pricelist_ids")
def _compute_is_alternative_to_pricelist_count(self):
for pricelist in self:
pricelist.is_alternative_to_pricelist_count = len(

Check warning on line 32 in product_pricelist_alternative/models/product_pricelist.py

Codecov / codecov/patch

product_pricelist_alternative/models/product_pricelist.py#L32

Added line #L32 was not covered by tests
pricelist.is_alternative_to_pricelist_ids
)

def action_view_is_alternative_to_pricelist(self):
self.ensure_one()
action = {

Check warning on line 38 in product_pricelist_alternative/models/product_pricelist.py

Codecov / codecov/patch

product_pricelist_alternative/models/product_pricelist.py#L37-L38

Added lines #L37 - L38 were not covered by tests
"type": "ir.actions.act_window",
"name": _("Is Alternative to Pricelist"),
"res_model": "product.pricelist",
"view_mode": "tree,form",
"domain": [("id", "in", self.is_alternative_to_pricelist_ids.ids)],
"context": dict(self._context, create=False),
}
if self.is_alternative_to_pricelist_count == 1:
action.update(

Check warning on line 47 in product_pricelist_alternative/models/product_pricelist.py

Codecov / codecov/patch

product_pricelist_alternative/models/product_pricelist.py#L47

Added line #L47 was not covered by tests
{"view_mode": "form", "res_id": self.is_alternative_to_pricelist_ids.id}
)
return action

Check warning on line 50 in product_pricelist_alternative/models/product_pricelist.py

Codecov / codecov/patch

product_pricelist_alternative/models/product_pricelist.py#L50

Added line #L50 was not covered by tests
32 changes: 32 additions & 0 deletions product_pricelist_alternative/models/product_pricelist_item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2024 Camptocamp (<https://www.camptocamp.com>).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


class PricelistItem(models.Model):
_inherit = "product.pricelist.item"

consider_alternative = fields.Selection(
selection=[
("use_lower_price", "Use lower price"),
("do_not_consider", "Do not consider"),
],
default="use_lower_price",
required=True,
)

def _compute_price(self, product, quantity, uom, date, currency):
price = super(PricelistItem, self)._compute_price(
product, quantity, uom, date, currency
)
if self.consider_alternative == "use_lower_price":
alternative_pricelists = self.pricelist_id.alternative_pricelist_ids
if alternative_pricelists:
for alternative_pricelist in alternative_pricelists:
alternative_price = alternative_pricelist._get_product_price(
product, quantity, uom, date
)
if alternative_price < price:
price = alternative_price
return price
2 changes: 2 additions & 0 deletions product_pricelist_alternative/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Telmo Santos <telmo.santos@camptocamp.com>
* Akim Juillerat <akim.juillerat@camptocamp.com>
4 changes: 4 additions & 0 deletions product_pricelist_alternative/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
It allows you to define alternative price lists to a reference price list.
As a general rule, the price of a given product is obtained from the minimum between its reference price list and the alternative price lists.

However, if the product's reference price has been calculated on the basis of a price rule in which the "Consider Alternative = Do not consider" field is selected, the alternative price lists will not be taken into account.
424 changes: 424 additions & 0 deletions product_pricelist_alternative/static/description/index.html

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions product_pricelist_alternative/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_pricelist_alternative
122 changes: 122 additions & 0 deletions product_pricelist_alternative/tests/test_pricelist_alternative.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# Copyright 2024 Camptocamp (<https://www.camptocamp.com>).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo.fields import Command
from odoo.tests import common, tagged


@tagged("post_install", "-at_install")
class TestPricelistAlternative(common.TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()

cls.datacard = cls.env["product.product"].create(
{"name": "Data card", "list_price": 100}
)
cls.usb_adapter = cls.env["product.product"].create(
{"name": "Usb adapter", "list_price": 100}
)

cls.alternative_pricelist_01 = cls.env["product.pricelist"].create(
{
"name": "Alternative pricelist 01",
"item_ids": [
Command.create(
{
"compute_price": "fixed",
"product_id": cls.usb_adapter.id,
"applied_on": "0_product_variant",
"fixed_price": 70,
}
),
],
}
)
cls.alternative_pricelist_02 = cls.env["product.pricelist"].create(
{
"name": "Alternative pricelist 02",
"item_ids": [
Command.create(
{
"compute_price": "fixed",
"product_id": cls.datacard.id,
"applied_on": "0_product_variant",
"fixed_price": 80,
}
),
],
}
)

cls.pricelist01 = cls.env["product.pricelist"].create(
{
"name": "Sale pricelist",
"item_ids": [
Command.create(
{
"compute_price": "fixed",
"product_id": cls.usb_adapter.id,
"applied_on": "0_product_variant",
"fixed_price": 95,
}
),
Command.create(
{
"compute_price": "fixed",
"product_id": cls.datacard.id,
"applied_on": "0_product_variant",
"fixed_price": 70,
}
),
],
"alternative_pricelist_ids": [
(4, cls.alternative_pricelist_01.id),
(4, cls.alternative_pricelist_02.id),
],
}
)

cls.product_categ01 = cls.env["product.category"].create(
{"name": "Category 01"}
)
cls.usb_adapter.categ_id = cls.product_categ01

cls.pricelist02 = cls.env["product.pricelist"].create(
{
"name": "Sale pricelist",
"item_ids": [
Command.create(
{
"compute_price": "percentage",
"applied_on": "2_product_category",
"categ_id": cls.product_categ01.id,
"percent_price": 40,
}
),
],
"alternative_pricelist_ids": [
(4, cls.alternative_pricelist_01.id),
],
}
)

def test_product_price_considering_alternative_pricelist_with_lower_price(self):
"""Test that the product price is computed considering the alternative
pricelist with the lower price"""

# Best price on alternative pricelist01
self.assertEqual(self.pricelist01._get_product_price(self.usb_adapter, 1.0), 70)
# Best price on alternative pricelist02
self.assertEqual(self.pricelist02._get_product_price(self.usb_adapter, 1.0), 60)

def test_product_price_not_considering_alternative_pricelist(self):
"""Test that the product price is computed not considering alternative pricelist"""

# Set the pricelist items to not consider alternative pricelist
self.pricelist01.item_ids.write({"consider_alternative": "do_not_consider"})
self.pricelist02.item_ids.write({"consider_alternative": "do_not_consider"})

# We won't consider the alternative pricelist
self.assertEqual(self.pricelist01._get_product_price(self.usb_adapter, 1.0), 95)
self.assertEqual(self.pricelist02._get_product_price(self.usb_adapter, 1.0), 60)
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="product_pricelist_item_view_form" model="ir.ui.view">
<field name="name">product.pricelist.item.form</field>
<field name="model">product.pricelist.item</field>
<field name="inherit_id" ref="product.product_pricelist_item_form_view" />
<field name="arch" type="xml">
<xpath expr="//field[@name='fixed_price']" position="after">
<field name="consider_alternative" />
</xpath>
</field>
</record>

<record id="product_pricelist_item_view_tree" model="ir.ui.view">
<field name="name">product.pricelist.item.tree</field>
<field name="model">product.pricelist.item</field>
<field name="inherit_id" ref="product.product_pricelist_item_tree_view" />
<field name="arch" type="xml">
<xpath expr="//field[@name='price']" position="after">
<field name="consider_alternative" />
</xpath>
</field>
</record>

<record id="product_pricelist_item_tree_view_from_product" model="ir.ui.view">
<field name="name">product.pricelist.item.tree</field>
<field name="model">product.pricelist.item</field>
<field
name="inherit_id"
ref="product.product_pricelist_item_tree_view_from_product"
/>
<field name="arch" type="xml">
<xpath expr="//field[@name='date_end']" position="after">
<field name="consider_alternative" />
</xpath>
</field>
</record>
</odoo>
48 changes: 48 additions & 0 deletions product_pricelist_alternative/views/product_pricelist_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="product_pricelist_view" model="ir.ui.view">
<field name="name">product.pricelist.form</field>
<field name="model">product.pricelist</field>
<field name="inherit_id" ref="product.product_pricelist_view" />
<field name="arch" type="xml">
<widget name="web_ribbon" position="before">
<button
class="oe_stat_button"
type="object"
name="action_view_is_alternative_to_pricelist"
icon="fa-list"
>
<field
string="Alternative to Pricelist"
name="is_alternative_to_pricelist_count"
widget="statinfo"
/>
</button>
</widget>

<group name="pricelist_settings" position="after">
<group string="Alternative Pricelists">
<field
name="alternative_pricelist_ids"
nolabel="1"
colspan="2"
widget="many2many_tags"
options="{'no_create': True}"
/>
</group>
</group>
<xpath
expr="//page[@name='pricelist_rules']/field[@name='item_ids']/tree/field[@name='product_id']"
position="after"
>
<field name="consider_alternative" />
</xpath>
<xpath
expr="//page[@name='pricelist_rules']/field[@name='item_ids']/tree[@groups='product.group_sale_pricelist']/field[@name='name']"
position="after"
>
<field name="consider_alternative" />
</xpath>
</field>
</record>
</odoo>
6 changes: 6 additions & 0 deletions setup/product_pricelist_alternative/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit f99e03a

Please sign in to comment.