From 5fe32edd5cc4ecf959e475597f4af48ee41a1d58 Mon Sep 17 00:00:00 2001 From: Jared Kipe Date: Fri, 26 Jul 2019 10:27:13 -0700 Subject: [PATCH 1/4] NEW `product_variant_so_always` for 11.0 Adds boolean on the `product.template` form to force the 'dynamic' mode for NOT creating variants on `product.template` save, but rather when added to sale orders. --- product_variant_so_always/__init__.py | 1 + product_variant_so_always/__manifest__.py | 22 +++++++++ product_variant_so_always/models/__init__.py | 1 + product_variant_so_always/models/product.py | 13 ++++++ product_variant_so_always/tests/__init__.py | 1 + .../tests/test_product_creation.py | 45 +++++++++++++++++++ .../views/product_views.xml | 17 +++++++ 7 files changed, 100 insertions(+) create mode 100755 product_variant_so_always/__init__.py create mode 100755 product_variant_so_always/__manifest__.py create mode 100644 product_variant_so_always/models/__init__.py create mode 100644 product_variant_so_always/models/product.py create mode 100644 product_variant_so_always/tests/__init__.py create mode 100644 product_variant_so_always/tests/test_product_creation.py create mode 100644 product_variant_so_always/views/product_views.xml diff --git a/product_variant_so_always/__init__.py b/product_variant_so_always/__init__.py new file mode 100755 index 00000000..0650744f --- /dev/null +++ b/product_variant_so_always/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/product_variant_so_always/__manifest__.py b/product_variant_so_always/__manifest__.py new file mode 100755 index 00000000..95c684d0 --- /dev/null +++ b/product_variant_so_always/__manifest__.py @@ -0,0 +1,22 @@ +{ + 'name': 'Product Variant Always on SO', + 'author': 'Hibou Corp. ', + 'category': 'Hidden', + 'version': '12.0.1.0.0', + 'description': + """ +Product Variant Always on SO +============================ + +The default limit in Odoo to 'always create variants' is 1000, but if you have a product +that needs to use 'always create variants' attributes AND you have too many attributes, +you may wish to have it behave as if it has attributes that + """, + 'depends': [ + 'sale', + ], + 'auto_install': False, + 'data': [ + 'views/product_views.xml', + ], +} diff --git a/product_variant_so_always/models/__init__.py b/product_variant_so_always/models/__init__.py new file mode 100644 index 00000000..23275437 --- /dev/null +++ b/product_variant_so_always/models/__init__.py @@ -0,0 +1 @@ +from . import product \ No newline at end of file diff --git a/product_variant_so_always/models/product.py b/product_variant_so_always/models/product.py new file mode 100644 index 00000000..d8489fa8 --- /dev/null +++ b/product_variant_so_always/models/product.py @@ -0,0 +1,13 @@ +from odoo import fields, models + + +class ProductTemplate(models.Model): + _inherit = 'product.template' + + always_variant_on_so = fields.Boolean(string='Always create variants on SO Lines') + + def has_dynamic_attributes(self): + self.ensure_one() + if self.always_variant_on_so: + return True + return super(ProductTemplate, self).has_dynamic_attributes() diff --git a/product_variant_so_always/tests/__init__.py b/product_variant_so_always/tests/__init__.py new file mode 100644 index 00000000..6919398d --- /dev/null +++ b/product_variant_so_always/tests/__init__.py @@ -0,0 +1 @@ +from . import test_product_creation diff --git a/product_variant_so_always/tests/test_product_creation.py b/product_variant_so_always/tests/test_product_creation.py new file mode 100644 index 00000000..befb9a99 --- /dev/null +++ b/product_variant_so_always/tests/test_product_creation.py @@ -0,0 +1,45 @@ +from odoo.tests import common +from odoo.exceptions import UserError + + +class TestProductCreation(common.TransactionCase): + def setUp(self): + super(TestProductCreation, self).setUp() + self.attrs = [] + + # Create 1000 combinations + for a in range(1, 4): + attribute = self.env['product.attribute'].create({ + 'name': 'Attr ' + str(a), + 'type': 'radio', + 'create_variant': 'always', + }) + self.attrs.append(attribute) + for v in range(1, 11): + self.env['product.attribute.value'].create({ + 'name': 'Value ' + str(v), + 'attribute_id': attribute.id, + }) + # Create 1 more... + self.env['product.attribute.value'].create({ + 'name': 'Value 11', + 'attribute_id': self.attrs[0].id, + }) + + def test_01_product_template(self): + product_tmpl = self.env['product.template'].create({ + 'name': 'Test Product', + 'type': 'product', + }) + attr_line_model = self.env['product.template.attribute.line'] + for a in self.attrs: + attr_line_model.create({ + 'product_tmpl_id': product_tmpl.id, + 'attribute_id': a.id, + 'value_ids': [(6, 0, a.value_ids.ids)], + }) + with self.assertRaises(UserError): + product_tmpl.create_variant_ids() + + product_tmpl.always_variant_on_so = True + product_tmpl.create_variant_ids() diff --git a/product_variant_so_always/views/product_views.xml b/product_variant_so_always/views/product_views.xml new file mode 100644 index 00000000..d28f9f28 --- /dev/null +++ b/product_variant_so_always/views/product_views.xml @@ -0,0 +1,17 @@ + + + + + product.template.product.form.inherit + product.template + + + + + + + + + + + \ No newline at end of file From 0b30a958a27848a61a768dcc5746ac75a29a8d09 Mon Sep 17 00:00:00 2001 From: Jared Kipe Date: Fri, 26 Jul 2019 10:44:33 -0700 Subject: [PATCH 2/4] FIX `product_variant_so_always` Checkbox placement displayed in the wrong location on deployment. --- product_variant_so_always/views/product_views.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/product_variant_so_always/views/product_views.xml b/product_variant_so_always/views/product_views.xml index d28f9f28..3cbcaca3 100644 --- a/product_variant_so_always/views/product_views.xml +++ b/product_variant_so_always/views/product_views.xml @@ -6,7 +6,7 @@ product.template - + From e894ac79ad75762681ac4a9f533508c5fef3237e Mon Sep 17 00:00:00 2001 From: Connor Christian Date: Tue, 10 Nov 2020 16:31:07 -0500 Subject: [PATCH 3/4] [MIG] product_variant_so_always: for Odoo 13.0 --- product_variant_so_always/__manifest__.py | 2 +- .../tests/test_product_creation.py | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/product_variant_so_always/__manifest__.py b/product_variant_so_always/__manifest__.py index 95c684d0..16b441d2 100755 --- a/product_variant_so_always/__manifest__.py +++ b/product_variant_so_always/__manifest__.py @@ -2,7 +2,7 @@ 'name': 'Product Variant Always on SO', 'author': 'Hibou Corp. ', 'category': 'Hidden', - 'version': '12.0.1.0.0', + 'version': '13.0.1.0.0', 'description': """ Product Variant Always on SO diff --git a/product_variant_so_always/tests/test_product_creation.py b/product_variant_so_always/tests/test_product_creation.py index befb9a99..65fe12df 100644 --- a/product_variant_so_always/tests/test_product_creation.py +++ b/product_variant_so_always/tests/test_product_creation.py @@ -11,7 +11,6 @@ class TestProductCreation(common.TransactionCase): for a in range(1, 4): attribute = self.env['product.attribute'].create({ 'name': 'Attr ' + str(a), - 'type': 'radio', 'create_variant': 'always', }) self.attrs.append(attribute) @@ -32,14 +31,19 @@ class TestProductCreation(common.TransactionCase): 'type': 'product', }) attr_line_model = self.env['product.template.attribute.line'] + + with self.assertRaises(UserError): + for a in self.attrs: + attr_line_model.create({ + 'product_tmpl_id': product_tmpl.id, + 'attribute_id': a.id, + 'value_ids': [(6, 0, a.value_ids.ids)], + }) + + product_tmpl.always_variant_on_so = True for a in self.attrs: attr_line_model.create({ 'product_tmpl_id': product_tmpl.id, 'attribute_id': a.id, 'value_ids': [(6, 0, a.value_ids.ids)], }) - with self.assertRaises(UserError): - product_tmpl.create_variant_ids() - - product_tmpl.always_variant_on_so = True - product_tmpl.create_variant_ids() From 2ca698748fb7d2e76b8c0b4541b0fa21062a4f9d Mon Sep 17 00:00:00 2001 From: Connor Christian Date: Wed, 11 Nov 2020 15:55:46 -0500 Subject: [PATCH 4/4] [MIG] product_variant_so_always: for Odoo 14.0 --- product_variant_so_always/__manifest__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/product_variant_so_always/__manifest__.py b/product_variant_so_always/__manifest__.py index 16b441d2..95796672 100755 --- a/product_variant_so_always/__manifest__.py +++ b/product_variant_so_always/__manifest__.py @@ -2,7 +2,7 @@ 'name': 'Product Variant Always on SO', 'author': 'Hibou Corp. ', 'category': 'Hidden', - 'version': '13.0.1.0.0', + 'version': '14.0.1.0.0', 'description': """ Product Variant Always on SO