0

我试图通过继承account.invoice.line表来创建一个功能字段,但我似乎无法让它工作。这是python代码

class account_invoice_line(orm.Model):

    _name = 'account.invoice.line'
    _inherit = 'account.invoice.line'

    _columns = {        
        'calc_qty': fields.function(_get_calc_qty, type="float", string="Quantity", store=False),
    }

    def _get_calc_qty(self, cr, uid, ids, field_name, arg, context=None):
        calc_qty = {'qty': 0.0}
        return calc_qty

这是xml视图代码

    <record id="view_account_invoice_custom_form_inherit" model="ir.ui.view">
        <field name="name">Account Invoice Form Inherited</field>
        <field name="model">account.invoice</field>
        <field name="inherit_id" ref="account.invoice_form"/>
        <field name="arch" type="xml">

            <xpath expr="/form/sheet/notebook/page[@string='Invoice Lines']/field[@name='invoice_line']/tree/field[@name='quantity']" position="replace">
                <field name="calc_qty" />
            </xpath>

        </field>
    </record>

现在我不想将此值存储在表中,但我想在视图中显示计算出的数字。我知道这是可能的,但是在我安装模块然后检查发票表格之后,我收到了这条消息

查看错误

在构成对象模型“account.invoice”视图的以下视图部分中找不到字段“calc_qty”:
* Account Invoice Form Inherited

要么你错误地定制了这个视图,要么带来这些视图的某些模块与你当前的数据模型不兼容

4

0 回答 0