diff --git a/product_main_supplierinfo/README.rst b/product_main_supplierinfo/README.rst new file mode 100644 index 00000000000..f7b48627bc7 --- /dev/null +++ b/product_main_supplierinfo/README.rst @@ -0,0 +1,86 @@ +=================== +Product Main Vendor +=================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:111d9997bccee36ca5a1d47aac2895947a0dae0c5d8b9adb856ab7a13834aed4 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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_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-16-0/product-attribute-16-0-product_main_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=16.0 + :alt: Try me on Runboat + +|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 to smash 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 00000000000..0650744f6bc --- /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 00000000000..0f3f4b2256e --- /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": "16.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/i18n/es.po b/product_main_supplierinfo/i18n/es.po new file mode 100644 index 00000000000..8f6892a2f50 --- /dev/null +++ b/product_main_supplierinfo/i18n/es.po @@ -0,0 +1,42 @@ +# 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" +"PO-Revision-Date: 2024-01-15 16:36+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: none\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: product_main_supplierinfo +#: model:ir.model.fields,field_description:product_main_supplierinfo.field_product_product__display_name +msgid "Display Name" +msgstr "Mostrar Nombre" + +#. module: product_main_supplierinfo +#: model:ir.model.fields,field_description:product_main_supplierinfo.field_product_product__id +msgid "ID" +msgstr "ID" + +#. module: product_main_supplierinfo +#: model:ir.model.fields,field_description:product_main_supplierinfo.field_product_product____last_update +msgid "Last Modified on" +msgstr "Última Modificación el" + +#. module: product_main_supplierinfo +#: model:ir.model.fields,field_description:product_main_supplierinfo.field_product_product__main_seller_id +msgid "Main Vendor" +msgstr "Vendedor Principal" + +#. module: product_main_supplierinfo +#: model:ir.model,name:product_main_supplierinfo.model_product_product +msgid "Product" +msgstr "Producto" diff --git a/product_main_supplierinfo/i18n/fr.po b/product_main_supplierinfo/i18n/fr.po new file mode 100644 index 00000000000..335a12156cc --- /dev/null +++ b/product_main_supplierinfo/i18n/fr.po @@ -0,0 +1,40 @@ +# 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: Automatically generated\n" +"Language-Team: none\n" +"Language: fr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n > 1;\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 "" diff --git a/product_main_supplierinfo/i18n/it.po b/product_main_supplierinfo/i18n/it.po new file mode 100644 index 00000000000..03e421e9ab6 --- /dev/null +++ b/product_main_supplierinfo/i18n/it.po @@ -0,0 +1,42 @@ +# 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" +"PO-Revision-Date: 2023-11-03 13:36+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: product_main_supplierinfo +#: model:ir.model.fields,field_description:product_main_supplierinfo.field_product_product__display_name +msgid "Display Name" +msgstr "Nome visualizzato" + +#. module: product_main_supplierinfo +#: model:ir.model.fields,field_description:product_main_supplierinfo.field_product_product__id +msgid "ID" +msgstr "ID" + +#. module: product_main_supplierinfo +#: model:ir.model.fields,field_description:product_main_supplierinfo.field_product_product____last_update +msgid "Last Modified on" +msgstr "Ultima modifica il" + +#. module: product_main_supplierinfo +#: model:ir.model.fields,field_description:product_main_supplierinfo.field_product_product__main_seller_id +msgid "Main Vendor" +msgstr "Fornitore principale" + +#. module: product_main_supplierinfo +#: model:ir.model,name:product_main_supplierinfo.model_product_product +msgid "Product" +msgstr "Prodotto" 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 00000000000..8ab2a362190 --- /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 "" diff --git a/product_main_supplierinfo/models/__init__.py b/product_main_supplierinfo/models/__init__.py new file mode 100644 index 00000000000..5c74c8c30f1 --- /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 00000000000..933c97bebd2 --- /dev/null +++ b/product_main_supplierinfo/models/product_product.py @@ -0,0 +1,55 @@ +# 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.partner_id.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(False).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.filtered(lambda s: (s.product_id == self)) + if not sellers: + sellers = all_sellers.filtered(lambda s: not s.product_id) + return sellers.sorted("price") diff --git a/product_main_supplierinfo/readme/CONTRIBUTORS.rst b/product_main_supplierinfo/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..046ba7c569e --- /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 00000000000..158e07c5435 --- /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/icon.png b/product_main_supplierinfo/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/product_main_supplierinfo/static/description/icon.png differ diff --git a/product_main_supplierinfo/static/description/index.html b/product_main_supplierinfo/static/description/index.html new file mode 100644 index 00000000000..b458c331f6b --- /dev/null +++ b/product_main_supplierinfo/static/description/index.html @@ -0,0 +1,428 @@ + + + + + +Product Main Vendor + + + +
+

