|
| 1 | +from odoo import models, fields, api, Command |
| 2 | + |
| 3 | + |
| 4 | +class AddWarrantyWizard(models.TransientModel): |
| 5 | + _name = "add.warranty.wizard" |
| 6 | + _description = "Wizard to Add Warranty" |
| 7 | + |
| 8 | + order_id = fields.Many2one("sale.order", string="Sale Order") |
| 9 | + product_ids = fields.Many2many("product.product") |
| 10 | + warranty_lines_ids = fields.One2many( |
| 11 | + comodel_name="add.warranty.line.wizard", |
| 12 | + inverse_name="wizard_id", |
| 13 | + store=True, |
| 14 | + string="Warranty Lines", |
| 15 | + ) |
| 16 | + |
| 17 | + def action_add_warranty(self): |
| 18 | + print("-*- " * 100) |
| 19 | + |
| 20 | + new_order_line_list = [] |
| 21 | + # Iterate through the warranty lines in the wizard |
| 22 | + for record in self: |
| 23 | + print(record.order_id) |
| 24 | + warranty_product_ids = record.warranty_lines_ids.mapped("product_id.id") |
| 25 | + print("Warranty product IDs:", warranty_product_ids) |
| 26 | + |
| 27 | + # # Iterate over order lines to find matching products |
| 28 | + # for ol in record.order_id.order_line: |
| 29 | + # new_order_line_list.append(ol) |
| 30 | + # print( |
| 31 | + # f"Checking Order Line Product: {ol.product_id.id} in Warranty Lines" |
| 32 | + # ) |
| 33 | + |
| 34 | + # if ol.product_id.id in warranty_product_ids: |
| 35 | + # print(f"Match found: {ol}") |
| 36 | + |
| 37 | + print(new_order_line_list) |
| 38 | + print("hello from warranty !") |
| 39 | + print("-*- " * 100) |
| 40 | + |
| 41 | + return new_order_line_list |
| 42 | + |
| 43 | + @api.model |
| 44 | + def default_get(self, fields): |
| 45 | + res = super(AddWarrantyWizard, self).default_get(fields) |
| 46 | + order_id = self.env.context.get("active_id") |
| 47 | + sale_order = self.env["sale.order"].browse(order_id) |
| 48 | + |
| 49 | + warranty_products = sale_order.order_line.mapped("product_id").filtered( |
| 50 | + lambda p: p.warranty |
| 51 | + ) |
| 52 | + |
| 53 | + warranty_line_vals = [] |
| 54 | + for product in warranty_products: |
| 55 | + warranty_line_vals.append(Command.create({"product_id": product.id})) |
| 56 | + print(warranty_products) |
| 57 | + res["product_ids"] = [Command.set(warranty_products)] |
| 58 | + |
| 59 | + return res |
0 commit comments