From 35ca56790eac0b9a996dc8760472de111edf734b Mon Sep 17 00:00:00 2001 From: pkgu-odoo Date: Wed, 25 Sep 2024 18:57:04 +0530 Subject: [PATCH] [ADD] warranty: implemented Warranty Functionality to Sales and Inventory After this commit: - Added warranty configuration model and settings. - Extended sale order and sale order line models to include warranty fields. - Implemented warranty wizard for adding warranties to sale orders. - Created views for managing warranty settings and applying warranties to products. - Added security rules to control access to warranty features. --- warranty/__init__.py | 2 + warranty/__manifest__.py | 21 +++++++ warranty/data/warranty_data.xml | 9 +++ warranty/models/__init__.py | 3 + warranty/models/product_template.py | 7 +++ warranty/models/product_warranty.py | 11 ++++ warranty/models/sale_order_line.py | 16 +++++ warranty/security/ir.model.access.csv | 4 ++ warranty/views/menu.xml | 5 ++ warranty/views/product_warranty_view.xml | 54 +++++++++++++++++ warranty/views/sale_oder_line_view.xml | 13 +++++ warranty/wizard/__init__.py | 1 + warranty/wizard/sale_order_warranty_wizard.py | 58 +++++++++++++++++++ .../sale_order_warranty_wizard_view.xml | 30 ++++++++++ 14 files changed, 234 insertions(+) create mode 100644 warranty/__init__.py create mode 100644 warranty/__manifest__.py create mode 100644 warranty/data/warranty_data.xml create mode 100644 warranty/models/__init__.py create mode 100644 warranty/models/product_template.py create mode 100644 warranty/models/product_warranty.py create mode 100644 warranty/models/sale_order_line.py create mode 100644 warranty/security/ir.model.access.csv create mode 100644 warranty/views/menu.xml create mode 100644 warranty/views/product_warranty_view.xml create mode 100644 warranty/views/sale_oder_line_view.xml create mode 100644 warranty/wizard/__init__.py create mode 100644 warranty/wizard/sale_order_warranty_wizard.py create mode 100644 warranty/wizard/sale_order_warranty_wizard_view.xml diff --git a/warranty/__init__.py b/warranty/__init__.py new file mode 100644 index 0000000000..9b4296142f --- /dev/null +++ b/warranty/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import wizard diff --git a/warranty/__manifest__.py b/warranty/__manifest__.py new file mode 100644 index 0000000000..f52a1df99c --- /dev/null +++ b/warranty/__manifest__.py @@ -0,0 +1,21 @@ +{ + 'name': 'Product Warranty Management', + 'version': '1.0', + 'category': 'Sales', + 'summary': 'Manage product warranties in sales', + 'description': """ + This module adds warranty configuration to products in the sales module. + """, + 'depends': ['stock', 'website_sale', 'sale_management'], + 'data': [ + 'security/ir.model.access.csv', + 'wizard/sale_order_warranty_wizard_view.xml', + 'views/sale_oder_line_view.xml', + 'views/product_warranty_view.xml', + 'views/menu.xml', + 'data/warranty_data.xml' + ], + 'installable': True, + 'application': False, + 'license': 'LGPL-3', +} diff --git a/warranty/data/warranty_data.xml b/warranty/data/warranty_data.xml new file mode 100644 index 0000000000..ced28eafff --- /dev/null +++ b/warranty/data/warranty_data.xml @@ -0,0 +1,9 @@ + + + + 1 Year Warranty + 2 + 10 + 1 + + diff --git a/warranty/models/__init__.py b/warranty/models/__init__.py new file mode 100644 index 0000000000..5e052e5446 --- /dev/null +++ b/warranty/models/__init__.py @@ -0,0 +1,3 @@ +from . import product_warranty +from . import product_template +from . import sale_order_line diff --git a/warranty/models/product_template.py b/warranty/models/product_template.py new file mode 100644 index 0000000000..c81e566ce3 --- /dev/null +++ b/warranty/models/product_template.py @@ -0,0 +1,7 @@ +from odoo import fields, models + + +class ProductTemplate(models.Model): + _inherit = 'product.template' + + warranty_available = fields.Boolean(string="Is Warranty Available") diff --git a/warranty/models/product_warranty.py b/warranty/models/product_warranty.py new file mode 100644 index 0000000000..c9ab32968a --- /dev/null +++ b/warranty/models/product_warranty.py @@ -0,0 +1,11 @@ +from odoo import models, fields + + +class ProductWarranty(models.Model): + _name = 'product.warranty' + _description = 'Product Warranty' + + name = fields.Char(string="Warranty Name", required=True) + product_id = fields.Many2one('product.product', string="Product") + percentage = fields.Float(string="Percentage") + year = fields.Integer(string="Year") diff --git a/warranty/models/sale_order_line.py b/warranty/models/sale_order_line.py new file mode 100644 index 0000000000..ea9b89869f --- /dev/null +++ b/warranty/models/sale_order_line.py @@ -0,0 +1,16 @@ +from odoo import fields, models + + +class SaleOrderLine(models.Model): + _inherit = 'sale.order.line' + + warranty_product_id = fields.Many2one('product.template', string='Warranty') + + def unlink(self): + removable_order_lines = self.env['sale.order.line'].search([ + ('order_id', '=', self.order_id.id), + ('warranty_product_id', '=', self.product_template_id.id) + ]) + if removable_order_lines: + removable_order_lines.unlink() + return super().unlink() diff --git a/warranty/security/ir.model.access.csv b/warranty/security/ir.model.access.csv new file mode 100644 index 0000000000..c5516424b8 --- /dev/null +++ b/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_product_warranty,access_product_warranty,model_product_warranty,base.group_user,1,1,1,1 +access_product_warranty_wizard,access_product_warranty_wizard,model_sale_order_warranty_wizard,base.group_user,1,1,1,1 +access_warranty_wizard_add_line,access_warranty_wizard_add_line,model_warranty_wizard_add_line,base.group_user,1,1,1,1 diff --git a/warranty/views/menu.xml b/warranty/views/menu.xml new file mode 100644 index 0000000000..0ac588b2b6 --- /dev/null +++ b/warranty/views/menu.xml @@ -0,0 +1,5 @@ + + + diff --git a/warranty/views/product_warranty_view.xml b/warranty/views/product_warranty_view.xml new file mode 100644 index 0000000000..da5254afb9 --- /dev/null +++ b/warranty/views/product_warranty_view.xml @@ -0,0 +1,54 @@ + + + + product.warranty.form + product.warranty + +
+ + + + + + + + +
+
+
+ + + + product.warranty.tree + product.warranty + + + + + + + + + + + + + product.form.inherit.warranty + product.template + + + + + + + + + + + + Warranty Configuration + product.warranty + tree,form + + +
diff --git a/warranty/views/sale_oder_line_view.xml b/warranty/views/sale_oder_line_view.xml new file mode 100644 index 0000000000..9874431188 --- /dev/null +++ b/warranty/views/sale_oder_line_view.xml @@ -0,0 +1,13 @@ + + + + sale.order.form + sale.order + + + +