From 0f1a8e9475f6cd22f50730c0058b2578993e69c6 Mon Sep 17 00:00:00 2001
From: "Christihan Laurel [Vauxoo]"
Date: Mon, 13 Jan 2025 20:59:37 +0000
Subject: [PATCH] [MIG] product_pricelist_supplierinfo: Migration to 18.0
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.
- Add a test for the scenarios where there are no sellers linked to the
product and no product variants linked to the product template.
- 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
---
product_pricelist_supplierinfo/README.rst | 10 ++--
.../__manifest__.py | 2 +-
.../models/product_template.py | 2 +-
.../static/description/index.html | 6 +-
.../tests/test_product_supplierinfo.py | 56 +++++++++++++------
5 files changed, 49 insertions(+), 27 deletions(-)
diff --git a/product_pricelist_supplierinfo/README.rst b/product_pricelist_supplierinfo/README.rst
index 041be8de661..892102ccc0c 100644
--- a/product_pricelist_supplierinfo/README.rst
+++ b/product_pricelist_supplierinfo/README.rst
@@ -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|
@@ -102,7 +102,7 @@ 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 to smash it by providing a detailed and welcomed
-`feedback `_.
+`feedback `_.
Do not contact contributors directly about support or help with technical issues.
@@ -152,6 +152,6 @@ Current `maintainer `__:
|maintainer-luisg123v|
-This module is part of the `OCA/product-attribute `_ project on GitHub.
+This module is part of the `OCA/product-attribute `_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
diff --git a/product_pricelist_supplierinfo/__manifest__.py b/product_pricelist_supplierinfo/__manifest__.py
index b036ae070c8..681768e2529 100644
--- a/product_pricelist_supplierinfo/__manifest__.py
+++ b/product_pricelist_supplierinfo/__manifest__.py
@@ -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",
diff --git a/product_pricelist_supplierinfo/models/product_template.py b/product_pricelist_supplierinfo/models/product_template.py
index 32c7dd91c10..41f2170fde9 100644
--- a/product_pricelist_supplierinfo/models/product_template.py
+++ b/product_pricelist_supplierinfo/models/product_template.py
@@ -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
diff --git a/product_pricelist_supplierinfo/static/description/index.html b/product_pricelist_supplierinfo/static/description/index.html
index 15344fe2044..1754eaeab8e 100644
--- a/product_pricelist_supplierinfo/static/description/index.html
+++ b/product_pricelist_supplierinfo/static/description/index.html
@@ -369,7 +369,7 @@ Supplier info prices in sales pricelists
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:3b1eaa22384d0573346866a317e714b3d95555e79eaf6a24283febb60d1e7e16
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
-
![Try me on Runboat](https://img.shields.io/badge/runboat-Try%20me-875A7B.png)
+
![Try me on Runboat](https://img.shields.io/badge/runboat-Try%20me-875A7B.png)
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.
@@ -451,7 +451,7 @@
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 to smash it by providing a detailed and welcomed
-feedback.
+feedback.
Do not contact contributors directly about support or help with technical issues.
diff --git a/product_pricelist_supplierinfo/tests/test_product_supplierinfo.py b/product_pricelist_supplierinfo/tests/test_product_supplierinfo.py
index 1aec56a3737..3278a97b918 100644
--- a/product_pricelist_supplierinfo/tests/test_product_supplierinfo.py
+++ b/product_pricelist_supplierinfo/tests/test_product_supplierinfo.py
@@ -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"})
@@ -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(
@@ -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(
@@ -327,3 +320,32 @@ 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],
+ )
+
+ def test_no_sellers_and_no_product_variants(self):
+ """Test scenarios where there are no sellers linked to the product and no
+ product variants linked to the product template.
+ """
+ product_template = self.product.product_tmpl_id
+ self.product.seller_ids = False
+ price = product_template._get_supplierinfo_pricelist_price(
+ self.pricelist.item_ids[0]
+ )
+ self.assertAlmostEqual(price, 0)
+
+ product_template.product_variant_ids = False
+ price = product_template._get_supplierinfo_pricelist_price(
+ self.pricelist.item_ids[0]
+ )
+ self.assertAlmostEqual(price, 0)