#start
from odoo import fields, models, api
class projo(models.Model):
_name='projo'
project = fields.Many2one('project', 'Project')
engineer = fields.Many2one('engineer', 'Engineer')
item_id = fields.One2many('book','item_id2')
#compute function 1 and it is working.
-
@api.one
@api.depends('item_id')
def _calcamount(self):
currentamount = 0
for projo in self.item_id:
currentamount = currentamount+(projo.qty * projo.unitprice)
self.totalam = currentamount
totalam = fields.Integer(string='Total Amount', store=True, compute='_calcamount')
#product many2onefield
class producta(models.Model):
_name='producta'
name = fields.Char('Name', required='true')
class Book(models.Model):
_name='book'
item_id2 = fields.Many2one('projo')
cr_date = fields.Date('Date')
prod = fields.Many2one('producta', 'Product')
Compute function 2 and it is not working.
@api.one
@api.depends('item_id')
def _calccost(self):
currenttotal = 0
for book in self.item_id:
currenttotal = currenttotal+(projo.qty * projo.unitprice)
self.costtotal = currenttotal
costtotal = fields.Integer(string='Total', store=True, readonly= False, compute='_calccost')
-
qty = fields.Integer('Quantity')
unitprice = fields.Integer('Unit Price')
item_id = fields.One2many('book', 'item_id2')