Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
6 Risposte
17471 Visualizzazioni

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!!!

Avatar
Abbandona
Risposta migliore

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

Avatar
Abbandona

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.

Risposta migliore

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

Avatar
Abbandona

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.

Risposta migliore

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


Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
0
apr 20
2698
3
ago 18
10363
1
mar 17
2796
5
nov 24
46571
0
gen 23
1573