Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
6 Trả lời
17503 Lượt xem

Hello everybody, I have the doubt that if is possible create a qweb with data from different models, for example, if I have the models A, B, C (each one with data completely different) but the 3 models have one field in common, the employee_id, but I don't know how can I put the 3 models in a pdf and group the data of each one by the employee.


Anyone could help me? Thanks!!!

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

Just adding a point to what Yenthe told.

You can also search the any models from the qweb like this,

<t t-foreach="request.env['model_name'].search([('user_id', '=', o.user_id.id)])" t-as="obj">
# ..........................
</t

Thanks

Ảnh đại diện
Huỷ bỏ

Yep, that is also an option if you don't need to do any operations with the data or nothing very advanced. :)

Thanks a lot.

Câu trả lời hay nhất

Hi Jorge,

Usually in this case you should have one model from where you print the report, let us say it is account.invoice. If you then want to access data from two other models you should have a link to these models to easily access the data. Let us say you have account.invoice.one and account.ionvoice.two.
The account.invoice.one model is linked to the account.invoice with a field named invoice_one_id and the account.invoice.two model is linked to the account.invoice with a field named invoice_two_id. You could then do this in the code:

<span t-field="o.invoice_one_id.field1"/> <span t-field="o.invoice_two_id.field2"/>

If this is not the case you could call a Python function from the QWeb report like this:

<t t-set="record_collection" t-value="doc.get_data()"/>

And in the Python code you can then call this function and do whatever you want:

@api.multi

def get_data(self): record_collection = [] # Do your browse, search, calculations, .. here and then return the data (which you can then use in the QWeb) record_collection = self.env['account.invoice.two'].search([('name', '=', 'Example')]) return record_collection

Regards,
Yenthe

Ảnh đại diện
Huỷ bỏ

What about <t t-if="doc_model in ['account.invoice','sale.order']"> DO SOMETHING </t> See https://www.odoo.com/documentation/11.0/reference/reports.html for a complete list of all variables accessible in reports - docs, doc_ids, doc_model, time, user and res_company.

Câu trả lời hay nhất

Create a report in odoo from scratch using Qweb reporting engine. I am not going to paste here complete code please visit these links :

1- http://learnopenerp.blogspot.com/2016/11/how-to-create-qweb-reports-in-openerp.html

2- http://learnopenerp.blogspot.com/2016/09/how-to-create-custom-reports-in-odoo.html


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 4 20
2726
3
thg 8 18
10379
1
thg 3 17
2802
5
thg 11 24
46627
0
thg 1 23
1592