diff --git a/product_kit/__init__.py b/product_kit/__init__.py new file mode 100644 index 00000000000..9b4296142f4 --- /dev/null +++ b/product_kit/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import wizard diff --git a/product_kit/__manifest__.py b/product_kit/__manifest__.py new file mode 100644 index 00000000000..1717618781e --- /dev/null +++ b/product_kit/__manifest__.py @@ -0,0 +1,15 @@ +{ + 'name': 'Product Kit', + 'Category': 'Sales/Product Kit', + 'license': 'LGPL-3', + 'installable': True, + 'depends': ['sale_management', 'stock'], + 'data': [ + 'security/ir.model.access.csv', + 'wizard/wizard_product_kit_views.xml', + 'views/product_template_views.xml', + 'views/sale_order_views.xml', + 'views/sale_portal_template.xml', + 'views/report_invoice.xml', + ] +} diff --git a/product_kit/models/__init__.py b/product_kit/models/__init__.py new file mode 100644 index 00000000000..8f2f8c0cbc1 --- /dev/null +++ b/product_kit/models/__init__.py @@ -0,0 +1,3 @@ +from . import product_template +from . import sale_order_line +from . import sale_order diff --git a/product_kit/models/product_template.py b/product_kit/models/product_template.py new file mode 100644 index 00000000000..128e4038a60 --- /dev/null +++ b/product_kit/models/product_template.py @@ -0,0 +1,8 @@ +from odoo import fields, models + + +class ProductTemplate(models.Model): + _inherit = 'product.template' + + kit = fields.Boolean(string="has kit ?", default=False, help="To enable new product type") + subproduct = fields.Many2many(comodel_name="product.product", string="Sub Product", help="Select subproduct if kit is enabled") diff --git a/product_kit/models/sale_order.py b/product_kit/models/sale_order.py new file mode 100644 index 00000000000..17045c59066 --- /dev/null +++ b/product_kit/models/sale_order.py @@ -0,0 +1,7 @@ +from odoo import fields, models + + +class SaleOrder(models.Model): + _inherit = 'sale.order' + + print_in_report = fields.Boolean(string="Print in report ?", default=True) diff --git a/product_kit/models/sale_order_line.py b/product_kit/models/sale_order_line.py new file mode 100644 index 00000000000..e33e12da083 --- /dev/null +++ b/product_kit/models/sale_order_line.py @@ -0,0 +1,55 @@ +from odoo import Command, fields, models + + +class SaleOrderLine(models.Model): + _inherit = 'sale.order.line' + + has_kit = fields.Boolean(related="product_template_id.kit", store=True, help="Check product has kit enable or not") + is_kit = fields.Boolean(string="Is kit", default=False, help="Distinguish main product and subproduct. If true it is sub product") + + def open_kit_wizard(self): + for record in self: + sale_order_line_id = record.id + sale_order_id = record.order_id.id + + existing_lines = [] + + # Fetching existing order lines from sale order + existing_lines = self.env['sale.order.line'].search([ + ('linked_line_id', '=', sale_order_line_id), + ('order_id', '=', sale_order_id) + ]) + + # Creating dictionary with product id as key and quantity as value from existing order line + existing_dict = { + line.product_id.id: line.product_uom_qty for line in existing_lines + } + product_commands = [] + + # Looping through all the subproduct of kit enabled product + for product in record.product_template_id.subproduct: + qty = existing_dict.get(product.id, 1) # Fetching quantity of product if not found return 1 + # Creating command to create new linked record + product_commands.append( + Command.create({ + "product_id": product.id, + "quantity": qty + }) + ) + + # Populating wizard models + wizard = self.env['wizard.product.kit'].create({ + "product_ids": product_commands + }) + + return { + 'type': 'ir.actions.act_window', + 'name': 'Product Kit', + 'res_model': 'wizard.product.kit', + 'view_mode': 'form', + 'target': 'new', + "res_id": wizard.id, + "context": { + "default_sale_order_id": record.order_id.id, + } + } diff --git a/product_kit/security/ir.model.access.csv b/product_kit/security/ir.model.access.csv new file mode 100644 index 00000000000..9fc358ea369 --- /dev/null +++ b/product_kit/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_wizard_product_kit,access_wizard_product_kit,model_wizard_product_kit,base.group_user,1,1,1,0 +access_wizard_product_kit_add,access_wizard_product_kit_add,model_wizard_product_kit_add,base.group_user,1,1,1,0 diff --git a/product_kit/views/product_template_views.xml b/product_kit/views/product_template_views.xml new file mode 100644 index 00000000000..f4118f4b440 --- /dev/null +++ b/product_kit/views/product_template_views.xml @@ -0,0 +1,16 @@ + + + + + product.template.form.inherit.product.kit + product.template + + + + + + + + + + diff --git a/product_kit/views/report_invoice.xml b/product_kit/views/report_invoice.xml new file mode 100644 index 00000000000..f4ba17ca9b9 --- /dev/null +++ b/product_kit/views/report_invoice.xml @@ -0,0 +1,13 @@ + + + + + + diff --git a/product_kit/views/sale_order_views.xml b/product_kit/views/sale_order_views.xml new file mode 100644 index 00000000000..33fd96a2d9d --- /dev/null +++ b/product_kit/views/sale_order_views.xml @@ -0,0 +1,41 @@ + + + + view.sale.form.order.line.inherit + sale.order + + + + + + + +