简体   繁体   English

如何在odoo 10中使用qweb report在不同模型上调用字段?

[英]How to call a field on different models using qweb report in odoo 10?

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'" . 我使用qweb创建了一个报告,当我需要显示来自不同模型的其他数据时,它说错误“ account.invoice对象没有属性'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. 我的主要问题是如何从相同的模块但不同的对象或模型调用pack_operation_product_ids。 Thanks 谢谢

PP.xml 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 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. 在编写此代码<tr t-foreach="o.pack_operation_product_ids" t-as="m"> ,您实际上正在访问的是对象o pack_operation_product_ids字段,该字段当前是account.invoice的记录集account.invoice根据您的问题account.invoice 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. 因此,要访问特定字段,您必须在模型account.invoice上定义该字段,您可以继承现有字段并添加该字段和相关功能,但您甚至没有继承任何模型或创建,刚刚创建了一个错误的函数。

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. 同样在您的python代码中,您正在使用以下术语'pack_operation_product_ids', '=', 'o.pack_operation_product_ids'进行搜索,但右叶是字符串,左叶是不存在的字段。 I don't know how you think that is going to work. 我不知道您怎么认为这将起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM