-
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.
[IMP] warranty: implemented the on delete warranty with product
- Implement the on delete on sale order line to delete the product then delete the warranty product also.
- Loading branch information
Showing
13 changed files
with
69 additions
and
112 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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
from datetime import timedelta | ||
import logging | ||
from odoo import api, Command, models, fields | ||
|
||
|
||
|
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
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 |
---|---|---|
|
@@ -78,5 +78,5 @@ def add_installment(self): | |
"product_uom": self.env.ref("uom.product_uom_unit").id, | ||
"tax_id": None, | ||
})] | ||
|
||
return |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
from . import models | ||
from . import wizard | ||
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from . import warranty_config | ||
from . import product_template | ||
from . import sale_order | ||
from . import sale_order_line | ||
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
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 |
---|---|---|
@@ -1,29 +1,7 @@ | ||
from odoo import api, fields, models | ||
from odoo import fields, models | ||
|
||
|
||
class SaleOrderLine(models.Model): | ||
_inherit = "sale.order.line" | ||
|
||
warranty_product_id = fields.Integer("Attached Product Id") | ||
|
||
# @api.ondelete(at_uninstall=False) | ||
# def _delete_recode_with_warranty(self): | ||
# print("Executed the delition of warranty along with product.") | ||
# product_id = None | ||
|
||
# for record in self: | ||
# product_id = record.id | ||
# warranty = self.env['sale.order.line'].search([("warranty_product_id", "=", product_id)]) | ||
# warranty.unlink() | ||
# print(warranty.id) | ||
# print("Executed the delition of warranty along with product.", product_id) | ||
|
||
def unlink(self): | ||
for line in self: | ||
# Check if any other order lines have this line as their warranty product | ||
warranty_lines = self.search([('warranty_product_id', '=', line.id)]) | ||
if warranty_lines: | ||
# If warranty lines exist, delete them | ||
warranty_lines.unlink() | ||
|
||
# Call super to delete the original order lines (including the product being removed) | ||
return super(SaleOrderLine, self).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 |
---|---|---|
@@ -1,17 +1,18 @@ | ||
<odoo> | ||
|
||
<record id="warranty_product_template_form_view" model="ir.ui.view"> | ||
<field name="name">warranty.product.template.product.form</field> | ||
<field name="model">product.template</field> | ||
<field name="inherit_id" ref="product.product_template_form_view"/> | ||
<field name="arch" type="xml"> | ||
|
||
<xpath expr="//page[@name='sales']" position="inside"> | ||
<group string="Warranty" name="warranty"> | ||
<field name="warranty_available"/> | ||
</group> | ||
</xpath> | ||
|
||
</field> | ||
</record> | ||
|
||
|
||
|
||
</odoo> | ||
</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
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
from . import add_waranty_wizard | ||
from . import warranty_add_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
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
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,18 @@ | ||
from dateutil.relativedelta import relativedelta | ||
from odoo import api, fields, models | ||
|
||
|
||
class WarrantyAddLine(models.TransientModel): | ||
_name = "warranty.add.line" | ||
|
||
name = fields.Char(string="Product") | ||
product_id = fields.Many2one("sale.order.line") | ||
warranty_id = fields.Many2one("warranty.add") | ||
year = fields.Many2one("warranty.config") | ||
end_date = fields.Date(compute="_compute_end_date", readonly=True) | ||
|
||
@api.depends('year') | ||
def _compute_end_date(self): | ||
for record in self: | ||
if record.year is not None: | ||
record.end_date = fields.Date.today() + relativedelta(years=record.year.period) |