It is currently Mon May 21, 2012 6:50 pm

All times are UTC + 2 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: [SOLVED] How is "name" derived in sale_view
PostPosted: Wed Jun 01, 2011 4:12 pm 
Offline

Joined: Tue Mar 09, 2010 4:08 pm
Posts: 117
Hi

In the res_partner model/table, there is a field which holds the Partner name and the field is called "name" (not surprising)

Then there is this line of code in the sale_view.xml:
Code:
<field name="partner_id" on_change="onchange_partner_id(partner_id)" ...


that calls this onchange_partner_id method/function:
Code:
def onchange_partner_id(self, cr, uid, ids, part):
        if not part:
            return {'value': {'partner_invoice_id': False, 'partner_shipping_id': False, 'partner_order_id': False, 'payment_term': False, 'fiscal_position': False}}

        addr = self.pool.get('res.partner').address_get(cr, uid, [part], ['delivery', 'invoice', 'contact'])
        part = self.pool.get('res.partner').browse(cr, uid, part)
        pricelist = part.property_product_pricelist and part.property_product_pricelist.id or False
        payment_term = part.property_payment_term and part.property_payment_term.id or False
        fiscal_position = part.property_account_position and part.property_account_position.id or False
        dedicated_salesman = part.user_id and part.user_id.id or uid
        val = {
            'partner_invoice_id': addr['invoice'],
            'partner_order_id': addr['contact'],
            'partner_shipping_id': addr['delivery'],
            'payment_term': payment_term,
            'fiscal_position': fiscal_position,
            'user_id': dedicated_salesman,
        }
        if pricelist:
            val['pricelist_id'] = pricelist
        return {'value': val}


that somehow puts the contents of the "name" column into the "partner_id" field on the screen. How is that linked together since there is no mention of "name" anywhere and the partner_id is just an key field.

Thanks in advance
O.


Last edited by ocset on Tue Jun 07, 2011 2:42 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: How is "name" derived in sale_view
PostPosted: Thu Jun 02, 2011 6:37 pm 
Offline

Joined: Wed Jan 27, 2010 6:21 pm
Posts: 797
Location: Auckland, NZ
There is 2 parts to your question.

1. How does name turn up - well it would look very stupid if everytime we had a relation we just showed their database id wouldn't it? I sold 4 of product 3 to partner 6 on pricelist 1 to deliver to address 3 is quite difficult to understand. So by default there is a function called name_get which displays (by default, it can be changed) the contents of the name column.

2. None of this has anything to do with onchange, well except that it also call name_get for all of the fields it returns as the values are just relation id's.

_________________
Graeme


Top
 Profile  
 
 Post subject: Re: How is "name" derived in sale_view
PostPosted: Fri Jun 03, 2011 2:41 am 
Offline

Joined: Tue Mar 09, 2010 4:08 pm
Posts: 117
Thanks gdaddy - what I would give right now for your knowledge of OpenERP 8)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 2 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:

Protected by Anti-Spam ACP