Product Main Vendor

+ + +

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

+

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 to smash 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 00000000000..f827dc0fbd8 --- /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 00000000000..d98192cbf64 --- /dev/null +++ b/product_main_supplierinfo/tests/test_product_main_supplier.py @@ -0,0 +1,117 @@ +# 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_1.price = 700 + cls.seller_2 = cls.env.ref("product.product_supplierinfo_2") + cls.seller_2.sequence = 2 + cls.seller_2.price = 720 + cls.seller_2bis = cls.env.ref("product.product_supplierinfo_2bis") + cls.seller_2bis.sequence = 3 + cls.seller_2bis.price = 740 + cls.company_2 = cls.env.company.create({"name": "Company2"}) + # For the test case 4 + cls.attribute = cls.env["product.attribute"].create({"name": "Size"}) + cls.attribute_value_1 = cls.env["product.attribute.value"].create( + {"name": "L", "attribute_id": cls.attribute.id} + ) + cls.attribute_value_2 = cls.env["product.attribute.value"].create( + {"name": "XL", "attribute_id": cls.attribute.id} + ) + cls.template1 = cls.env["product.template"].create( + { + "name": "Hat", + "attribute_line_ids": [ + ( + 0, + 0, + { + "attribute_id": cls.attribute.id, + "value_ids": [ + ( + 6, + 0, + [ + cls.attribute_value_1.id, + cls.attribute_value_2.id, + ], + ) + ], + }, + ), + ], + } + ) + cls.product_1 = cls.template1.product_variant_ids[0] + cls.product_2 = cls.template1.product_variant_ids[1] + cls.date_old = "2000-01-01" + cls.date_older = "2000-12-31" + cls.product_template_supply = cls.seller_2.copy( + { + "product_tmpl_id": cls.product_2.product_tmpl_id.id, + "sequence": 1, + "date_start": cls.date_older, + "date_end": cls.date_old, + } + ) + cls.product_1_supply = cls.seller_1.copy( + { + "product_tmpl_id": cls.product_1.product_tmpl_id.id, + "product_id": cls.product_1.id, + "sequence": 2, + "date_start": cls.date_older, + "date_end": cls.date_old, + } + ) + cls.product_2_supply = cls.seller_2.copy( + { + "product_tmpl_id": cls.product_2.product_tmpl_id.id, + "product_id": cls.product_2.id, + "sequence": 3, + "date_start": cls.date_older, + "date_end": cls.date_old, + } + ) + + 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.price = 650 + 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) + + def test_main_seller_4(self): + """Case 4: No valid supplier so select one related to the variant.""" + self.assertEqual(self.product_1.main_seller_id, self.product_1_supply) + self.assertEqual(self.product_2.main_seller_id, self.product_2_supply) diff --git a/product_main_supplierinfo/views/product_product.xml b/product_main_supplierinfo/views/product_product.xml new file mode 100644 index 00000000000..c95c72e1ead --- /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 + + + + + + + + + diff --git a/setup/product_main_supplierinfo/odoo/addons/product_main_supplierinfo b/setup/product_main_supplierinfo/odoo/addons/product_main_supplierinfo new file mode 120000 index 00000000000..33822983817 --- /dev/null +++ b/setup/product_main_supplierinfo/odoo/addons/product_main_supplierinfo @@ -0,0 +1 @@ +../../../../product_main_supplierinfo \ No newline at end of file diff --git a/setup/product_main_supplierinfo/setup.py b/setup/product_main_supplierinfo/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/product_main_supplierinfo/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)