Odoo - 如何添加“代码"会计模型字段 [英] Odoo - How to add "code" field to Accounting Model
问题描述
我正在开发一个模块,该模块将打印与发票相关的一些值.会计模型中唯一缺少的两件事是字段:
I am working on a module that will print some values related to the invoice. The only two things that are missing in the Accounting Model are fields:
-增值税
-code(国家/地区代码)
-code (Country Code)
我已成功添加增值税字段.但是,尝试带入代码"字段时出现错误.我的py代码如下:
I have successfully added vat field. However, get an error when trying to bring the "code" field. My py code is as follows:
from openerp import models, fields
class CountryCodeInvoice(models.Model):
# where to place new fields
_inherit = 'account.invoice'
# getting country code to the accounting model
code = fields.Char(string='Country Code', related='res_country.code')
class AccountInvoiceInherited(models.Model):
# where to place new fields
_inherit = 'account.invoice'
# getting the vat field to accounting model
vat = fields.Char(string='vat', related='partner_id.vat')
我肯定把这部分搞砸了:
I have definitely messed up this part:
related='res_country.code'
这是我想要得到的最终结果:
This is the final result I am trying to get:
您是否知道任何解释如何处理相关领域的教程?官方文档不是很深入...
Do you know any tutorials that explain how to work with related fields? Official documentation does not go very deep...
推荐答案
相关字段基于您正在处理的模型上的关系.通常这些字段是 Many2one
字段.您已经将一个用于 vat
:partner_id
,它是与模型 res.partner
的 Many2one
关系.您可以与此关系的其他字段相关联,例如在您的示例中发票合作伙伴的增值税.您必须像在大多数面向对象的语言中一样使用点符号.但是链条并没有停在第一块上.因此,您可以关联更多更深层次"的关系.例如您的国家/地区代码:
Related fields base on a relation on the model you're working on. Usually these fields are Many2one
fields. You already used one for vat
: partner_id
which is a Many2one
relation to model res.partner
.
You can relate to other fields of this relation, like in your example the vat of the invoice partner. You have to use dot-notation like in the most object oriented languages.
But the chain doesn't stop on the first piece. So you can relate on much "deeper" relations. For example your country code:
code = fields.Char(string='Country Code', related='partner_id.country_id.code')
再次以 partner_id
开头.但是国家代码在关系链中更深.res.partner
与包含代码的模型 res.country
有 Many2one
关系.只需使用点表示法即可.
Again it's partner_id
the chain begins with. But the country code lays deeper in the relation chain. res.partner
has a Many2one
relation to model res.country
which holds the code. Just use dot-notation to get to it.
这篇关于Odoo - 如何添加“代码"会计模型字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!