Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
2 Replies
4070 Tampilan

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
Buang

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

Penulis

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

Jawaban Terbai

from openerp.osv import fields, osv, orm

class AccountInvoice(osv.osv):

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

Avatar
Buang
Penulis

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 ?

Jawaban Terbai

Hi Yassine,

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

Avatar
Buang
Penulis

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

Penulis

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

Post Terkait Replies Tampilan Aktivitas
0
Mei 22
3438
1
Nov 24
2148
5
Jul 24
94511
1
Des 23
3495
1
Mei 22
4384