It is currently Tue May 22, 2012 11:46 pm

All times are UTC + 2 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Dynamically change type of field
PostPosted: Tue Jul 19, 2011 4:12 pm 
Offline

Joined: Tue Jul 19, 2011 4:09 pm
Posts: 6
Hi,

Is there a way to change the type of a field based on the value of another field? Specifically, I'm trying to make a check box which, when enabled, will let the price field on a product get calculated (ie. it's a function field), but when disabled the user should be able to enter the price manually.


Top
 Profile  
 
 Post subject: Re: Dynamically change type of field
PostPosted: Wed Jul 20, 2011 2:22 pm 
Offline

Joined: Thu Oct 28, 2010 1:51 pm
Posts: 53
Hi,
I wouldnt have the price field a function field, i'd have an on change on product assign so when the product was assigned and the check box was ticked it would return the price value into the price field.

I dont even bother with the tick box in my code, i've simply got a price field, on product assign it writes the price in and the user can then override if necessary.

_________________
Developing OpenERP Modules for what seems like an eternity
Smart IT Ltd
http://www.smart-ltd.co.uk


Top
 Profile  
 
 Post subject: Re: Dynamically change type of field
PostPosted: Thu Jul 21, 2011 5:11 am 
Offline

Joined: Wed Jan 27, 2010 6:21 pm
Posts: 797
Location: Auckland, NZ
onchange is the way to go. However it shouldn't be assigned on the boolean (or at least not only on the boolean). It needs to occur on the fields that affect the calculation of price. Then test for bool if False keep going if true calculate.

My very first module I wrote had that requirement. It sounds easy, but to really get it working properly is quite intricate, especially with all the onchange calls already happening around products and prices.

Also gets a bit tricky in that if price is read-only when you save it won't be stored. So often you have to do trickery to stop users from changing, like changing field back to writable on exit, or making invisible instead of readonly, or overriding write function.

_________________
Graeme


Top
 Profile  
 
 Post subject: Re: Dynamically change type of field
PostPosted: Wed Aug 03, 2011 10:39 am 
Offline

Joined: Tue Jul 19, 2011 4:09 pm
Posts: 6
Thanks - I'll definitely check on_change (already had half a mind to do that with the calculation on fields that affect it), but looks like I'll need to be doing a little more with it than just that.


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