0

I am trying to create a functional field by inheriting the account.invoice.line table, but I cant seem to get it working. Here is the python code

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

and here is the xml view code

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

Now I dont want to store this value in the table, but I would like to show the calculated number in the view. I know this is possible, but after I install the module and then check the invoices form then I get this message

View error

Can't find field 'calc_qty' in the following view parts composing the view of object model 'account.invoice':
* Account Invoice Form Inherited

Either you wrongly customized this view, or some modules bringing those views are not compatible with your current data model

Erik Kaplun
  • 37,128
  • 15
  • 99
  • 111
Eric
  • 1
  • 1
  • 4
  • Well I found out what the problem was. It had nothing to do with this code above, but instead it was related to the __init__.py file. I forgot to add the import for the python file in the __init__.py file so the field wasn't being created at all – Eric Mar 06 '14 at 19:02
  • function must be come first before _columns = {} Otherwise you will be get error like function not found "your function name" – Bhavesh Odedra Mar 07 '14 at 08:07
  • Function definition must comes before the function calling line. in your case define you function before the _columns. – Viraj Joshi - Emipro Mar 17 '15 at 12:22

0 Answers0