我一直试图在account.invoice.line模型中添加一个字段,我在自定义模块中这样声明了Many2one字段:
class AccountInvoiceLine(models.Model):
"""
Model to add withholding concepts into the base invoice model
"""
_inherit = "account.invoice.line"
concept_id = fields.Many2one(
'account.wh.islr.concept',
string='Withholding Concept',
required=False,
help="Withholding concept asociated to this invoice line")
事实是,我无法通过直接将字段插入此模型的相应xml视图(account.invoice.line)中来将该字段添加到视图中,因为基本Odoo帐户模块在其基本发票视图中使用该字段定义了树形视图将发票连接到他们的行,即** invoice_line_ids。
<field
name="invoice_line_ids"
nolabel="1"
widget="section_and_note_one2many"
mode="tree,kanban"
context="{'type': type, 'journal_id': journal_id, 'default_invoice_id': id}"
>
<tree string="Invoice Lines" editable="bottom">
<control>
<create string="Add a line"/>
<create string="Add a section" context="{'default_display_type': 'line_section'}"/>
<create string="Add a note" context="{'default_display_type': 'line_note'}"/>
</control>
<field name="sequence" widget="handle"/>
<field name="product_id" domain="[('sale_ok','=',True)]"/>
<field name="origin" invisible="1"/>
<field name="is_rounding_line" invisible="1"/>
<field name="name" widget="section_and_note_text"/>
<field name="display_type" invisible="1"/>
<field name="company_id" invisible="1"/>
<field
name="account_id"
groups="account.group_account_user"
domain="[('company_id', '=', parent.company_id), ('internal_type', '=', 'other'), ('deprecated', '=', False)]"
attrs="{'required': [('display_type', '=', False)]}"
/>
<field name="account_analytic_id" groups="analytic.group_analytic_accounting"
domain="[('company_id', '=', parent.company_id)]"
context="{'default_partner_id': parent.partner_id}"/>
<field name="analytic_tag_ids" groups="analytic.group_analytic_tags" widget="many2many_tags" options="{'color_field': 'color'}"/>
<field name="quantity"/>
<field name="uom_id" groups="uom.group_uom"/>
<field name="price_unit" string="Price"/>
<field name="discount" groups="base.group_no_one" string="Disc (%)"/>
<field name="invoice_line_tax_ids" widget="many2many_tags" options="{'no_create': True}" context="{'type':parent.type, 'tree_view_ref': 'account.account_tax_view_tree', 'search_view_ref': 'account.account_tax_view_search'}"
domain="[('type_tax_use','=','sale'),('company_id', '=', parent.company_id)]"/>
<field name="price_subtotal" string="Subtotal" groups="account.group_show_line_subtotals_tax_excluded"/>
<field name="price_total" string="Total" groups="account.group_show_line_subtotals_tax_included"/>
<field name="currency_id" invisible="1"/>
</tree>
因此,我真正要做的是通过继承在account.invoice.line中设置字段,然后创建一个继承基本发票表单(在这种情况下是针对客户)的视图,并将该字段插入内部的树中那个领域的一部分。像这样:
<record model="ir.ui.view" id="view_invoice_line_form_islr">
<field name="name">account_invoice_line_concept_islr</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='invoice_line_ids']/tree/field[@name='product_id']" position="after">
<field name="concept_id" required="1"/>
</xpath>
</field>
</record>
遗憾的是,这些都不起作用,我完全确定这是完成这项工作的方法,但可悲的是我没有看到任何结果。 Odoo正在将concept_id字段正确地加载到数据库中,并且每当我升级模块并加载此代码时,都不会出现任何错误。但是,它根本不显示。初始化文件正在正确加载所有内容,并且视图已按原样加载到清单中。我用尽了所有的想法,我将自己的代码建立在可以正常工作的代码基础上,但是在Odoo 8中,该代码当时没有树形视图,但基本相同。
有什么想法吗?预先感谢!
答案 0 :(得分:0)
我设法自己解决了此问题。出于某种原因,当我将继承视图的ID更改为此Odoo时,它会识别并正确加载它。现在它显示了,这使我感到困惑,为什么这首先是一个问题,但现在已经解决了。我正在发布解决方案,因此,即使我确定我的案子非常特殊,如果将来有人发现类似的内容,他们也可以向该帖子寻求帮助。
我的代码最终看起来像这样:
<record model="ir.ui.view" id="view_invoice_line_form_islr_inherited">
<field name="name">account_invoice_line_concept_islr_inherited</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='invoice_line_ids']/tree/field[@name='product_id']" position="after">
<field name="concept_id" required="1"/>
</xpath>
</field>
</record>