From 91b45e328d7cbb68a75763a5fb379468dad50a2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Mart=C3=ADnez?= Date: Tue, 25 Jun 2024 12:35:03 +0200 Subject: [PATCH] [MIG] purchase_variant_configurator_on_confirm: Migration to 16.0 TT46597 --- .../README.rst | 10 +-- .../__manifest__.py | 5 +- .../models/purchase_order.py | 40 +++++----- .../static/description/index.html | 7 +- .../tests/test_purchase_order.py | 76 ++++++++++--------- .../views/inherited_purchase_order_views.xml | 2 +- 6 files changed, 74 insertions(+), 66 deletions(-) diff --git a/purchase_variant_configurator_on_confirm/README.rst b/purchase_variant_configurator_on_confirm/README.rst index 822f5e85f..b4e49f25c 100644 --- a/purchase_variant_configurator_on_confirm/README.rst +++ b/purchase_variant_configurator_on_confirm/README.rst @@ -17,13 +17,13 @@ Purchase Variant Configurator On Confirm :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--variant-lightgray.png?logo=github - :target: https://github.com/OCA/product-variant/tree/13.0/purchase_variant_configurator_on_confirm + :target: https://github.com/OCA/product-variant/tree/16.0/purchase_variant_configurator_on_confirm :alt: OCA/product-variant .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/product-variant-13-0/product-variant-13-0-purchase_variant_configurator_on_confirm + :target: https://translation.odoo-community.org/projects/product-variant-16-0/product-variant-16-0-purchase_variant_configurator_on_confirm :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-variant&target_branch=13.0 + :target: https://runboat.odoo-community.org/builds?repo=OCA/product-variant&target_branch=16.0 :alt: Try me on Runboat |badge1| |badge2| |badge3| |badge4| |badge5| @@ -41,7 +41,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. @@ -82,6 +82,6 @@ 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-variant `_ project on GitHub. +This module is part of the `OCA/product-variant `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/purchase_variant_configurator_on_confirm/__manifest__.py b/purchase_variant_configurator_on_confirm/__manifest__.py index 8a701dcea..43a897b79 100644 --- a/purchase_variant_configurator_on_confirm/__manifest__.py +++ b/purchase_variant_configurator_on_confirm/__manifest__.py @@ -5,9 +5,8 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { "name": "Purchase Variant Configurator On Confirm", - "summary": """ - Create product variants when confirming the purchase order""", - "version": "13.0.1.0.0", + "summary": "Create product variants when confirming the purchase order", + "version": "16.0.1.0.0", "license": "AGPL-3", "author": "AvanzOSC, " "Tecnativa, " diff --git a/purchase_variant_configurator_on_confirm/models/purchase_order.py b/purchase_variant_configurator_on_confirm/models/purchase_order.py index f89ddbf60..a3f2a6ac6 100644 --- a/purchase_variant_configurator_on_confirm/models/purchase_order.py +++ b/purchase_variant_configurator_on_confirm/models/purchase_order.py @@ -63,7 +63,7 @@ def _onchange_product_tmpl_id_configurator(self): a virtual product created on the fly. """ res = super()._onchange_product_tmpl_id_configurator() - if not self.product_id: + if not self.product_id and self.product_tmpl_id: self.product_id = self.product_tmpl_id._product_from_tmpl() # HACK: With NewId, the `search` method that looks for vendor pricelists # related to the product is unable to find the linked template as the @@ -74,26 +74,28 @@ def _onchange_product_tmpl_id_configurator(self): self.with_context( pvc_product_tmpl=self.product_tmpl_id.id ).onchange_product_id() - self.product_id = False - # HACK: With NewId, making `with_context` loses temp values, so we - # need to recreate these operations - product_lang = self.product_tmpl_id.with_context( - {"lang": self.partner_id.lang, "partner_id": self.partner_id.id} - ) - self.name = product_lang.display_name - if product_lang.description_purchase: - self.name += "\n" + product_lang.description_purchase return res - def create(self, vals): + @api.model + def _get_product_description(self, template, product, product_attributes): + """Add description_purchase to name field (similar to what purchase does).""" + name = super()._get_product_description( + template=template, product=product, product_attributes=product_attributes + ) + if template.description_purchase: + name += "\n" + template.description_purchase + return name + + @api.model_create_multi + def create(self, vals_list): """Create variant before calling super when the purchase order is confirmed, as it creates associated stock moves. """ - if "order_id" not in vals or vals.get("product_id"): - return super().create(vals) - order = self.env["purchase.order"].browse(vals["order_id"]) - if order.state == "purchase": - line = self.new(vals) - product = line.create_variant_if_needed() - vals["product_id"] = product.id - return super().create(vals) + for vals in vals_list: + if vals.get("order_id") and not vals.get("product_id"): + order = self.env["purchase.order"].browse(vals["order_id"]) + if order.state == "purchase": + line = self.new(vals) + product = line.create_variant_if_needed() + vals["product_id"] = product.id + return super().create(vals_list) diff --git a/purchase_variant_configurator_on_confirm/static/description/index.html b/purchase_variant_configurator_on_confirm/static/description/index.html index 7b92db040..b1256c16f 100644 --- a/purchase_variant_configurator_on_confirm/static/description/index.html +++ b/purchase_variant_configurator_on_confirm/static/description/index.html @@ -1,4 +1,3 @@ - @@ -369,7 +368,7 @@

Purchase Variant Configurator On Confirm

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! source digest: sha256:c3e2e02c44ae9bde4f5da3f1235fc0708bd7ffd3fca00def779795f66484776f !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

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

