Odoo Help


Get and set text in a xml field

João Sequeira
on 12/30/14, 5:13 AM 807 views

Hello, I am a new programmer to odoo and in my search i didn't find an answer to my problem.

I am using an extension of the res_partner_view in the base folder for the name field. What i want to do is that a user can not change the name of a partner if there is no vat or there is one defined as generic(999999990). When i do the raise saying the user can't change the name i want to put the original name in the field before he tried to change.


I have a onchange function in my module:

  def onchange_partner_name(self, cr, uid, ids, n, context=None):
        #raise osv.except_osv(_('Alterar nome'), _('Função onchange_partner_name'))
        result = {}
        cr.execute("Select res_partner.vat, res_partner.name, account_invoice.state from account_invoice inner join res_partner on account_invoice.partner_id = res_partner.id where res_partner.id = '%s'" % ids[0])
        registos = cr.fetchall()
        if (len(registos) > 0):
            partner_nif = list(set(i[0] for i in registos))
            if partner_nif[-1] == None or str(partner_nif[-1]) == '999999990':
                for vat,nam,estado in registos:
                    if estado == 'open' or estado == 'paid':
                            raise osv.except_osv(_('Cliente com documentos emitidos'), _(content + 'Não pode alterar o Nome de um cliente sem NIF.'))
        result['name'] = n
        return {'value': result}   

And my xml is:

<?xml version="1.0" encoding="utf-8"?>

        <record id="view_partner_form_Name" model="ir.ui.view">
            <field name="name">res.partner.form2</field>
            <field name="model">res.partner</field>
            <field name="inherit_id" ref="base.view_partner_form"/>
            <field eval="1" name="priority"/>
            <field name="arch" type="xml">
                <field name="name" default_focus="1" placeholder="Name" position="replace">
                    <field name="name" default_focus="1" placeholder="Name" on_change="onchange_partner_name(name)"/>


So i want to, or save the name before changing of the field "name" from the xml and before the raise change it back or before the raise put the name that is in the table.

Is there a way to get and set the contend (string) that is present in the field name of the xml?

Thanks in advance 

João Sequeira
On 1/6/15, 10:50 AM

i don't know if anyone have the same problem as I but the solution that i found was to add a warning to the return instead of the raise osv.except....

     for vat,nam,estado in registos:
                        if estado == 'open' or estado == 'paid':
                            result['name'] = nam
                            return{'value': result, 'warning':{'title':'warning','message':'Não pode alterar o Nome de um cliente sem NIF.'}}


And this will not permit to change the field "name" giving a warning, and rollback the changes in the field to the name stored in the table.

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 12/30/14, 5:13 AM
Seen: 807 times
Last updated: 3/16/15, 8:10 AM