I have created a report using qweb , when i need to show the others data from different models it says error "account.invoice object has no attribute 'pack_operation_product_ids'" . My main question here is how to call pack_operation_product_ids from that same module but different object or models. Thanks
PP.xml
<tr t-foreach="o.pack_operation_product_ids" t-as="m">
<tr t-foreach="o.picking_ids" t-as="l">
<td> <span t-field="l.name"/> | <span t-field="m.name"/> </td>
models.py
from odoo import fields,models,api
@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['stock.picking'].search([('pack_operation_product_ids', '=', 'o.pack_operation_product_ids')])
return record_collection
return error
AttributeError: 'account.invoice' object has no attribute 'pack_operation_product_ids'
Error to render compiling AST
AttributeError: 'account.invoice' object has no attribute 'pack_operation_product_ids'
Template: invoice_report2.qweb_inv_pp_document
Path: /templates/t/t/t/div/div[3]/div[2]/table/tbody/tr
Node: <tr t-foreach="o.pack_operation_product_ids" t-as="m">
<!-- <tr t-foreach="request.env['stock.picking'].search([(
'pack_operation_product_ids', '=', o.pack_operation_product_ids.name)])" t-as="obj"> -->
<!--<tr t-set="record_collection" t-value="doc.get_data()">-->
<tr t-foreach="o.picking_ids" t-as="l">
<td> <span t-field="l.name"/> | <span t-field="m.name"/> </td>
</tr>
</tr>
When you are writing this code <tr t-foreach="o.pack_operation_product_ids" t-as="m">
what you are actually doing is this, you are accessing pack_operation_product_ids
field of object o
, which is currently a recordset of account.invoice
probably, as from your question. So, to need to access a particular field, you have to have that field defined on the model, account.invoice
, you can just inherit this existing and add that field and related functions, but you didn't even inherited any model or create, just created a function which is wrong.
from odoo import fields,models,api
class AccountInvoice(models.Model):
_inherit = 'account.invoice'
pack_operation_product_ids = field.One2many(compute='get_data')
@api.multi
def get_data(self):
...
...
your code don't have to be exactly like this, but something like this, based on your requirements which I don't know.
Also in your python code, you are using this term 'pack_operation_product_ids', '=', 'o.pack_operation_product_ids'
to search but the right leaf is a string and left leaf is a not existing field. I don't know how you think that is going to work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.