0
votes

I had created a new field in res.partner Model using this code and modified the form view of Partner to display the new field, and it worked very well. Now I am trying to refer to the new field in the Invoice View and make it get added to the Print Invoice. I don't know how to do it. I tried different ways but nothing works. Could you help me please? I searched many hours on this and other forums but nothing. i'm working with odoo 8, Please Help me. Thanks!

.py file

    from openerp.osv import osv, fields

    class res_partner(osv.osv):

        _inherit = 'res.partner'

        _columns = {
               'clientes_rnc_ced': fields.char('RNC o Cédula',size=12),
        }

    res_partner()

XML file

    <?xml version="1.0" encoding="utf-8"?>
    <openerp>
        <data>
            <record id="clientes_atributos_form" model="ir.ui.view">
                <field name="name">clientes.atributos.form</field>
                <field name="model">res.partner</field>
                <field name="type">form</field>
                <field name="inherit_id" ref="base.view_partner_form"/>
                <field name="arch" type="xml">
                   <field name="ref" position="after">
                        <field name="clientes_rnc_ced" />
                   </field>
                </field>
            </record>
            <record id="clientes_atributos_tree" model="ir.ui.view">
                <field name="name">clientes.atributos.tree</field>
                <field name="model">res.partner</field>
                <field name="type">form</field>
                <field name="inherit_id" ref="base.view_partner_tree"/>
                <field name="arch" type="xml">
                   <field name="display_name" position="before">
                        <field name="clientes_rnc_ced" />
                   </field>
                </field>
            </record>        
        </data>
    </openerp>
1
Thanks so much Alex! Sorry for my very bad English.user2574943
Do you mean to say that you want add the same field in 'account.invoice', which you have added in the 'res.partner'?. If yes then you can take the 'fields.related' field in the invoice screen which will be related to the 'partner_id' field in 'account.invoice'. Search for the example of how to add related field.Hardik Patadia
Thanks! i have solved the issue callíng the field like this "partner_id.clientes_rnc_ced"user2574943

1 Answers

0
votes

As @Hardik suggests you have to use related field in you account.invoice model. I personally find this weird as it would be much more intuitive, flexible and powerful to write just <field name="partner_id.clientes_rnc_cedclientes_rnc_ced"> but this doesn't work in OpenERP.

Instead, you have to declare a new field in the 'account.invoice' model which takes the value from the related 'res.partner' model. In an appropriate place in your model extend the 'account.invoice' model as you did for 'res.partner'

class invoice(osv.osv):
    _inherit = 'account.invoice'
    _columns = {
           'rnc_ced': fields.related('partner_id',
                                     'clientes_rnc_ced',
                                     type='char', size=12,
                                     string='RNC o Cédula'),
    }

invoice()

Now you can put it in the Invoice the way you already know.

<field name="rnc_ced">