From 774c0788040aae2ffc6b029506cbf7bfd1013b5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Alix?= Date: Tue, 19 Oct 2021 16:26:34 +0200 Subject: [PATCH 01/17] [ADD] New module 'product_main_supplierinfo' --- product_main_supplierinfo/README.rst | 83 ++++ product_main_supplierinfo/__init__.py | 1 + product_main_supplierinfo/__manifest__.py | 17 + product_main_supplierinfo/models/__init__.py | 1 + .../models/product_product.py | 53 +++ .../readme/CONTRIBUTORS.rst | 3 + .../readme/DESCRIPTION.rst | 1 + .../static/description/index.html | 424 ++++++++++++++++++ product_main_supplierinfo/tests/__init__.py | 1 + .../tests/test_product_main_supplier.py | 47 ++ .../views/product_product.xml | 30 ++ 11 files changed, 661 insertions(+) create mode 100644 product_main_supplierinfo/README.rst create mode 100644 product_main_supplierinfo/__init__.py create mode 100644 product_main_supplierinfo/__manifest__.py create mode 100644 product_main_supplierinfo/models/__init__.py create mode 100644 product_main_supplierinfo/models/product_product.py create mode 100644 product_main_supplierinfo/readme/CONTRIBUTORS.rst create mode 100644 product_main_supplierinfo/readme/DESCRIPTION.rst create mode 100644 product_main_supplierinfo/static/description/index.html create mode 100644 product_main_supplierinfo/tests/__init__.py create mode 100644 product_main_supplierinfo/tests/test_product_main_supplier.py create mode 100644 product_main_supplierinfo/views/product_product.xml diff --git a/product_main_supplierinfo/README.rst b/product_main_supplierinfo/README.rst new file mode 100644 index 000000000000..b47220169236 --- /dev/null +++ b/product_main_supplierinfo/README.rst @@ -0,0 +1,83 @@ +=================== +Product Main Vendor +=================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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%2Fproduct--attribute-lightgray.png?logo=github + :target: https://github.com/OCA/product-attribute/tree/14.0/product_main_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-14-0/product-attribute-14-0-product_main_supplierinfo + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/135/14.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module shows the main vendor of a product. + +**Table of contents** + +.. contents:: + :local: + +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 +~~~~~~~ + +* Camptocamp + +Contributors +~~~~~~~~~~~~ + +* `Camptocamp `_ + + * Sébastien Alix + +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-sebalix| image:: https://github.com/sebalix.png?size=40px + :target: https://github.com/sebalix + :alt: sebalix + +Current `maintainer `__: + +|maintainer-sebalix| + +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_main_supplierinfo/__init__.py b/product_main_supplierinfo/__init__.py new file mode 100644 index 000000000000..0650744f6bc6 --- /dev/null +++ b/product_main_supplierinfo/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/product_main_supplierinfo/__manifest__.py b/product_main_supplierinfo/__manifest__.py new file mode 100644 index 000000000000..adc723689562 --- /dev/null +++ b/product_main_supplierinfo/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2021 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) +{ + "name": "Product Main Vendor", + "version": "14.0.1.0.0", + "summary": "Display the main vendor of a product.", + "website": "https://github.com/OCA/product-attribute", + "author": "Camptocamp, Odoo Community Association (OCA)", + "maintainers": ["sebalix"], + "development_status": "Beta", + "license": "AGPL-3", + "category": "Product", + "depends": ["product", "purchase"], + "data": ["views/product_product.xml"], + "auto_install": False, + "installable": True, +} diff --git a/product_main_supplierinfo/models/__init__.py b/product_main_supplierinfo/models/__init__.py new file mode 100644 index 000000000000..5c74c8c30f1e --- /dev/null +++ b/product_main_supplierinfo/models/__init__.py @@ -0,0 +1 @@ +from . import product_product diff --git a/product_main_supplierinfo/models/product_product.py b/product_main_supplierinfo/models/product_product.py new file mode 100644 index 000000000000..04bfdef451af --- /dev/null +++ b/product_main_supplierinfo/models/product_product.py @@ -0,0 +1,53 @@ +# Copyright 2021 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) + +from odoo import api, fields, models + + +class ProductProduct(models.Model): + _inherit = "product.product" + + main_seller_id = fields.Many2one( + comodel_name="product.supplierinfo", + string="Main Vendor", + compute="_compute_main_seller_id", + ) + + @api.depends( + "seller_ids.name.active", + "seller_ids.sequence", + "seller_ids.min_qty", + "seller_ids.price", + "seller_ids.company_id", + "seller_ids.product_id", + "seller_ids.date_start", + "seller_ids.date_end", + ) + @api.depends_context("company") + def _compute_main_seller_id(self): + for product in self: + sellers = product._get_sellers() + product.main_seller_id = fields.first(sellers) + + def _get_sellers(self): + """Returns all available sellers of a product based on some constraints. + + They are ordered and filtered like it is done in the standard 'product' addon. + """ + self.ensure_one() + all_sellers = self._prepare_sellers().filtered( + lambda s: not s.company_id or s.company_id.id == self.env.company.id + ) + today = fields.Date.context_today(self) + sellers = all_sellers.filtered( + lambda s: ( + (s.product_id == self or not s.product_id) + and ( + (s.date_start <= today if s.date_start else True) + and (s.date_end >= today if s.date_end else True) + ) + ) + ) + if not sellers: + sellers = all_sellers + return sellers diff --git a/product_main_supplierinfo/readme/CONTRIBUTORS.rst b/product_main_supplierinfo/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000000..046ba7c569ee --- /dev/null +++ b/product_main_supplierinfo/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Camptocamp `_ + + * Sébastien Alix diff --git a/product_main_supplierinfo/readme/DESCRIPTION.rst b/product_main_supplierinfo/readme/DESCRIPTION.rst new file mode 100644 index 000000000000..158e07c54359 --- /dev/null +++ b/product_main_supplierinfo/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module shows the main vendor of a product. diff --git a/product_main_supplierinfo/static/description/index.html b/product_main_supplierinfo/static/description/index.html new file mode 100644 index 000000000000..aadad70ef824 --- /dev/null +++ b/product_main_supplierinfo/static/description/index.html @@ -0,0 +1,424 @@ + + + + + + +Product Main Vendor + + + +
+

