This question has been flagged
2285 Views

Hi All,

I have created a form like distributors, in this form distributor_lines need to take customer name(onchange function), phone and email, when i click the save button customer name is not saved, different user name is saved , please help me.

here is my code :

xml file :


<record model="ir.ui.view" id="crm_sale_distributor_view_form">

<field name="name">endo.distributor.form</field>

<field name="model">endo.distributor</field>

<field name="arch" type="xml">

<form string="Sales Distributor" version="7.0">

<group col="5">

<field name="name" style="width: 50%%" />

<field name="dist_id"/>

</group>

<group>

<notebook colspan="4">

<page string="Distributor Line">

<field name="distributor_line" widget="one2many" nolabel="1">

<tree editable="bottom">

<field name="partner_id" string="Customer Name"

on_change="on_change_partner(partner_id)"/>

<field name="x_cus_phone"/>

<field name="x_cus_email"/>

</tree>

</field>

</page>

</notebook>

</group>

</form>

</field>

</record>

py file :


class distributor_lines(osv.osv):

_name = "endo.distributor.lines"

_description="Sales Distributor Lines"

_columns = {

'partner_id': fields.many2one('res.partner', 'Customer Name', ondelete='cascade', select=True),

'x_cus_phone': fields.char('Mobile', size=64),

'x_cus_email': fields.char('Email', size=240),

}

def on_change_partner(self, cr, uid, ids, partner_id, context=None):

values = {}

if partner_id:

partner = self.pool.get('res.partner').browse(cr, uid, partner_id, context=context)

values = {

'x_cus_email' : partner.email,

'x_cus_phone' : partner.phone,

}

print "values", values

return {'value' : values}

distributor_lines()

class endo_distributor(osv.osv):

_name = 'endo.distributor'

_description="Sales Distributors"

_columns={

'name':fields.char('Distributor Name', size=128, required=True),

'dist_id': fields.many2one('res.partner', 'Partner'),

'distributor_line': fields.one2many('endo.distributor.lines', 'partner_id', 'Distributor Lines'),

}

endo_distributor()

Thanks in advance

Avatar
Discard