From f9ffd660cd7c6bba2bc1613872cd505dcc7c4106 Mon Sep 17 00:00:00 2001 From: nipl-odoo Date: Thu, 23 Jan 2025 18:39:58 +0530 Subject: [PATCH] [ADD] product_warranty: add product warranty module Add product warranty module which adds warranty product by clicking on 'Add Warranty' button in quotation on addition of related product in sales order line Also by deleting the product warranty will also get removed. Add warranty as sale order line so we can see it as any other product in sales order in print report. Firstly we need to configure warranty from warranty config.(Which is located in sales-> menu -> Configuration -> (Under product section) -> Warranty Config) By clicking on is warranty product on product template's sales section we can mark that product as warranty product. task - 4504888 --- product_warranty/__init__.py | 2 + product_warranty/__manifest__.py | 21 ++++++++ product_warranty/models/__init__.py | 3 ++ product_warranty/models/product_template.py | 7 +++ product_warranty/models/sale_order.py | 34 +++++++++++++ product_warranty/models/warranty_config.py | 17 +++++++ product_warranty/security/ir.model.access.csv | 4 ++ .../views/product_template_views.xml | 18 +++++++ .../views/product_warranty_config_menu.xml | 4 ++ .../views/product_warranty_config_views.xml | 28 ++++++++++ product_warranty/views/sale_order_views.xml | 15 ++++++ product_warranty/wizard/__init__.py | 2 + .../wizard/product_warranty_wizard.py | 51 +++++++++++++++++++ .../wizard/product_warranty_wizard_line.py | 34 +++++++++++++ .../wizard/product_warranty_wizard_view.xml | 27 ++++++++++ 15 files changed, 267 insertions(+) create mode 100644 product_warranty/__init__.py create mode 100644 product_warranty/__manifest__.py create mode 100644 product_warranty/models/__init__.py create mode 100644 product_warranty/models/product_template.py create mode 100644 product_warranty/models/sale_order.py create mode 100644 product_warranty/models/warranty_config.py create mode 100644 product_warranty/security/ir.model.access.csv create mode 100644 product_warranty/views/product_template_views.xml create mode 100644 product_warranty/views/product_warranty_config_menu.xml create mode 100644 product_warranty/views/product_warranty_config_views.xml create mode 100644 product_warranty/views/sale_order_views.xml create mode 100644 product_warranty/wizard/__init__.py create mode 100644 product_warranty/wizard/product_warranty_wizard.py create mode 100644 product_warranty/wizard/product_warranty_wizard_line.py create mode 100644 product_warranty/wizard/product_warranty_wizard_view.xml diff --git a/product_warranty/__init__.py b/product_warranty/__init__.py new file mode 100644 index 0000000000..9b4296142f --- /dev/null +++ b/product_warranty/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import wizard diff --git a/product_warranty/__manifest__.py b/product_warranty/__manifest__.py new file mode 100644 index 0000000000..9faf3b3595 --- /dev/null +++ b/product_warranty/__manifest__.py @@ -0,0 +1,21 @@ +{ + "name": "Product Warranty", + "version": "1.0", + "category": "Sales/Warranty", + "summary": "Add warranty information to products and display it on sale order lines.", + "description": """ +This module provides functionality to manage product warranties. +Users can define warranties for products and see warranty details in sale order lines. +""", + "license": "AGPL-3", + "depends": ["base", "sale_management"], + "data": [ + "security/ir.model.access.csv", + "views/product_template_views.xml", + "views/product_warranty_config_menu.xml", + "views/product_warranty_config_views.xml", + "views/sale_order_views.xml", + "wizard/product_warranty_wizard_view.xml", + ], + "auto_install": True, +} diff --git a/product_warranty/models/__init__.py b/product_warranty/models/__init__.py new file mode 100644 index 0000000000..4b53b297b9 --- /dev/null +++ b/product_warranty/models/__init__.py @@ -0,0 +1,3 @@ +from . import product_template +from . import sale_order +from . import warranty_config diff --git a/product_warranty/models/product_template.py b/product_warranty/models/product_template.py new file mode 100644 index 0000000000..caacda89a1 --- /dev/null +++ b/product_warranty/models/product_template.py @@ -0,0 +1,7 @@ +from odoo import fields, models + + +class ProductTemplate(models.Model): + _inherit = "product.template" + + is_warranty_product = fields.Boolean("Is Warranty Product") diff --git a/product_warranty/models/sale_order.py b/product_warranty/models/sale_order.py new file mode 100644 index 0000000000..7da7a37227 --- /dev/null +++ b/product_warranty/models/sale_order.py @@ -0,0 +1,34 @@ +from odoo import api, Command, models + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + def action_open_warranty_wizard(self): + return { + "name": "Add Warranty", + "type": "ir.actions.act_window", + "res_model": "product.warranty.wizard", + "view_mode": "form", + "target": "new", + } + + @api.onchange("order_line") + def _onchange_order_line(self): + super()._onchange_order_line() + deleted_product_template_ids = [] + for line in self.order_line: + # Find each products that is not in Sale Order currently + if ( + line.linked_line_id.id + and line.linked_line_id.id not in self.order_line.ids + ): + deleted_product_template_ids.append(line.linked_line_id.id) + + linked_line_ids_to_delete = self.order_line.search( + [("linked_line_id", "in", deleted_product_template_ids)] + ) + self.order_line = [ + Command.unlink(linked_line_id) + for linked_line_id in linked_line_ids_to_delete.ids + ] diff --git a/product_warranty/models/warranty_config.py b/product_warranty/models/warranty_config.py new file mode 100644 index 0000000000..c1107bcfd9 --- /dev/null +++ b/product_warranty/models/warranty_config.py @@ -0,0 +1,17 @@ +from odoo import fields, models + + +class ProductWarrantyConfig(models.Model): + _name = "product.warranty.config" + _description = "Product Warranty Configuration" + + name = fields.Char(string="Name", required=True) + product_template_id = fields.Many2one( + "product.template", string="Product", required=True + ) + percentage = fields.Float(string="Percentage", required=True) + years = fields.Integer(string="Years", required=True) + + _sql_constraints = [ + ("name_uniq", "unique (name)", "Two Waranties can not be of same name"), + ] diff --git a/product_warranty/security/ir.model.access.csv b/product_warranty/security/ir.model.access.csv new file mode 100644 index 0000000000..609f7846ad --- /dev/null +++ b/product_warranty/security/ir.model.access.csv @@ -0,0 +1,4 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +product_warranty.access_product_warranty_config,access_product_warranty_config,product_warranty.model_product_warranty_config,base.group_user,1,1,1,1 +product_warranty.access_prodcut_warranty_wizard,access_prodcut_warranty_wizard,product_warranty.model_product_warranty_wizard,base.group_user,1,1,1,1 +product_warranty.access_product_warranty_wizard_line,access_product_warranty_wizard_line,product_warranty.model_product_warranty_wizard_line,base.group_user,1,1,1,1 diff --git a/product_warranty/views/product_template_views.xml b/product_warranty/views/product_template_views.xml new file mode 100644 index 0000000000..ad45790d4e --- /dev/null +++ b/product_warranty/views/product_template_views.xml @@ -0,0 +1,18 @@ + + + + + product.template.view.form.inherit + product.template + + + + + + + + + + + + diff --git a/product_warranty/views/product_warranty_config_menu.xml b/product_warranty/views/product_warranty_config_menu.xml new file mode 100644 index 0000000000..886929bba0 --- /dev/null +++ b/product_warranty/views/product_warranty_config_menu.xml @@ -0,0 +1,4 @@ + + + + diff --git a/product_warranty/views/product_warranty_config_views.xml b/product_warranty/views/product_warranty_config_views.xml new file mode 100644 index 0000000000..07de3ae778 --- /dev/null +++ b/product_warranty/views/product_warranty_config_views.xml @@ -0,0 +1,28 @@ + + + + + Warranty Config + product.warranty.config + list + +

+ Define new warranty +

+
+
+ + + product.warranty.config.view.tree + product.warranty.config + + + + + + + + + + +
diff --git a/product_warranty/views/sale_order_views.xml b/product_warranty/views/sale_order_views.xml new file mode 100644 index 0000000000..ba672e2fc6 --- /dev/null +++ b/product_warranty/views/sale_order_views.xml @@ -0,0 +1,15 @@ + + + + + sale.order.view.form.inherit + sale.order + + + +