From e9126d95060c063fc70990b38d083a9e1adb6b5f Mon Sep 17 00:00:00 2001 From: kame-odoo Date: Sat, 26 Apr 2025 22:05:18 +0530 Subject: [PATCH 1/3] [ADD] product_warranty: add warranty management on sale orders Added a boolean field is_warranty_available on products to indicate if a warranty is available. In the quotation, users can add warranties to order lines using a new Add Warranty wizard. The wizard allows selecting available warranty configurations and automatically creates linked warranty order lines. --- product_warranty/__init__.py | 2 + product_warranty/__manifest__.py | 18 +++++ product_warranty/models/__init__.py | 4 + product_warranty/models/product_template.py | 6 ++ product_warranty/models/sale_order.py | 17 ++++ product_warranty/models/sale_order_line.py | 25 ++++++ product_warranty/models/warranty_config.py | 10 +++ product_warranty/security/ir.model.access.csv | 4 + .../views/product_template_views.xml | 13 +++ product_warranty/views/sale_order_views.xml | 16 ++++ .../views/warranty_config_menu.xml | 7 ++ .../views/warranty_config_views.xml | 21 +++++ product_warranty/wizard/__init__.py | 1 + .../wizard/add_warranty_wizard_views.xml | 30 +++++++ product_warranty/wizard/warranty_wizard.py | 79 +++++++++++++++++++ 15 files changed, 253 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/sale_order_line.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/sale_order_views.xml create mode 100644 product_warranty/views/warranty_config_menu.xml create mode 100644 product_warranty/views/warranty_config_views.xml create mode 100644 product_warranty/wizard/__init__.py create mode 100644 product_warranty/wizard/add_warranty_wizard_views.xml create mode 100644 product_warranty/wizard/warranty_wizard.py diff --git a/product_warranty/__init__.py b/product_warranty/__init__.py new file mode 100644 index 00000000000..9b4296142f4 --- /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 00000000000..3bbfb06c06c --- /dev/null +++ b/product_warranty/__manifest__.py @@ -0,0 +1,18 @@ +{ + 'name': 'Product Warranty', + 'version': '1.0', + 'depends': ['sale_management'], + 'description': """ + This module adds warranty availabe feature for products. + """, + 'data': [ + 'security/ir.model.access.csv', + 'wizard/add_warranty_wizard_views.xml', + 'views/product_template_views.xml', + 'views/warranty_config_views.xml', + 'views/warranty_config_menu.xml', + 'views/sale_order_views.xml', + ], + 'installable': True, + 'license': 'LGPL-3' +} diff --git a/product_warranty/models/__init__.py b/product_warranty/models/__init__.py new file mode 100644 index 00000000000..d1ab36003fb --- /dev/null +++ b/product_warranty/models/__init__.py @@ -0,0 +1,4 @@ +from . import product_template +from . import warranty_config +from . import sale_order +from . import sale_order_line diff --git a/product_warranty/models/product_template.py b/product_warranty/models/product_template.py new file mode 100644 index 00000000000..0c12cab3ae3 --- /dev/null +++ b/product_warranty/models/product_template.py @@ -0,0 +1,6 @@ +from odoo import models, fields + +class ProductTemplate(models.Model): + _inherit = 'product.template' + + is_warranty_available = fields.Boolean(string="Is Warranty Available") diff --git a/product_warranty/models/sale_order.py b/product_warranty/models/sale_order.py new file mode 100644 index 00000000000..5906c107a29 --- /dev/null +++ b/product_warranty/models/sale_order.py @@ -0,0 +1,17 @@ +from odoo import api, fields, models + +class SaleOrder(models.Model): + _inherit = "sale.order" + + + def open_warranty_wizard(self): + + return { + 'type': 'ir.actions.act_window', + 'name': 'Add Warranty', + 'res_model': 'add.warranty.wizard', + 'view_mode': 'form', + 'target': 'new', + 'context': {'default_sale_order_id': self.id}, + } + diff --git a/product_warranty/models/sale_order_line.py b/product_warranty/models/sale_order_line.py new file mode 100644 index 00000000000..8f8e6273a9e --- /dev/null +++ b/product_warranty/models/sale_order_line.py @@ -0,0 +1,25 @@ +from odoo import api, fields, models + + +class SaleOrderLine(models.Model): + _inherit = "sale.order.line" + + has_warranty = fields.Boolean(string="Has Warranty") + order_line_linked_to_warranty = fields.Many2one(comodel_name="sale.order.line", copy=False , string="Warranty Product", ondelete="cascade") + is_warranty = fields.Boolean('Is Warranty') + + @api.model_create_multi + def create(self, vals_list): + clean_vals_list = [] + for vals in vals_list: + if vals.get('is_warranty') and not vals.get('order_line_linked_to_warranty'): + continue + clean_vals_list.append(vals) + return super().create(clean_vals_list) + + @api.ondelete(at_uninstall=False) + def _unlink_except_confirmed(self): + super()._unlink_except_confirmed() + for line in self: + if line.is_warranty: + line.order_line_linked_to_warranty.write({'has_warranty': False}) diff --git a/product_warranty/models/warranty_config.py b/product_warranty/models/warranty_config.py new file mode 100644 index 00000000000..03d7ebd06b3 --- /dev/null +++ b/product_warranty/models/warranty_config.py @@ -0,0 +1,10 @@ +from odoo import models, fields + +class WarrantyConfig(models.Model): + _name = 'warranty.config' + _description = 'Warranty Configuration' + + name = fields.Char(string="Name") + product = fields.Many2one('product.product', string="Warranty Product") + period = fields.Float(string='Period (in years)', default=1) + percentage = fields.Float(string="Percentage (%)") diff --git a/product_warranty/security/ir.model.access.csv b/product_warranty/security/ir.model.access.csv new file mode 100644 index 00000000000..548ac20a7fb --- /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 +access_warranty_config,access.warranty.config,model_warranty_config,base.group_user,1,1,1,1 +access_add_warranty_wizard,access.add.warranty.wizard,model_add_warranty_wizard,base.group_user,1,1,1,1 +access_add_warranty_lines_wizard,access.add.warranty.lines.wizard,model_add_warranty_lines_wizard,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 00000000000..7d31b43d88b --- /dev/null +++ b/product_warranty/views/product_template_views.xml @@ -0,0 +1,13 @@ + + + + product.template.form.warranty.inherit + product.template + + + + + + + + diff --git a/product_warranty/views/sale_order_views.xml b/product_warranty/views/sale_order_views.xml new file mode 100644 index 00000000000..39bed4748cf --- /dev/null +++ b/product_warranty/views/sale_order_views.xml @@ -0,0 +1,16 @@ + + + + sale.order.list.view.inherit.add.warranty + sale.order + + + +