diff --git a/product_configurator_default_val/README.rst b/product_configurator_default_val/README.rst new file mode 100644 index 00000000..b1e62994 --- /dev/null +++ b/product_configurator_default_val/README.rst @@ -0,0 +1,33 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +================================== +Product Configurator Default Value +================================== + +This module provides the scope to allow default value for attribute line. + +Usage +===== + +To use this module: + +* Go to Sales > Configurable Products > Configurable Templates +* Create or Select a configurable template +* In the Variants tab, enter the attribute and its values +* Enter a default attribute value +* Save the configurable template +* Run the configuration wizard in the back or on the website +* The default attribute value is selected by default + +Credits +======= + +* Paul Catinean +* Sandip Mangukiya + +Contributors +------------ + +* Ursa Information Systems diff --git a/product_configurator_default_val/__init__.py b/product_configurator_default_val/__init__.py new file mode 100755 index 00000000..75492fa5 --- /dev/null +++ b/product_configurator_default_val/__init__.py @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2012 - TODAY, Ursa Information Systems +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import ( + models, +) diff --git a/product_configurator_default_val/__manifest__.py b/product_configurator_default_val/__manifest__.py new file mode 100755 index 00000000..176a8daf --- /dev/null +++ b/product_configurator_default_val/__manifest__.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2012 - TODAY, Ursa Information Systems +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Product Configurator Default Value", + "summary": "To allow default value for attribute line", + "version": "10.0.1.0.0", + "license": "AGPL-3", + "author": "Ursa Information Systems", + "category": "Sales", + "maintainer": "Ursa Information Systems", + "website": "http://www.ursainfosystems.com", + "depends": [ + "product_configurator", + ], + "qweb": [ + ], + "data": [ + "views/product_view.xml", + ], + "application": False, +} diff --git a/product_configurator_default_val/models/__init__.py b/product_configurator_default_val/models/__init__.py new file mode 100755 index 00000000..6f33640e --- /dev/null +++ b/product_configurator_default_val/models/__init__.py @@ -0,0 +1,9 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2012 - TODAY, Ursa Information Systems +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import ( + product_config, + product_attribute, + product +) diff --git a/product_configurator_default_val/models/product.py b/product_configurator_default_val/models/product.py new file mode 100644 index 00000000..f9be29a1 --- /dev/null +++ b/product_configurator_default_val/models/product.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2012 - TODAY, Ursa Information Systems +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import api, models, _ +from odoo.exceptions import ValidationError + + +class ProductTemplate(models.Model): + _inherit = 'product.template' + + @api.multi + @api.constrains('attribute_line_ids') + def _check_default_values(self): + """Validate default values set on the product template""" + default_val_ids = self.attribute_line_ids.filtered( + lambda l: l.default_val).mapped('default_val').ids + + # TODO: Remove if cond when PR with raise error on github is merged + if not self.validate_configuration(default_val_ids, final=False): + raise ValidationError( + _('Default values provided generate an invalid configuration') + ) + + @api.multi + @api.constrains('config_line_ids') + def _check_default_value_domains(self): + try: + self._check_default_values() + except ValidationError: + raise ValidationError( + _('Restrictions added make the current default values ' + 'generate an invalid configuration') + ) diff --git a/product_configurator_default_val/models/product_attribute.py b/product_configurator_default_val/models/product_attribute.py new file mode 100644 index 00000000..f6645cb6 --- /dev/null +++ b/product_configurator_default_val/models/product_attribute.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2012 - TODAY, Ursa Information Systems +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import api, fields, models, _ +from odoo.exceptions import ValidationError + + +class ProductAttributeLine(models.Model): + _inherit = 'product.attribute.line' + + @api.onchange('value_ids') + def onchange_values(self): + if self.default_val and self.default_val not in self.value_ids: + self.default_val = None + + default_val = fields.Many2one( + comodel_name='product.attribute.value', + string='Default Value' + ) + + @api.multi + @api.constrains('value_ids', 'default_val') + def _check_default_values(self): + for line in self.filtered(lambda l: l.default_val): + if line.default_val not in line.value_ids: + raise ValidationError( + _("Default values for each attribute line must exist in " + "the attribute values (%s: %s)" % ( + line.attribute_id.name, line.default_val.name) + ) + ) diff --git a/product_configurator_default_val/models/product_config.py b/product_configurator_default_val/models/product_config.py new file mode 100644 index 00000000..8af7e7bb --- /dev/null +++ b/product_configurator_default_val/models/product_config.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2012 - TODAY, Ursa Information Systems +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, models, _ +from odoo.exceptions import ValidationError + + +class ProductConfigSession(models.Model): + _inherit = 'product.config.session' + + @api.model + def create(self, vals): + product_tmpl = self.env['product.template'].browse( + vals.get('product_tmpl_id')).exists() + if product_tmpl: + default_val_ids = product_tmpl.attribute_line_ids.filtered( + lambda l: l.default_val).mapped('default_val').ids + value_ids = vals.get('value_ids') + if value_ids: + default_val_ids += value_ids[0][2] + valid_conf = product_tmpl.validate_configuration( + default_val_ids, final=False) + # TODO: Remove if cond when PR with raise error on github is merged + if not valid_conf: + raise ValidationError( + _('Default values provided generate an invalid ' + 'configuration') + ) + vals.update({'value_ids': [(6, 0, default_val_ids)]}) + return super(ProductConfigSession, self).create(vals) diff --git a/product_configurator_default_val/static/description/icon.png b/product_configurator_default_val/static/description/icon.png new file mode 100644 index 00000000..601dab3d Binary files /dev/null and b/product_configurator_default_val/static/description/icon.png differ diff --git a/product_configurator_default_val/views/product_view.xml b/product_configurator_default_val/views/product_view.xml new file mode 100644 index 00000000..3af5045f --- /dev/null +++ b/product_configurator_default_val/views/product_view.xml @@ -0,0 +1,22 @@ + + + + + product.configurator.product.template.form + product.template + + + + + + + + + + diff --git a/product_configurator_refactor/README.rst b/product_configurator_refactor/README.rst new file mode 100644 index 00000000..1e81cdc9 --- /dev/null +++ b/product_configurator_refactor/README.rst @@ -0,0 +1,29 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg +:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +============================= +Product Configurator Refactor +============================= + +This module refactors the product configurator module to add the +product.attribute.value.line object to store additional fields specific to the +product-attribute-value. + +Usage +===== + +To use this module: + +* Go to Sales > Configurable Products + +Credits +======= + +* Paul Catinean +* Sandip Mangukiya + +Contributors +------------ + +* Ursa Information Systems diff --git a/product_configurator_refactor/__init__.py b/product_configurator_refactor/__init__.py new file mode 100755 index 00000000..75492fa5 --- /dev/null +++ b/product_configurator_refactor/__init__.py @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2012 - TODAY, Ursa Information Systems +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import ( + models, +) diff --git a/product_configurator_refactor/__manifest__.py b/product_configurator_refactor/__manifest__.py new file mode 100755 index 00000000..19147a66 --- /dev/null +++ b/product_configurator_refactor/__manifest__.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2012 - TODAY, Ursa Information Systems +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Product Configurator Refactor", + "summary": "To refactor product configurator", + "version": "10.0.1.0.0", + "license": "AGPL-3", + "author": "Ursa Information Systems", + "category": "Sales", + "maintainer": "Ursa Information Systems", + "website": "http://www.ursainfosystems.com", + "depends": [ + "product_configurator_default_val" + ], + "qweb": [ + ], + "data": [ + "security/ir.model.access.csv", + "views/product_attribute_value_line_view.xml", + "views/product_attribute_views.xml", + "views/product_view.xml", + ], + "application": False, +} diff --git a/product_configurator_refactor/models/__init__.py b/product_configurator_refactor/models/__init__.py new file mode 100755 index 00000000..c15351bb --- /dev/null +++ b/product_configurator_refactor/models/__init__.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2012 - TODAY, Ursa Information Systems +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import ( + product_attribute_value_line, + product_attribute, +) diff --git a/product_configurator_refactor/models/product_attribute.py b/product_configurator_refactor/models/product_attribute.py new file mode 100644 index 00000000..126bf59e --- /dev/null +++ b/product_configurator_refactor/models/product_attribute.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2012 - TODAY, Ursa Information Systems +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import api, fields, models, _ +from odoo.exceptions import ValidationError + + +class ProductAttributeLine(models.Model): + _inherit = 'product.attribute.line' + + @api.multi + def _get_attribute_values(self): + for line in self: + attribute_value_ids = line.value_idss.mapped('attrib_value_id') + if attribute_value_ids: + line.value_ids = [(6, 0, attribute_value_ids.ids)] + + value_idss = fields.One2many('product.attribute.value.line', + 'attribute_line_id', 'Values', copy=True) + value_ids = fields.Many2many(compute='_get_attribute_values', + comodel_name='product.attribute.value', + string='Attribute Values') + default_val = fields.Many2one('product.attribute.value', + compute='_is_default_value', + string="Default Value", store=True) + + @api.depends('value_idss.is_default') + def _is_default_value(self): + default_lines = [default for default in + self.value_idss.mapped('is_default') if default] + if default_lines: + if len(default_lines) == 1: + for value in self.value_idss: + if value.is_default: + self.default_val = value.attrib_value_id + else: + raise ValidationError(_( + "Please select one, first selected option will be valid!")) + else: + self.default_val = False + + @api.multi + @api.constrains('value_ids', 'default_val') + def _check_default_values(self): + return True diff --git a/product_configurator_refactor/models/product_attribute_value_line.py b/product_configurator_refactor/models/product_attribute_value_line.py new file mode 100644 index 00000000..8eac9fae --- /dev/null +++ b/product_configurator_refactor/models/product_attribute_value_line.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2012 - TODAY, Ursa Information Systems +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import api, fields, models, _ +from odoo.exceptions import ValidationError + + +class ProductAttributeValueLine(models.Model): + _name = 'product.attribute.value.line' + + related_attribute_id = fields.Many2one( + related='attribute_line_id.attribute_id', string='Product Attribute') + attribute_line_id = fields.Many2one('product.attribute.line', + 'Product Attribute') + attrib_value_id = fields.Many2one('product.attribute.value', + 'Attribute Value') + is_default = fields.Boolean("Is Default") diff --git a/product_configurator_refactor/security/ir.model.access.csv b/product_configurator_refactor/security/ir.model.access.csv new file mode 100644 index 00000000..2bf3676f --- /dev/null +++ b/product_configurator_refactor/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +product_configurator_refactor,Attribute Value Line,model_product_attribute_value_line,product_configurator.group_product_configurator,1,1,1,1 diff --git a/product_configurator_refactor/static/description/icon.png b/product_configurator_refactor/static/description/icon.png new file mode 100644 index 00000000..601dab3d Binary files /dev/null and b/product_configurator_refactor/static/description/icon.png differ diff --git a/product_configurator_refactor/views/product_attribute_value_line_view.xml b/product_configurator_refactor/views/product_attribute_value_line_view.xml new file mode 100644 index 00000000..1d764c74 --- /dev/null +++ b/product_configurator_refactor/views/product_attribute_value_line_view.xml @@ -0,0 +1,41 @@ + + + + + + product.attribute.value.line.form + product.attribute.value.line + +
+ + + + + + + + + + + + +
+
+
+ + + product.attribute.value.line.tree + product.attribute.value.line + +
+ + + + + +
+
+
+ +
diff --git a/product_configurator_refactor/views/product_attribute_views.xml b/product_configurator_refactor/views/product_attribute_views.xml new file mode 100644 index 00000000..16062308 --- /dev/null +++ b/product_configurator_refactor/views/product_attribute_views.xml @@ -0,0 +1,17 @@ + + + + + product.attribute.line.form + product.attribute.line + + primary + + + + + + + + + diff --git a/product_configurator_refactor/views/product_view.xml b/product_configurator_refactor/views/product_view.xml new file mode 100644 index 00000000..6e34da9a --- /dev/null +++ b/product_configurator_refactor/views/product_view.xml @@ -0,0 +1,73 @@ + + + + + + product.configurator.product.template.form.refactor + + product.template + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + +
+

+ Warning: adding or deleting attributes + will delete and recreate existing variants and lead + to the loss of their possible customizations. +

+
+
+
+
+ +