+

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

Create product variants when confirming the purchase order.

Table of contents

@@ -388,7 +387,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.

@@ -424,7 +423,7 @@

Maintainers

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-variant project on GitHub.

+

This module is part of the OCA/product-variant project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

diff --git a/purchase_variant_configurator_on_confirm/tests/test_purchase_order.py b/purchase_variant_configurator_on_confirm/tests/test_purchase_order.py index 00ef34a2f..0d8d0ed67 100644 --- a/purchase_variant_configurator_on_confirm/tests/test_purchase_order.py +++ b/purchase_variant_configurator_on_confirm/tests/test_purchase_order.py @@ -1,9 +1,11 @@ # Copyright 2017 Tecnativa - David Vidal # License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html -from odoo.tests import Form, common +from odoo.tests import Form +from odoo.addons.base.tests.common import BaseCommon -class TestPurchaseOrder(common.SavepointCase): + +class TestPurchaseOrder(BaseCommon): @classmethod def setUpClass(cls): super().setUpClass() @@ -31,6 +33,7 @@ def setUpClass(cls): { "name": cls.template_name, "no_create_variants": "yes", + "description_purchase": "Purchase Description", "categ_id": cls.category1.id, "standard_price": 100, "attribute_line_ids": [ @@ -48,7 +51,7 @@ def setUpClass(cls): cls.supplier_pricelist = cls.env["product.supplierinfo"].create( { "product_tmpl_id": cls.product_template_yes.id, - "name": cls.supplier.id, + "partner_id": cls.supplier.id, "min_qty": 11, "price": 90, } @@ -61,52 +64,57 @@ def setUpClass(cls): "description_purchase": "Purchase Description", } ) + cls.env.user.groups_id += cls.env.ref("uom.group_uom") cls.order = cls.env["purchase.order"].create({"partner_id": cls.supplier.id}) def test_onchange_product_tmpl_id(self): purchase = Form(self.order) - with purchase.order_line.new() as line: - line.product_tmpl_id = self.product_template_yes - self.assertEqual(line.name, self.template_name) + with purchase.order_line.new() as line_form: + line_form.product_tmpl_id = self.product_template_yes + purchase.save() + line = self.order.order_line + self.assertFalse(line.product_id) + self.assertIn(self.template_name, line.name) + self.assertIn("Purchase Description", line.name) self.assertEqual(line.product_uom, self.product_template_yes.uom_id) self.assertEqual(line.price_unit, 90) self.assertEqual(line.product_qty, 11) self.assertTrue(line.date_planned) + self.order.button_confirm() + self.assertTrue(line.product_id) + self.assertIn(self.template_name, line.name) + self.assertIn("Purchase Description", line.name) def test_button_confirm(self): - line1 = self.env["purchase.order.line"].new( - { - "order_id": self.order.id, - "product_tmpl_id": self.product_template_yes.id, - } - ) - line1._onchange_product_tmpl_id_configurator() - line1.product_attribute_ids[0].value_id = self.value1.id - line1 = line1.create(line1._convert_to_write(line1._cache)) + purchase = Form(self.order) + with purchase.order_line.new() as line_form: + line_form.product_tmpl_id = self.product_template_yes + with line_form.product_attribute_ids.edit(0) as pa_form: + pa_form.value_id = self.value1 + purchase.save() + line1 = self.order.order_line + self.assertFalse(line1.product_id) self.order.button_confirm() self.assertTrue(line1.product_id) - line2 = self.env["purchase.order.line"].new( - { - "order_id": self.order.id, - "product_tmpl_id": self.product_template_yes.id, - } - ) - line2._onchange_product_tmpl_id_configurator() - line2.product_attribute_ids[0].value_id = self.value1.id - line2 = line2.create(line2._convert_to_write(line2._cache)) + purchase = Form(self.order) + with purchase.order_line.new() as line_form: + line_form.product_tmpl_id = self.product_template_yes + with line_form.product_attribute_ids.edit(0) as pa_form: + pa_form.value_id = self.value2 + purchase.save() + line2 = self.order.order_line - line1 self.assertTrue(line2.product_id) + self.assertNotEqual(line1.product_id, line2.product_id) def test_copy(self): - line1 = self.env["purchase.order.line"].new( - { - "order_id": self.order.id, - "product_tmpl_id": self.product_template_yes.id, - } - ) - line1._onchange_product_tmpl_id_configurator() - line1.product_attribute_ids[0].value_id = self.value1.id + purchase = Form(self.order) + old_date = "2017-01-01" + with purchase.order_line.new() as line_form: + line_form.product_tmpl_id = self.product_template_yes + line_form.date_planned = old_date + with line_form.product_attribute_ids.edit(0) as pa_form: + pa_form.value_id = self.value1 + purchase.save() old_date = "2017-01-01" - line1.date_planned = old_date - line1.create(line1._convert_to_write(line1._cache)) new_order = self.order.copy() self.assertNotEqual(new_order.order_line.date_planned, old_date) diff --git a/purchase_variant_configurator_on_confirm/views/inherited_purchase_order_views.xml b/purchase_variant_configurator_on_confirm/views/inherited_purchase_order_views.xml index 747519d47..51aa8fc17 100644 --- a/purchase_variant_configurator_on_confirm/views/inherited_purchase_order_views.xml +++ b/purchase_variant_configurator_on_confirm/views/inherited_purchase_order_views.xml @@ -1,6 +1,6 @@ - + purchase.order.extended.form purchase.order