콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
5623 화면

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
아바타
취소
작성자 베스트 답변

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.

아바타
취소

Hello Cornelius,

One question, can this be done via Studio? (Create the related fields, I don't know if the model info is available or not)

작성자

Hello Bruno, I am not sure. Sorry, I don't know much about Studio. If you are able to, just do it directly in the code behind.

Hi Cornelius

i have a question should i related field to model ?

Thanks for your help in advance

관련 게시물 답글 화면 활동
1
9월 23
3595
2
10월 19
9093
1
10월 15
8158
2
1월 20
9198
0
12월 24
1375