Good morning,
I have created a field from graphical interface that for each order (in sale.order) calculates all the amounts of the invoices linked to this order (in account.invoice).
The code of the field x_accountInvoice_amountUntaxed is the following, added in the model sale.order:
for record in self:
temp = self.env['account.invoice'].search([('origin','=', self.name)]) total = 0 for comp in temp: total += comp.amount_untaxed record['x_accountInvoice_amountUntaxed'] = total |
The field does the correct calculation, the problem is when I add it to the view of the orders (I would like to make a comparison between the total sold and the total invoice)
If I add the field in the view sale.order.form the field is displayed and calculated correctly:
<field name="x_accountInvoice_amountUntaxed"/>
If instead I insert it in the view sale.order.tree I have the following error:
ValueError: <type 'exceptions.ValueError'>: "Expected singleton: sale.order(2, 5, 6, 7, 8, 13, 14, 15, 16, 21, 25, 30, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 45, 46, 47, 49, 50, 51, 53, 54, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 92, 93, 95, 108, 109, 110, 111, 112, 113, 114, 116, 117, 122, 123, 124, 125, 126)" while evaluating u"for record in self:\r\n temp = self.env['account.invoice'].search([('origin','=', self.name)])\r\n total = 0\r\n for comp in temp:\r\n total += comp.amount_untaxed \r\n record['x_accountInvoice_amountUntaxed'] = total"
The relationship between sale.order and account.invoice is recognized because the data is displayed, but I can not add it in the view sale.order.tree.
Thanks