[英]How to call a field on different models using qweb report in odoo 10?
我使用qweb創建了一個報告,當我需要顯示來自不同模型的其他數據時,它說錯誤“ account.invoice對象沒有屬性'pack_operation_product_ids'”。 我的主要問題是如何從相同的模塊但不同的對象或模型調用pack_operation_product_ids。 謝謝
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
返回錯誤
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>
在編寫此代碼<tr t-foreach="o.pack_operation_product_ids" t-as="m">
,您實際上正在訪問的是對象o
pack_operation_product_ids
字段,該字段當前是account.invoice
的記錄集account.invoice
根據您的問題account.invoice
。 因此,要訪問特定字段,您必須在模型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):
...
...
您的代碼不必完全像這樣,而是類似這樣,基於您不知道的要求。
同樣在您的python代碼中,您正在使用以下術語'pack_operation_product_ids', '=', 'o.pack_operation_product_ids'
進行搜索,但右葉是字符串,左葉是不存在的字段。 我不知道您怎么認為這將起作用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.