-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] warranty: implemented Warranty Functionality to Sales and Inven…
…tory 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.
- Loading branch information
Showing
14 changed files
with
234 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import models | ||
from . import wizard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<odoo> | ||
<record id="product_warranty1" model="product.warranty"> | ||
<field name="name">1 Year Warranty</field> | ||
<field name="product_id">2</field> | ||
<field name="percentage">10</field> | ||
<field name='year'>1</field> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from . import product_warranty | ||
from . import product_template | ||
from . import sale_order_line |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from odoo import fields, models | ||
|
||
|
||
class ProductTemplate(models.Model): | ||
_inherit = 'product.template' | ||
|
||
warranty_available = fields.Boolean(string="Is Warranty Available") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<odoo> | ||
<menuitem id="menu_warranty_configuration" name="Warranty Configuration" | ||
parent="sale.menu_sale_config" sequence="10" | ||
action="action_warranty_configuration"/> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<odoo> | ||
<!-- Warranty Configuration Form View --> | ||
<record id="view_product_warranty_form" model="ir.ui.view"> | ||
<field name="name">product.warranty.form</field> | ||
<field name="model">product.warranty</field> | ||
<field name="arch" type="xml"> | ||
<form string="Product Warranty"> | ||
<sheet> | ||
<group> | ||
<field name="name"/> | ||
<field name="product_id"/> | ||
<field name="percentage"/> | ||
<field name="year"/> | ||
</group> | ||
</sheet> | ||
</form> | ||
</field> | ||
</record> | ||
|
||
<!-- Warranty Configuration List View --> | ||
<record id="view_product_warranty_tree" model="ir.ui.view"> | ||
<field name="name">product.warranty.tree</field> | ||
<field name="model">product.warranty</field> | ||
<field name="arch" type="xml"> | ||
<tree string="Product Warranties" editable="bottom"> | ||
<field name="name"/> | ||
<field name="product_id"/> | ||
<field name="percentage"/> | ||
<field name="year"/> | ||
</tree> | ||
</field> | ||
</record> | ||
|
||
<!-- Product Template Form View Extension --> | ||
<record id="view_product_form_inherit_warranty" model="ir.ui.view"> | ||
<field name="name">product.form.inherit.warranty</field> | ||
<field name="model">product.template</field> | ||
<field name="inherit_id" ref="product.product_template_only_form_view"/> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//field[@name='product_template_image_ids']" position="after"> | ||
<group> | ||
<field name="warranty_available"/> | ||
</group> | ||
</xpath> | ||
</field> | ||
</record> | ||
|
||
<record id="action_warranty_configuration" model="ir.actions.act_window"> | ||
<field name="name">Warranty Configuration</field> | ||
<field name="res_model">product.warranty</field> | ||
<field name="view_mode">tree,form</field> | ||
</record> | ||
|
||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<odoo> | ||
<record id="view_order_form" model="ir.ui.view"> | ||
<field name="name">sale.order.form</field> | ||
<field name="model">sale.order</field> | ||
<field name="inherit_id" ref="sale.view_order_form"/> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//button[@name='action_open_discount_wizard']" position="before"> | ||
<button name="%(action_add_warranty)d" string="Add Warranty" type="action" class="oe_highlight"/> | ||
</xpath> | ||
</field> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import sale_order_warranty_wizard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from dateutil.relativedelta import relativedelta | ||
from odoo import api, fields, models | ||
|
||
|
||
class SaleOrderWarrantyWizard(models.TransientModel): | ||
_name = "sale.order.warranty.wizard" | ||
|
||
product_ids = fields.One2many('warranty.wizard.add.line', 'warranty_id') | ||
|
||
@api.model | ||
def default_get(self, fields): | ||
res = super().default_get(fields) | ||
active_id = self.env.context.get("active_id") | ||
sale_order = self.env["sale.order"].browse(active_id) | ||
|
||
warranty_lines = self.env['warranty.wizard.add.line'].create([ | ||
{ | ||
'product': product.product_template_id.id, | ||
} | ||
for product in sale_order.order_line | ||
if product.product_template_id.warranty_available | ||
]) | ||
|
||
res['product_ids'] = [(6, 0, warranty_lines.ids)] | ||
return res | ||
|
||
def add_warranty_wizard_action(self): | ||
active_id = self.env.context.get('active_id') | ||
sale_order = self.env['sale.order'].browse(active_id) | ||
for record in self.product_ids: | ||
sale_order_line = sale_order.order_line.filtered( | ||
lambda line: line.product_template_id == record.product) | ||
price = sale_order_line.price_subtotal * (record.year.percentage / 100) | ||
vals_to_create = { | ||
"name": "Exteded Warranty End Date: " + str(record.end_date), | ||
"order_id": sale_order.id, | ||
"price_unit": price, | ||
"product_id": record.year.product_id.id, | ||
"tax_id": None, | ||
"warranty_product_id": sale_order_line.product_template_id.id | ||
} | ||
# self.env["sale.order.line"].create(vals_to_create) | ||
sale_order.order_line.create(vals_to_create) | ||
|
||
|
||
class WarrantyWizardAddLine(models.TransientModel): | ||
_name = "warranty.wizard.add.line" | ||
|
||
warranty_id = fields.Many2one("sale.order.warranty.wizard") | ||
product = fields.Many2one("product.template", string="Product") | ||
year = fields.Many2one("product.warranty") | ||
end_date = fields.Date(compute="_compute_end_date", store=True) | ||
|
||
@api.depends('year') | ||
def _compute_end_date(self): | ||
for record in self.year: | ||
if record.year: | ||
self.end_date = fields.date.today() + relativedelta(years=record.year) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<odoo> | ||
|
||
<record id='add_warranty_form' model='ir.ui.view'> | ||
<field name="name">Add Warranty</field> | ||
<field name="model">sale.order.warranty.wizard</field> | ||
<field name="arch" type="xml"> | ||
<form string="Add Warranty"> | ||
<field name="product_ids"> | ||
<tree string="Products" editable="bottom" create='0'> | ||
<field name="product"/> | ||
<field name="year"/> | ||
<field name="end_date"/> | ||
</tree> | ||
</field> | ||
<footer> | ||
<button name="add_warranty_wizard_action" class="btn btn-primary" string="Add" type="object"/> | ||
</footer> | ||
</form> | ||
</field> | ||
</record> | ||
|
||
<record id="action_add_warranty" model="ir.actions.act_window"> | ||
<field name="name">Add Warranty</field> | ||
<field name="res_model">sale.order.warranty.wizard</field> | ||
<field name="view_mode">form</field> | ||
<field name="view_id" ref="add_warranty_form" /> | ||
<field name="target">new</field> | ||
</record> | ||
|
||
</odoo> |