mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
Merge branch 'new/12.0/product_variant_so_always' into 12.0-test
This commit is contained in:
1
product_variant_so_always/__init__.py
Executable file
1
product_variant_so_always/__init__.py
Executable file
@@ -0,0 +1 @@
|
||||
from . import models
|
||||
22
product_variant_so_always/__manifest__.py
Executable file
22
product_variant_so_always/__manifest__.py
Executable file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
'name': 'Product Variant Always on SO',
|
||||
'author': 'Hibou Corp. <hello@hibou.io>',
|
||||
'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',
|
||||
],
|
||||
}
|
||||
1
product_variant_so_always/models/__init__.py
Normal file
1
product_variant_so_always/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import product
|
||||
13
product_variant_so_always/models/product.py
Normal file
13
product_variant_so_always/models/product.py
Normal file
@@ -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()
|
||||
1
product_variant_so_always/tests/__init__.py
Normal file
1
product_variant_so_always/tests/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import test_product_creation
|
||||
45
product_variant_so_always/tests/test_product_creation.py
Normal file
45
product_variant_so_always/tests/test_product_creation.py
Normal file
@@ -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()
|
||||
17
product_variant_so_always/views/product_views.xml
Normal file
17
product_variant_so_always/views/product_views.xml
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
|
||||
<record id="product_template_only_form_view_inherit" model="ir.ui.view">
|
||||
<field name="name">product.template.product.form.inherit</field>
|
||||
<field name="model">product.template</field>
|
||||
<field name="inherit_id" ref="product.product_template_only_form_view"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='attribute_line_ids']" position="before">
|
||||
<group>
|
||||
<field name="always_variant_on_so"/>
|
||||
</group>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user