Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Openerp 7 Functional Field Help [Closed]

By
Eric
on 3/6/14, 1:55 PM 844 views

The Question has been closed

by
Sudhir Arya (SA)
on 03/07/2014 02:35:34

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

image description

1

Sudhir Arya (SA)

--Sudhir Arya (SA)--
10150
| 6 8 8
Ahmedabad, India
--Sudhir Arya (SA)--

Working as an OpenERP/Odoo developer and a Team Leader 

Top 5 Odoo contributor On Stackoverflow

LinkedIn

Blog

Stackoverflow

Sudhir Arya (SA)
On 3/6/14, 2:48 PM

Try it again after restarting the OpenERP server.

Tried it again by removing _name. You just need to use _inherit

If you already have tried this then make sure you have imported your py file in __init__.py.

As per the error it seems your code is not getting updated.

Thank you Sudhir! It turned out that all I needed to do was to import the python file in the __init__.py file. I forgot to add that in haha.

Eric
on 3/6/14, 2:59 PM

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 3/6/14, 1:55 PM
Seen: 844 times
Last updated: 3/16/15, 8:10 AM