Skip to Content
Menu
This question has been flagged
3 Replies
3518 Views

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.

How can I insert the field in my tree?

Thanks
Avatar
Discard
Best Answer

Try this search domain  [('origin','=', record.name)]

Avatar
Discard
Author Best Answer

Sorry, the correct error is as follows. By mistake I copied the error doing other tests:

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.

Avatar
Discard
Best Answer

Hello Valentina,

Sale Order have order_line

sale order line have invoice_lines

invoice line have invoice_id

So by using above relation you can get whatever you want.

I Hope your problem will be solved with this.

Avatar
Discard