This question has been flagged

I'm trying to customize the invoice form, especially the Customer invoices form, I'm just trying to add a date field after the invoice date, and replace a button, for that I created a new module, here after the code : 

from openerp.osv import fields, osv, orm
from openerp.tools.translate import _

class AccountInvoice(orm.Model):

    _inherit = 'account.invoice'
    _name = 'account.invoice'
    _colmuns = {
        'date_livraison': fields.date('Date Livraison'),
    }

For the view : 

        <record id="invoice_form_custom" model="ir.ui.view">
            <field name="name">invoice.form.custom</field>
            <field name="model">account.invoice</field>
            <field name="inherit_id" ref="account.invoice_form"/>
            <field name="arch" type="xml">

                <xpath expr="//form/header/button[@name='invoice_open']" position="replace">
                   <button name="invoice_validate" states="draft" string="Valider" type="object" class="oe_highlight"/>
                </xpath>
                <xpath expr="//form/sheet/group/group/field[@name='date_invoice]" position="after">
                    <field name="date_livraison"/>
                </xpath>


            </field>
        </record>

Three points deserves interest : 

When commenting the inheritance of date_livraison, it rises XML architecture error,then, the replacement of the button is correct, and the inheritance for date_livraison is not correct.

The account.invoice inherits from mail.thread like this : 

    _name = "account.invoice"
    _inherit = ['mail.thread']

And invoice_form is a view used also for Customer refund.

Is that may cause some problems when customizing invoice_form view, or just I'm missing something on the xml code ?

Avatar
Discard

In original "account.invoice_form" are two buttons named 'invoice_open', you have not specified clearly that replacing.

Author

but when I remove the second inheritance, it works fine, so the problem is wieh the field "date_livraison", it's not recognized as a field added by inheritance !!

Best Answer

from openerp.osv import fields, osv, orm

class AccountInvoice(osv.osv):

    _inherit = 'account.invoice'
    _columns = {
        'date_livraison': fields.date('Date Livraison'),
    }

Avatar
Discard
Author

Yes, that's right, I used to inherit with "orm.Model", when adding fields, it's considered among the best practices of inheritance, why it didn't work here ?

Best Answer

Hi Yassine,

I can see in your code that instead of "_columns" it says "_colmuns"... Could this be your problem?

Avatar
Discard
Author

Hi Aitor, No it's just here, it's right on the source code.

Author

In fact, I should inherit with "osv.osv" check my comment for sameer.