Skip to Content
Menu
This question has been flagged
1 Reply
3269 Views
I am trying to customize the invoice lines using the tools available in the developer mode.
I have started by creating a new field in account.invoice.line that perform a function defined in its compute field. Then added it to the invoice view and report. everything is perfect so far.
However, I need to also find the sum of this field , same as the amount_subtotal field in account.invoice which is the sum of the price_total for all items. I tried to mimic this and created a field in account.invoice, then tried to iterate over the account.invoice.line .x_my_field, but it seems that I can't access other models fields.

is there any way to perform this?
Here a how my invoice looks like ( https://image.ibb.co/jmY2bK/thumbnail_Odoo.jpg ). I want to sum the Net and Gross Weight for all entries. I'll show the total net and gross weight below the untaxed amount once I figure out how to sum them.
Avatar
Discard
Author Best Answer

Never mind. I figured it out :D

1) There is a field in account.invoice that is already related to account.invoice.line (named invoice_line_ids)

2) I created a new monetary field (x_sum_my_field) in account.invoice and added invoice_lines_ids as a dependency.

3) in the compute field, I wrote a simple code for summing the entries of my custom field (account.invoice.lines.x_my_field) 

for record in self: 
    record['x_sum_my_field'] = sum(l.x_my_field for l in record.invoice_line_ids) 

Hopefully it will help someone.

Avatar
Discard
Author

Just to answer the question is the title.. You can access fields of other objects by using a relational field (one2many in my case).

Related Posts Replies Views Activity
1
Aug 24
631
2
Jul 24
404
1
Jan 24
420
2
Apr 24
1920
1
Jul 22
890