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.

1

Get and set text in a xml field

By
João Sequeira
on 12/30/14, 5:13 AM 484 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"?>
<openerp>
    <data>

        <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)"/>
                </field>
            </field>
        </record>

    </data>
</openerp>

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 

1
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.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

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

Question tools

1 follower(s)

Stats

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