콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
6129 화면

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 

아바타
취소
작성자 베스트 답변

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.

아바타
취소