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