如何关联国家和发票以打印自定义文本? [英] How can I relation countries and invoices for print a custom text?
问题描述
在发票视图中,我有一个自定义的布尔字段和一个自定义的文本字段.
In the invoice view I have a custom boolean field and a custom text field.
Odoo Server Error
Traceback (most recent call last):
File "/home/ubuntu/OdooAddons/odoo/odoo/addons/base/models/qweb.py", line 348, in _compiled_fn
return compiled(self, append, new, options, log)
File "<template>", line 1, in template_account_report_invoice_document_with_payments_104
File "<template>", line 2, in body_call_content_103
File "/home/ubuntu/OdooAddons/odoo/addons-extra/emb_account/models/account_invoice.py", line 13, in country_group_country_ids
return self.env['country.group'].search([('name', '=', group)]).mapped('country_ids.id')
File "/home/ubuntu/OdooAddons/odoo/odoo/api.py", line 831, in __getitem__
return self.registry[model_name]._browse((), self)
File "/home/ubuntu/OdooAddons/odoo/odoo/modules/registry.py", line 177, in __getitem__
return self.models[model_name]
KeyError: 'country.group'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/ubuntu/OdooAddons/odoo/addons/web/controllers/main.py", line 1686, in report_download
response = self.report_routes(reportname, docids=docids, converter=converter)
File "/home/ubuntu/OdooAddons/odoo/odoo/http.py", line 519, in response_wrap
response = f(*args, **kw)
File "/home/ubuntu/OdooAddons/odoo/addons/web/controllers/main.py", line 1627, in report_routes
pdf = report.with_context(context).render_qweb_pdf(docids, data=data)[0]
File "/home/ubuntu/OdooAddons/odoo/odoo/addons/base/models/ir_actions_report.py", line 727, in render_qweb_pdf
html = self.with_context(context).render_qweb_html(res_ids, data=data)[0]
File "/home/ubuntu/OdooAddons/odoo/odoo/addons/base/models/ir_actions_report.py", line 767, in render_qweb_html
return self.render_template(self.report_name, data), 'html'
File "/home/ubuntu/OdooAddons/odoo/odoo/addons/base/models/ir_actions_report.py", line 540, in render_template
return view_obj.render_template(template, values)
File "/home/ubuntu/OdooAddons/odoo/odoo/addons/base/models/ir_ui_view.py", line 1338, in render_template
return self.browse(self.get_view_id(template)).render(values, engine)
File "/home/ubuntu/OdooAddons/odoo/addons/web_editor/models/ir_ui_view.py", line 29, in render
return super(IrUiView, self).render(values=values, engine=engine, minimal_qcontext=minimal_qcontext)
File "/home/ubuntu/OdooAddons/odoo/odoo/addons/base/models/ir_ui_view.py", line 1347, in render
return self.env[engine].render(self.id, qcontext)
File "/home/ubuntu/OdooAddons/odoo/odoo/addons/base/models/ir_qweb.py", line 59, in render
result = super(IrQWeb, self).render(id_or_xml_id, values=values, **context)
File "/home/ubuntu/OdooAddons/odoo/odoo/addons/base/models/qweb.py", line 275, in render
self.compile(template, options)(self, body.append, values or {})
File "/home/ubuntu/OdooAddons/odoo/odoo/addons/base/models/qweb.py", line 350, in _compiled_fn
raise e
File "/home/ubuntu/OdooAddons/odoo/odoo/addons/base/models/qweb.py", line 348, in _compiled_fn
return compiled(self, append, new, options, log)
File "<template>", line 1, in template_967_50
File "<template>", line 2, in body_call_content_49
File "<template>", line 3, in foreach_48
File "/home/ubuntu/OdooAddons/odoo/odoo/addons/base/models/qweb.py", line 355, in _compiled_fn
raise QWebException("Error to render compiling AST", e, path, node and etree.tostring(node[0], encoding='unicode'), name)
odoo.addons.base.models.qweb.QWebException: 'country.group'
Traceback (most recent call last):
File "/home/ubuntu/OdooAddons/odoo/odoo/addons/base/models/qweb.py", line 348, in _compiled_fn
return compiled(self, append, new, options, log)
File "<template>", line 1, in template_account_report_invoice_document_with_payments_104
File "<template>", line 2, in body_call_content_103
File "/home/ubuntu/OdooAddons/odoo/addons-extra/emb_account/models/account_invoice.py", line 13, in country_group_country_ids
return self.env['country.group'].search([('name', '=', group)]).mapped('country_ids.id')
File "/home/ubuntu/OdooAddons/odoo/odoo/api.py", line 831, in __getitem__
return self.registry[model_name]._browse((), self)
File "/home/ubuntu/OdooAddons/odoo/odoo/modules/registry.py", line 177, in __getitem__
return self.models[model_name]
KeyError: 'country.group'
Error to render compiling AST
KeyError: 'country.group'
Template: account.report_invoice_document_with_payments
Path: /templates/t/t/div/t[2]
Node: <t t-set="is_for_emb_message_country" t-value="o.partner_id.country_id and o.partner_id.country_id.id in o.country_group_country_ids('Exportaciones')"/>
我试图在报告中打印自定义字段的文本,但是仅当发票要转到国家/地区组时,我才具有该ID.我该怎么做?如何关联国家和发票来创建此商品?
I'm trying to print in the report the text of my custom field but only if the invoice is going to go to a country group i have the id of it. How can I do the function? How can I relation countries and invoices to create this?
推荐答案
最简单的方法是在帐户发票模型中添加一个函数,然后从qweb报表中调用它.您可以定义 qweb报告解析器,然后在此处定义它,以便在报告上下文中可用.
The easiest way is to add a function in account invoice model and call it from the qweb report. You can define a qweb report parser and define it there so it will be available in the report context.
示例
我想国家组的定义如下:
I suppose that the country group is defined like following:
class CountryGroup(models.Model):
_name = 'country.group'
name = fields.Char()
country_ids = fields.Many2many("res.country")
您需要做的是在帐户发票模型中定义一个函数,以返回特定国家/地区组的国家/地区ID:
All you need is to define a function in account invoice model to return the country ids of a specific country group:
class AccountInvoice(models.Model):
_inherit = 'account.invoice'
def country_group_country_ids(self, group):
return self.env['country.group'].search([('name', '=', group)]).mapped('country_ids.id')
以下代码扩展了发票报告,并在要演示的发票状态之后显示参考字段:
The following code extend the invoice report and show the reference field just after the invoice status for demonstration:
<template id="report_invoice_document" inherit_id="account.report_invoice_document">
<xpath expr="//h2" position="after">
<t t-if="o.partner_id.country_id and o.partner_id.country_id.id in o.country_group_country_ids('export')">
<p t-field="o.reference"/>
</t>
</xpath>
</template>
这篇关于如何关联国家和发票以打印自定义文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!