It is currently Tue May 22, 2012 9:38 pm

All times are UTC + 2 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: setting a default value for a field based on a m2m
PostPosted: Wed Nov 18, 2009 8:44 pm 
Offline

Joined: Wed Nov 18, 2009 8:39 pm
Posts: 1
hi,

i have a model 'A' wich relates to a model 'B' through a o2m field 'b_id'. the A model also has an integer field 'a_field'

when I'm adding a new 'A' entry through the OpenERP interface I go to a B instance page and click "add new A'. i need to set a default value for the a_field based on the last 'A' instance related to this 'B' instance.

The problem is that I can't find how I get the 'B' instance id I'm adding these 'A' instance.

is there a way to accomplish that?

thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 19, 2009 4:10 pm 
Offline

Joined: Fri May 29, 2009 1:51 pm
Posts: 16
i faced a similar problem and the way i solved it was via the context option. within the xml definition i used the context tag to store the "active_id". within the py file i created a default for the (as you call it) "a_field" and assigned the variable from the context string.

hope this will help you.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 11, 2009 3:10 am 
Offline

Joined: Fri Nov 06, 2009 4:26 am
Posts: 79
Hi Rhanke
rhanke wrote:
i faced a similar problem and the way i solved it was via the context option. within the xml definition i used the context tag to store the "active_id". within the py file i created a default for the (as you call it) "a_field" and assigned the variable from the context string.


Could you please paste your code on how you put this "context option" ?

Sincerely
-bino-


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 11, 2009 3:44 pm 
Offline

Joined: Thu Oct 01, 2009 4:27 pm
Posts: 9
Hi, I also would appreciate if you could paste your code. I have no idea how to solve this problem via xml and py file.
regards
-tulator-


Top
 Profile  
 
 Post subject: Re: setting a default value for a field based on a m2m
PostPosted: Sun Jul 24, 2011 11:16 pm 
Offline

Joined: Sun Jul 24, 2011 11:04 pm
Posts: 3
Location: Canada
Hi,
Here, is what I found (this example is base on an o2m field):

In the py file:

Code:
    _defaults = {
        'a_field' : lambda self, cr, uid, context : context['a_field'] if context and 'a_field' in context else None 
    }


In the xml file (in a ir.ui.view record):

Code:
...
<field  name="o2m_field" nolabel="1" mode="tree,form" context="a_field=active_id,b_field=xxx,c_field=yyy">
...


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 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