Product Main Vendor

+ + +

Beta License: AGPL-3 OCA/product-attribute Translate me on Weblate Try me on Runbot

+

This module shows the main vendor of a product.

+

Table of contents

+ +
+

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

+
    +
  • Camptocamp
  • +
+
+
+

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.

+

Current maintainer:

+

sebalix

+

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_main_supplierinfo/tests/__init__.py b/product_main_supplierinfo/tests/__init__.py new file mode 100644 index 000000000000..f827dc0fbd88 --- /dev/null +++ b/product_main_supplierinfo/tests/__init__.py @@ -0,0 +1 @@ +from . import test_product_main_supplier diff --git a/product_main_supplierinfo/tests/test_product_main_supplier.py b/product_main_supplierinfo/tests/test_product_main_supplier.py new file mode 100644 index 000000000000..1c5649af4a9d --- /dev/null +++ b/product_main_supplierinfo/tests/test_product_main_supplier.py @@ -0,0 +1,47 @@ +# Copyright 2021 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) + +from odoo import fields +from odoo.tests.common import SavepointCase + + +class TestProductMainSupplierInfo(SavepointCase): + @classmethod + def setUpClass(cls): + super(TestProductMainSupplierInfo, cls).setUpClass() + cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) + cls.product = cls.env.ref("product.product_product_6") + cls.seller_1 = cls.env.ref("product.product_supplierinfo_1") + cls.seller_1.sequence = 1 + cls.seller_2 = cls.env.ref("product.product_supplierinfo_2") + cls.seller_2.sequence = 2 + cls.seller_2bis = cls.env.ref("product.product_supplierinfo_2bis") + cls.seller_2bis.sequence = 3 + cls.company_2 = cls.env.company.create({"name": "Company2"}) + + def test_main_seller_1(self): + """"Case 1: all the sellers share the same company.""" + self.assertEqual(self.product.main_seller_id, self.seller_1) + self.seller_2.sequence = -1 + self.assertEqual(self.product.main_seller_id, self.seller_2) + + def test_main_seller_2(self): + """"Case 2: the sellers do not share the same company.""" + # Assign 'seller_1' to the second company, so the main vendor computed + # for the main company is now 'seller_2' + self.seller_1.company_id = self.company_2 + self.assertEqual(self.product.main_seller_id, self.seller_2) + # Check that the main vendor for the second company is 'seller_1' + self.assertEqual( + self.product.with_company(self.company_2).main_seller_id, + self.seller_1, + ) + + def test_main_seller_3(self): + """"Case 3: the sellers have different start/end dates.""" + today = fields.Date.today() + tomorrow = fields.Date.add(today, days=1) + yesterday = fields.Date.subtract(today, days=1) + self.seller_1.date_start = tomorrow + self.seller_2.date_end = yesterday + self.assertEqual(self.product.main_seller_id, self.seller_2bis) diff --git a/product_main_supplierinfo/views/product_product.xml b/product_main_supplierinfo/views/product_product.xml new file mode 100644 index 000000000000..c95c72e1eade --- /dev/null +++ b/product_main_supplierinfo/views/product_product.xml @@ -0,0 +1,30 @@ + + + + + + product.product.form.inherit + product.product + + + + + + + + + + + + product.product.tree.inherit + product.product + + + + + + + + + From 60ccfe4673686e0f3b175b18a3b7edac71958ecc Mon Sep 17 00:00:00 2001 From: oca-travis Date: Wed, 20 Oct 2021 10:21:58 +0000 Subject: [PATCH 02/17] [UPD] Update product_main_supplierinfo.pot --- .../i18n/product_main_supplierinfo.pot | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 product_main_supplierinfo/i18n/product_main_supplierinfo.pot diff --git a/product_main_supplierinfo/i18n/product_main_supplierinfo.pot b/product_main_supplierinfo/i18n/product_main_supplierinfo.pot new file mode 100644 index 000000000000..8ab2a362190b --- /dev/null +++ b/product_main_supplierinfo/i18n/product_main_supplierinfo.pot @@ -0,0 +1,39 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_main_supplierinfo +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.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: product_main_supplierinfo +#: model:ir.model.fields,field_description:product_main_supplierinfo.field_product_product__display_name +msgid "Display Name" +msgstr "" + +#. module: product_main_supplierinfo +#: model:ir.model.fields,field_description:product_main_supplierinfo.field_product_product__id +msgid "ID" +msgstr "" + +#. module: product_main_supplierinfo +#: model:ir.model.fields,field_description:product_main_supplierinfo.field_product_product____last_update +msgid "Last Modified on" +msgstr "" + +#. module: product_main_supplierinfo +#: model:ir.model.fields,field_description:product_main_supplierinfo.field_product_product__main_seller_id +msgid "Main Vendor" +msgstr "" + +#. module: product_main_supplierinfo +#: model:ir.model,name:product_main_supplierinfo.model_product_product +msgid "Product" +msgstr "" From 630bb637fc7f78a10282d69ce4722b6ba777d996 Mon Sep 17 00:00:00 2001 From: OCA-git-bot Date: Wed, 20 Oct 2021 10:54:54 +0000 Subject: [PATCH 03/17] [UPD] README.rst --- product_main_supplierinfo/static/description/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/product_main_supplierinfo/static/description/index.html b/product_main_supplierinfo/static/description/index.html index aadad70ef824..de78f44aac49 100644 --- a/product_main_supplierinfo/static/description/index.html +++ b/product_main_supplierinfo/static/description/index.html @@ -3,7 +3,7 @@ - + Product Main Vendor