2

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
    

1 Answers1

0

I'm not sure if I understood your question accurately, but it seems that you are trying to get the ans field filled up based on whatever the total is. First of all find and get which field links both these model (in your case it is the customer_id field), probably there will be a Many2one relation between these two models. Using this related field (customer_id) you can user related fields to obtain the total into ans. It would be something like the following:

ans = fields.Integer(related=customer_id.total, string='ans')
Fotu N
  • 1
  • 2