Odoo-如何添加“代码"会计模型领域 [英] Odoo - How to add "code" field to Accounting Model

查看:90
本文介绍了Odoo-如何添加“代码"会计模型领域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个模块,该模块将打印一些与发票有关的值.会计模型中唯一缺少的两件事是字段:

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:

-vat

-代码(国家/地区代码)

-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')

我肯定弄乱了这部分:

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.partnerMany2one关系. 您可以关联到此关系的其他字段,例如在您的示例中,发票合作伙伴的增值税.您必须像大多数面向对象的语言一样使用点符号. 但是,链条并没有止步于第一块.因此,您可以联系许多更深层次的"关系.例如您的国家/地区代码:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