-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] warranty_configuration: created transient model for wizard
Updated module created transient models required to add order line as per selected product warranty. facing issues in it. updated wizard views to display only product which has warranty and select particular warranty product to add in the orderlines of sales order.
- Loading branch information
Showing
12 changed files
with
143 additions
and
48 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 +1,2 @@ | ||
from . import models | ||
from . import wizards |
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,19 +1,7 @@ | ||
from odoo import models, api, fields | ||
from datetime import date | ||
from dateutil.relativedelta import relativedelta | ||
|
||
|
||
class SaleOrder(models.Model): | ||
_inherit = "sale.order" | ||
|
||
def action_open_warranty_wizard(self): | ||
print("-" * 100) | ||
# Properly define the return dictionary for the wizard action | ||
return { | ||
'type': 'ir.actions.act_window', | ||
'name': 'Add Warranty', | ||
'res_model': 'warranty.configuration', # Your wizard model | ||
'view_mode': 'form', | ||
'view_id': self.env.ref('warranty_configuration.view_add_warranty_wizard').id, # Adjust the module/view XML ID | ||
'target': 'new', | ||
'context': { | ||
'default_product_ids': self.order_line.ids, # Adjust based on the wizard's logic | ||
}, | ||
} |
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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | ||
warranty_configuration.access_warranty_configuration,access_warranty_configuration,warranty_configuration.model_warranty_configuration,base.group_user,1,1,1,1 | ||
warranty_configuration.access_add_warranty_wizard,access_add_warranty_wizard,warranty_configuration.model_add_warranty_wizard,base.group_user,1,1,1,1 | ||
warranty_configuration.access_add_warranty_line_wizard,access_add_warranty_line_wizard,warranty_configuration.model_add_warranty_line_wizard,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
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 add_warranty_wizard | ||
from . import add_warranty_line_wizard |
37 changes: 37 additions & 0 deletions
37
warranty_configuration/wizards/add_warranty_line_wizard.py
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,37 @@ | ||
from odoo import models, fields, api | ||
from datetime import date | ||
from dateutil.relativedelta import relativedelta | ||
|
||
|
||
class AddWarrantyLineWizard(models.TransientModel): | ||
_name = "add.warranty.line.wizard" | ||
_description = "Temporary line model for warranty in wizard" | ||
|
||
wizard_id = fields.Many2one( | ||
"add.warranty.wizard", | ||
string="Wizard Reference", | ||
readonly=True, | ||
required=True, | ||
ondelete='cascade', | ||
) | ||
|
||
product_id = fields.Many2one( | ||
"product.product", | ||
string="Product", | ||
readonly=True, | ||
ondelete='cascade', | ||
) | ||
warranty_config_id = fields.Many2one("warranty.configuration", string="Year") | ||
end_date = fields.Date(string="End Date", compute="_compute_end_date", store=True) | ||
|
||
@api.depends("warranty_config_id") | ||
def _compute_end_date(self): | ||
today = date.today() | ||
for record in self: | ||
if record.warranty_config_id and record.warranty_config_id.year: | ||
record.end_date = today + relativedelta( | ||
years=int(record.warranty_config_id.year) | ||
) | ||
else: | ||
record.product_id = record.product_id | ||
record.end_date = False |
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,59 @@ | ||
from odoo import models, fields, api, Command | ||
|
||
|
||
class AddWarrantyWizard(models.TransientModel): | ||
_name = "add.warranty.wizard" | ||
_description = "Wizard to Add Warranty" | ||
|
||
order_id = fields.Many2one("sale.order", string="Sale Order") | ||
product_ids = fields.Many2many("product.product") | ||
warranty_lines_ids = fields.One2many( | ||
comodel_name="add.warranty.line.wizard", | ||
inverse_name="wizard_id", | ||
store=True, | ||
string="Warranty Lines", | ||
) | ||
|
||
def action_add_warranty(self): | ||
print("-*- " * 100) | ||
|
||
new_order_line_list = [] | ||
# Iterate through the warranty lines in the wizard | ||
for record in self: | ||
print(record.order_id) | ||
warranty_product_ids = record.warranty_lines_ids.mapped("product_id.id") | ||
print("Warranty product IDs:", warranty_product_ids) | ||
|
||
# # Iterate over order lines to find matching products | ||
# for ol in record.order_id.order_line: | ||
# new_order_line_list.append(ol) | ||
# print( | ||
# f"Checking Order Line Product: {ol.product_id.id} in Warranty Lines" | ||
# ) | ||
|
||
# if ol.product_id.id in warranty_product_ids: | ||
# print(f"Match found: {ol}") | ||
|
||
print(new_order_line_list) | ||
print("hello from warranty !") | ||
print("-*- " * 100) | ||
|
||
return new_order_line_list | ||
|
||
@api.model | ||
def default_get(self, fields): | ||
res = super(AddWarrantyWizard, self).default_get(fields) | ||
order_id = self.env.context.get("active_id") | ||
sale_order = self.env["sale.order"].browse(order_id) | ||
|
||
warranty_products = sale_order.order_line.mapped("product_id").filtered( | ||
lambda p: p.warranty | ||
) | ||
|
||
warranty_line_vals = [] | ||
for product in warranty_products: | ||
warranty_line_vals.append(Command.create({"product_id": product.id})) | ||
print(warranty_products) | ||
res["product_ids"] = [Command.set(warranty_products)] | ||
|
||
return res |
32 changes: 32 additions & 0 deletions
32
warranty_configuration/wizards/add_warranty_wizard_view.xml
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,32 @@ | ||
<odoo> | ||
<record id="view_add_warranty_wizard" model="ir.ui.view"> | ||
<field name="name">add.warranty.wizard.form</field> | ||
<field name="model">add.warranty.wizard</field> | ||
<field name="arch" type="xml"> | ||
<form string="Add Warranty" editable="false"> | ||
<sheet> | ||
<field name="warranty_lines_ids"> | ||
<list create="false" no_open="1" editable="top" > | ||
<field name="product_id" readonly="1" /> | ||
<field name="warranty_config_id" /> | ||
<field name="end_date" readonly="1" /> | ||
</list> | ||
</field> | ||
</sheet> | ||
<footer> | ||
<button string="Add" name="action_add_warranty" type="object" | ||
class="btn-primary" /> | ||
<button string="Cancel" class="btn-secondary" special="cancel" /> | ||
</footer> | ||
</form> | ||
</field> | ||
</record> | ||
|
||
<record id="action_open_warranty_wizard" model="ir.actions.act_window"> | ||
<field name="name">Add Warranty</field> | ||
<field name="res_model">add.warranty.wizard</field> | ||
<field name="view_mode">form</field> | ||
<field name="view_id" ref="view_add_warranty_wizard" /> | ||
<field name="target">new</field> | ||
</record> | ||
</odoo> |
This file was deleted.
Oops, something went wrong.