Here is The problems
class Purchase(models.Model):
_name = 'purchase'
name = fields.Char(string="name")
orderDate = fields.Date(string="Order Date")
salesPerson = fields.Char(string="Sales Person", required=True)
expiredDate = fields.Date(string="Expired Date", required=True)
company = fields.Char(string="Company", related="customer_id.company", readonly=True)
tax = fields.Float(string ="Tax")
unTax = fields.Float(string="Untaxed", compute="_total_price")
amount_total = fields.Float(compute='_compute_amount_total', string="Total")
orderNumber = fields.Char(string="Order Number")
subpurchase_ids = fields.One2many('subpurchase', 'purchase_id', string="Purchase Lines")
customer_id = fields.Many2one('customer', string='partner', required=True)
state = fields.Selection([
('new', 'New'),
('draft', 'Draft'),
('validate', 'Validated'),
('cancel', 'Cancelled')],
string='Status', required=False, readonly=True, copy=False, default='new')
@api.onchange('tax', 'unTax')
@api.multi
def _compute_amount_total(self):
self.amount_total = self.unTax + self.tax
@api.depends('subpurchase_ids', 'subpurchase_ids.amount') #tambah kalo butuh relasi tambahan
@api.multi
def _total_price(self):
for purchase in self :
total_price = 0
for subpurchase in purchase.subpurchase_ids:
total_price += subpurchase.amount
purchase.unTax = total_price
i have an order lines so when i want add an item 2 or more the error come out ? how to fix this ?
example in order line i add an item Mouse 1 and save <= OKEY but when i add another item mouse 2 so there have a 2 item when i save this error come out
Thanks to you all for answer this question