from odoo import api, fields, models class WarrantyClaim(models.Model): _name = "warranty.claim" _description = "Warranty Claim" _inherit = ["mail.thread", "mail.activity.mixin"] _order = "create_date desc" name = fields.Char("Claim Reference", required=True, copy=False, default="New", tracking=True) # Link to the customer and various parties partner_id = fields.Many2one("res.partner", string="Customer", tracking=True) manufacturer_id = fields.Many2one("warranty.manufacturer", string="Manufacturer") true_vendor_id = fields.Many2one( "res.partner", string="True Vendor", domain="[('supplier_rank', '>', 0)]", tracking=True, ) extra_recipient_ids = fields.Many2many( "res.partner", string="Additional Email Recipients", help="Separate recipients you want CC'd on the warranty email.", ) # Link to sales and invoices sale_order_id = fields.Many2one("sale.order", string="Sales Order", tracking=True) original_sale_order_id = fields.Many2one("sale.order", string="Original Sales Order") # Customer invoices to attach invoice_customer_ids = fields.Many2many( "account.move", "warranty_claim_customer_invoice_rel", "claim_id", "move_id", string="Customer Invoices", domain="[('move_type', 'in', ('out_invoice', 'out_refund'))]", ) # Vendor invoices to attach invoice_vendor_ids = fields.Many2many( "account.move", "warranty_claim_vendor_invoice_rel", "claim_id", "move_id", string="Vendor Invoices", domain="[('move_type', 'in', ('in_invoice', 'in_refund'))]", ) # Technical / product fields product_id = fields.Many2one("product.product", string="Product") model = fields.Char("Model") serial_number = fields.Char("Serial Number") failure = fields.Text("Failure Description") warranty_type = fields.Selection( [ ("90_day", "90 Day Warranty"), ("cabinet", "Cabinet Warranty"), ("other", "Other"), ], string="Warranty Type", ) claim_date = fields.Date("Claim Date", default=fields.Date.context_today) state = fields.Selection( [ ("draft", "Draft"), ("sent", "Sent to Vendor"), ("in_progress", "In Progress"), ("approved", "Approved"), ("rejected", "Rejected"), ("done", "Done"), ], string="Status", default="draft", tracking=True, ) @api.model def create(self, vals): if vals.get("name", "New") == "New": seq = self.env.ref( "odoo_warranty_claims.seq_warranty_claim", raise_if_not_found=False ) if seq: vals["name"] = seq.next_by_id() return super().create(vals) def action_send_to_vendor(self): """Uses an email template and moves to 'sent' state.""" self.ensure_one() template = self.env.ref("odoo_warranty_claims.mail_template_warranty_claim", raise_if_not_found=False) if template: template.send_mail(self.id, force_send=True) self.state = "sent" return True