diff --git a/new_producttype/__init__.py b/new_producttype/__init__.py new file mode 100644 index 00000000000..9b4296142f4 --- /dev/null +++ b/new_producttype/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import wizard diff --git a/new_producttype/__manifest__.py b/new_producttype/__manifest__.py new file mode 100644 index 00000000000..c911da1919c --- /dev/null +++ b/new_producttype/__manifest__.py @@ -0,0 +1,17 @@ +{ + 'name': "New Product Type", + 'version': '0.1', + 'depends': ['sale'], + 'sequence': 1, + 'application': True, + 'installable': True, + 'data': [ + "security/ir.model.access.csv", + "report/sub_product_report.xml", + "wizard/sub_product_kit_wizard_view.xml", + "views/product_views.xml", + "views/sale_order_view.xml", + "views/sub_product_customer_preview.xml", + ], + 'license': 'AGPL-3' +} diff --git a/new_producttype/models/__init__.py b/new_producttype/models/__init__.py new file mode 100644 index 00000000000..8f2f8c0cbc1 --- /dev/null +++ b/new_producttype/models/__init__.py @@ -0,0 +1,3 @@ +from . import product_template +from . import sale_order_line +from . import sale_order diff --git a/new_producttype/models/product_template.py b/new_producttype/models/product_template.py new file mode 100644 index 00000000000..f1ec80566f9 --- /dev/null +++ b/new_producttype/models/product_template.py @@ -0,0 +1,25 @@ +from odoo import fields, models, api +from odoo.exceptions import ValidationError + + +class ProductTemplate(models.Model): + _inherit = 'product.template' + + is_kit = fields.Boolean(default=False, string='Is kit') + sub_products_ids = fields.Many2many('product.product', string='Sub products') + + @api.constrains("sub_products_ids") + def check_sub_product_not_itself(self): + for record in self: + if record.id in record.sub_products_ids.mapped("product_tmpl_id.id"): + raise ValidationError( + "A product cannot be added as its own sub-product" + ) + + @api.constrains("sub_products_ids", "is_kit") + def check_sub_product(self): + for record in self: + if record.is_kit and not record.sub_products_ids: + raise ValidationError( + "A kit product must have at least one sub-product" + ) diff --git a/new_producttype/models/sale_order.py b/new_producttype/models/sale_order.py new file mode 100644 index 00000000000..64b6caff4ce --- /dev/null +++ b/new_producttype/models/sale_order.py @@ -0,0 +1,7 @@ +from odoo import models, fields + + +class SaleOrder(models.Model): + _inherit = 'sale.order' + + print_report = fields.Boolean(string="Print in Report") diff --git a/new_producttype/models/sale_order_line.py b/new_producttype/models/sale_order_line.py new file mode 100644 index 00000000000..d1da7861180 --- /dev/null +++ b/new_producttype/models/sale_order_line.py @@ -0,0 +1,23 @@ +from odoo import fields, models + + +class SaleOrderLine(models.Model): + _inherit = 'sale.order.line' + + is_kit = fields.Boolean(string='Is kit', related='product_id.is_kit') + main_product_line_id = fields.Many2one('sale.order.line', ondelete='cascade') + sub_products_ids = fields.Many2many( + "product.product", + related="product_template_id.sub_products_ids", + string="Sub Products", + ) + last_price = fields.Float() + + def action_open_kit_wizard(self): + return { + 'type': 'ir.actions.act_window', + 'name': 'sub.product.kit.wizard.view', + 'res_model': 'sub.product.kit.wizard', + 'view_mode': 'form', + 'target': 'new', + } diff --git a/new_producttype/report/sub_product_report.xml b/new_producttype/report/sub_product_report.xml new file mode 100644 index 00000000000..3e705c34cfc --- /dev/null +++ b/new_producttype/report/sub_product_report.xml @@ -0,0 +1,8 @@ + + + + diff --git a/new_producttype/security/ir.model.access.csv b/new_producttype/security/ir.model.access.csv new file mode 100644 index 00000000000..2ec380ca018 --- /dev/null +++ b/new_producttype/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_sub_product_kit_wizard,access_sub_product_kit_wizard,model_sub_product_kit_wizard,base.group_user,1,1,1,1 +access_sub_product_line_kit_wizard,access_sub_product_line_kit_wizard,model_sub_product_line_kit_wizard,base.group_user,1,1,1,1 diff --git a/new_producttype/views/product_views.xml b/new_producttype/views/product_views.xml new file mode 100644 index 00000000000..2924bde217e --- /dev/null +++ b/new_producttype/views/product_views.xml @@ -0,0 +1,14 @@ + + + + product.template.form.view.inherit + product.template + + + + + + + + + diff --git a/new_producttype/views/sale_order_view.xml b/new_producttype/views/sale_order_view.xml new file mode 100644 index 00000000000..b01a32dd595 --- /dev/null +++ b/new_producttype/views/sale_order_view.xml @@ -0,0 +1,35 @@ + + + + view.order.form.inherit.sub.product + sale.order + + + +