Skip to content

Commit

Permalink
[MIG] product_pricelist_supplierinfo: Migration to 18.0
Browse files Browse the repository at this point in the history
Changelog:
- Use `is` and `is not` for type comparisons, or `isinstance()` for
  isinstance checks.
- Add a test for the scenario where the pricelist is not based on the
  supplier info, ensuring the price is calculated as expected natively.
- Replace the currency rate update by a currency rate creation in the
  tests, as demo rates have a fixed rate in the past.

Co-authored-by: mle <[email protected]>
  • Loading branch information
CLaurelB and marielejeune committed Jan 13, 2025
1 parent 22064ce commit 25e8f5a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 27 deletions.
10 changes: 5 additions & 5 deletions product_pricelist_supplierinfo/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ Supplier info prices in sales pricelists
: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/17.0/product_pricelist_supplierinfo
:target: https://github.com/OCA/product-attribute/tree/18.0/product_pricelist_supplierinfo
: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-17-0/product-attribute-17-0-product_pricelist_supplierinfo
:target: https://translation.odoo-community.org/projects/product-attribute-18-0/product-attribute-18-0-product_pricelist_supplierinfo
: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=17.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/product-attribute&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -102,7 +102,7 @@ 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_supplierinfo%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/product-attribute/issues/new?body=module:%20product_pricelist_supplierinfo%0Aversion:%2018.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 @@ -152,6 +152,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-luisg123v|

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

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion product_pricelist_supplierinfo/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"name": "Supplier info prices in sales pricelists",
"summary": "Allows to create priceslists based on supplier info",
"version": "17.0.2.0.0",
"version": "18.0.1.0.0",
"category": "Sales/Sales",
"website": "https://github.com/OCA/product-attribute",
"author": "Tecnativa, Odoo Community Association (OCA), Vauxoo",
Expand Down
2 changes: 1 addition & 1 deletion product_pricelist_supplierinfo/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def _get_supplierinfo_pricelist_price(
# The product_variant_id returns empty recordset if template is not
# active, so we must ensure variant exists or _select_seller fails.
if product:
if type(date) == datetime:
if type(date) is datetime:
date = date.date()
seller = product.with_context(
override_min_qty=rule.no_supplierinfo_min_quantity
Expand Down
6 changes: 3 additions & 3 deletions product_pricelist_supplierinfo/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ <h1 class="title">Supplier info prices in sales pricelists</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:3b1eaa22384d0573346866a317e714b3d95555e79eaf6a24283febb60d1e7e16
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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-attribute/tree/17.0/product_pricelist_supplierinfo"><img alt="OCA/product-attribute" src="https://img.shields.io/badge/github-OCA%2Fproduct--attribute-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/product-attribute-17-0/product-attribute-17-0-product_pricelist_supplierinfo"><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/builds?repo=OCA/product-attribute&amp;target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-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-attribute/tree/18.0/product_pricelist_supplierinfo"><img alt="OCA/product-attribute" src="https://img.shields.io/badge/github-OCA%2Fproduct--attribute-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/product-attribute-18-0/product-attribute-18-0-product_pricelist_supplierinfo"><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/builds?repo=OCA/product-attribute&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module allows you to create a sales pricelist based on product
supplierinfo prices. If you want, you can bypass minimum quantity in
pricelist item.</p>
Expand Down Expand Up @@ -451,7 +451,7 @@ <h1><a class="toc-backref" href="#toc-entry-5">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/product-attribute/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 to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/product-attribute/issues/new?body=module:%20product_pricelist_supplierinfo%0Aversion:%2017.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-attribute/issues/new?body=module:%20product_pricelist_supplierinfo%0Aversion:%2018.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 @@ -491,7 +491,7 @@ <h2><a class="toc-backref" href="#toc-entry-9">Maintainers</a></h2>
promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/luisg123v"><img alt="luisg123v" src="https://github.com/luisg123v.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/product-attribute/tree/17.0/product_pricelist_supplierinfo">OCA/product-attribute</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/product-attribute/tree/18.0/product_pricelist_supplierinfo">OCA/product-attribute</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
39 changes: 22 additions & 17 deletions product_pricelist_supplierinfo/tests/test_product_supplierinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class TestProductSupplierinfo(TransactionCase):
def setUpClass(cls):
super().setUpClass()
cls.partner_obj = cls.env["res.partner"]
cls.currency_rate_obj = cls.env["res.currency.rate"]
cls.partner = cls.partner_obj.create({"name": "Partner Test"})
cls.supplier1 = cls.partner_obj.create({"name": "Supplier #1"})
cls.supplier2 = cls.partner_obj.create({"name": "Supplier #2"})
Expand Down Expand Up @@ -60,20 +59,14 @@ def setUpClass(cls):
)

@classmethod
def _update_rate(cls, currency_id, rate):
currency_rate = cls.currency_rate_obj.search(
[("name", "=", date.today()), ("currency_id", "=", currency_id.id)], limit=1
)
if not currency_rate:
cls.currency_rate_obj.create(
{
"currency_id": currency_id.id,
"rate": rate,
"name": date.today(),
}
)
else:
currency_rate.write({"rate": rate})
def _create_rate(cls, currency_id, rate):
cls.env["res.currency.rate"].create(
{
"currency_id": currency_id.id,
"rate": rate,
"name": date.today(),
}
)

def test_pricelist_based_on_product_category(self):
self.pricelist.item_ids[0].write(
Expand Down Expand Up @@ -259,8 +252,8 @@ def test_pricelist_and_supplierinfo_currencies(self):
# and pricelist with different currencies
currency_usd = self.env.ref("base.USD")
currency_mxn = self.env.ref("base.MXN")
self._update_rate(currency_usd, 1)
self._update_rate(currency_mxn, 20)
self._create_rate(currency_usd, 1)
self._create_rate(currency_mxn, 20)

# Setting the item with the product
self.pricelist.item_ids[0].write(
Expand Down Expand Up @@ -327,3 +320,15 @@ def test_pricelist_exclude_supplier_info_discount(self):
self.pricelist._get_product_price(self.product, 1),
10,
)

def test_pricelist_price_not_based_on_supplierinfo(self):
"""Test the scenario where the pricelist is not based on the supplier info,
so the price should be calculated as expected natively.
"""
self.pricelist.item_ids[0].base = "list_price"
product_template = self.product.product_tmpl_id
expected_price = product_template._price_compute("list_price")
self.assertAlmostEqual(
self.pricelist._get_product_price(self.product, 1),
expected_price[product_template.id],
)

0 comments on commit 25e8f5a

Please sign in to comment.