Help

0

Show product categories on invoice

Avatar
Cornelius Kraus

Hello guys, 

I started Odoo development few months ago and set up my own module where I added some fields, edited views and defined actions.
Now I am facing a big challenge and do not know how to start. I should add a frontpage to the printed out invoice where you can see the invoiced positions but filtered by their category. 
For example, the categories are "ESX", "EXT" and "COLOR", there should be a frontpage of the invoice where you can see how many products of which category are invoiced, so it should be like
"ESX, 37 products invoiced, 69$ total"
"EXT, 42 products invoiced, 99$ total" and so on.
Is it possible to sum the quantities of products with the same category directly in qweb or has it to be done in python? How to declare the function that computes quantities for only one product category?
I appreciate any answer.
Thanks for your help in advance

Sincerely

Nils Kraus
Avatar
Abbandona
1 Risposta
0
Avatar
Cornelius Kraus
Best Answer

I got it! If anyone is also wondering how to this, I did it within my custom module.
First of all, you have to create two new fields in python code. The first in the model "sale.order.line" which gets the category of the product model. It should look like this:

x_category_on_saleorderline = fields.Many2one(related="product_id.categ_id")
Now we have the field on the sale.order.line so we can process it to the invoice by creating another related field on the model "account.move.line". This should look like following:

x_category_on_invoiceline = fields.Many2one(related='sale_line_ids.xcategory_on_saleorderline')

Now we can add the field to the invoice QWeb template and even filter it there. For example, to get the summed up quantities for one category I did it like:

<span t-esc="int(sum(line.quantity for line in lines.filtered(lambda r: r.x_category_on_invoiceline.name == '[name of category]')))"/>

Don't mind to contact me if you have any questions regarding this.

Avatar
Abbandona