Accessing a value from another model in odoo

Viewed 118

I have 2 simple models:

the first one is to create a product total

the other one is to calculate product total.

I want to get the product total value from the second model and pass first model how can I do that? I want to get ans fields value from second model ans pass total field from first model

class MyinvoiceInvoice(models.Model):
   _name = "myinvoice.invoice"
  total = fields.Integer(string="Total",store=True)

class InvoiceLine(models.Model):
    _name = "myinvoice.invoice.line"
    _description = "myinvoice.invoice.line"
    _inherit = "myinvoice.invoice"
    
    customer_id = fields.Many2one('myinvoice.invoice', string='Customer Id')
    product_id = fields.Many2one('myinvoice.product', string='Product')
    quanitity = fields.Integer(string="Quanitity")
    unit_price = fields.Integer(string="Unit Price",related='product_id.price')
    line_total = fields.Integer(string="Line Total",compute='_compute_total')
    ans = fields.Integer(string='ans')

   @api.depends('quanitity')
    def _compute_total(self):
        check = 0
        for record in self:
             if record.quanitity:
                record.line_total = record.unit_price * record.quanitity
                check += record.line_total
              else:
                record.quanitity = 0
        record.ans = check
    
0 Answers
Related