Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
6370 Vistas

I want to add the TIN No. in onchange_partner_id so that in a user choose a supplier the TIN no. of that specific supplier will also appear in the view. when I overrite the codes in both .py and .xml. It does not show the value of tin.. Please someone help me... here is my code:

.py:

class account_invoice(osv.osv):
    _inherit = "account.invoice"
    _columns = {
                'tin' : fields.char('TIN No.',size=100),
                
                }
    
    def onchange_partner_id(self, cr, uid, ids, type, partner_id,\
            date_invoice=False, payment_term=False, partner_bank_id=False, company_id=False):
        partner_payment_term = False
        acc_id = False
        bank_id = False
        fiscal_position = False
        tin = False
        opt = [('uid', str(uid))]
        if partner_id:

            opt.insert(0, ('id', partner_id))
            p = self.pool.get('res.partner').browse(cr, uid, partner_id)
            tin = p.tin
            if company_id:
                if (p.property_account_receivable.company_id and (p.property_account_receivable.company_id.id != company_id)) and (p.property_account_payable.company_id and (p.property_account_payable.company_id.id != company_id)):
                    property_obj = self.pool.get('ir.property')
                    rec_pro_id = property_obj.search(cr,uid,[('name','=','property_account_receivable'),('res_id','=','res.partner,'+str(partner_id)+''),('company_id','=',company_id)])
                    pay_pro_id = property_obj.search(cr,uid,[('name','=','property_account_payable'),('res_id','=','res.partner,'+str(partner_id)+''),('company_id','=',company_id)])
                    if not rec_pro_id:
                        rec_pro_id = property_obj.search(cr,uid,[('name','=','property_account_receivable'),('company_id','=',company_id)])
                    if not pay_pro_id:
                        pay_pro_id = property_obj.search(cr,uid,[('name','=','property_account_payable'),('company_id','=',company_id)])
                    rec_line_data = property_obj.read(cr,uid,rec_pro_id,['name','value_reference','res_id'])
                    pay_line_data = property_obj.read(cr,uid,pay_pro_id,['name','value_reference','res_id'])
                    rec_res_id = rec_line_data and rec_line_data[0].get('value_reference',False) and int(rec_line_data[0]['value_reference'].split(',')[1]) or False
                    pay_res_id = pay_line_data and pay_line_data[0].get('value_reference',False) and int(pay_line_data[0]['value_reference'].split(',')[1]) or False
                    if not rec_res_id and not pay_res_id:
                        raise osv.except_osv(_('Configuration Error!'),
                            _('Cannot find a chart of accounts for this company, you should create one.'))
                    account_obj = self.pool.get('account.account')
                    rec_obj_acc = account_obj.browse(cr, uid, [rec_res_id])
                    pay_obj_acc = account_obj.browse(cr, uid, [pay_res_id])
                    p.property_account_receivable = rec_obj_acc[0]
                    p.property_account_payable = pay_obj_acc[0]

            if type in ('out_invoice', 'out_refund'):
                acc_id = p.property_account_receivable.id
                partner_payment_term = p.property_payment_term and p.property_payment_term.id or False
            else:
                acc_id = p.property_account_payable.id
                partner_payment_term = p.property_supplier_payment_term and p.property_supplier_payment_term.id or False
            fiscal_position = p.property_account_position and p.property_account_position.id or False
            if p.bank_ids:
                bank_id = p.bank_ids[0].id
                
        netsvc.Logger().notifyChannel("111111111 ", netsvc.LOG_INFO, 'IN IN IN ????? ' + str(acc_id))
        netsvc.Logger().notifyChannel("111111111 ", netsvc.LOG_INFO, 'IN IN IN ????? ' + str(partner_payment_term))
        netsvc.Logger().notifyChannel("111111111 ", netsvc.LOG_INFO, 'IN IN IN ????? ' + str(p.tin))
        result = {'value': {
            'account_id': acc_id,
            'payment_term': partner_payment_term,
            'fiscal_position': fiscal_position,
            
            }
        }
        result['value']['tin'] = p.tin
        if type in ('in_invoice', 'in_refund'):
            result['value']['partner_bank_id'] = bank_id

        if payment_term != partner_payment_term:
            if partner_payment_term:
                to_update = self.onchange_payment_term_date_invoice(
                    cr, uid, ids, partner_payment_term, date_invoice)
                result['value'].update(to_update['value'])
            else:
                result['value']['date_due'] = False

        if partner_bank_id != bank_id:
            to_update = self.onchange_partner_bank(cr, uid, ids, bank_id)
            result['value'].update(to_update['value'])
      
        return result
             
account_invoice()

.xml:

<record model="ir.ui.view" id="rl_invoice_supplier_form_inherit">
        <field name="name">rl.account.invoice.supplier.form.inherit</field>
        <field name="model">account.invoice</field>
        <field name="inherit_id" ref="account.invoice_supplier_form"/>
        <field name="priority">2</field>
        <field name="arch" type="xml">
              <xpath expr="//field[@name='partner_id']" position="after">
                <field name="tin"/>
            </xpath>
        </field>
    </record>
   

 

 

Avatar
Descartar
Mejor respuesta

You need to redefine the partner_id and all other fields that uses onchange_partner_id in rl_invoice_supplier_form_inherit.  Specifically you need to change the on_change attributes of those field.  Just redefine it with the same on_change.

I'm not 100% sure but I think the reason is that each onchange_partner_id method defined for account.invoice and the all it's inherits are be tagged with the module name as namespace.  And each view will only look for the method that belongs to the same namespace.  So, originally onchange_partner_id is defined in module account.  The view defined in module account will look for onchange_partner_id that is defined there.  If you define (inherit) it in your module, you need to inherit the view and redefine the on_change attribute of that field again so it will look for the method defined in your module.

Avatar
Descartar
Autor

how will i going to redefined it?

Easy way: just copy it from the original and put it between ...

Sorry, forgot that comment dislike HTML: copy the original and put it in place of ... in <field name='partner_id' position='replace'>...</field>

Do it for every field that uses the method in on_change.

Autor

i already did this but nothing happen

You marked the question as solved. Maybe you can help others by sharing how you solve it.