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

All times are UTC + 2 hours




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: [Solved] Ask for extra data to write on action
PostPosted: Mon Jul 11, 2011 9:56 am 
Offline

Joined: Thu Mar 31, 2011 8:45 am
Posts: 242
Location: Málaga, Spain
Hi, i need to ask for extra info to the user when a button is pressed to fill a confirmation file.

What i have now, is a button which when is pressed creates a xml file, with the data of the current record, and i need to ask the user to fill 2 text fields to add to that file.

What should i use? a wizard? i didn't use them yet and i don't really know how it works.

_________________
Desarrollo Compuservice
Parque Tecnológico de Andalucía


Last edited by Reinhart on Wed Jul 20, 2011 9:18 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Ask for extra data to write on action
PostPosted: Mon Jul 11, 2011 10:23 am 
Offline

Joined: Wed Jan 27, 2010 6:21 pm
Posts: 797
Location: Auckland, NZ
Yes you need a wizard.

Specifically a wizard defines an interaction between between a client and the server.
Specifically your requirement requires an interaction between the client and the server.

They aren't too hard.

Basically your button will now call the wizard.

Your wizard will contain 2 fields of type char.

Your wizard will have an OK button, and the return of the function on the OK button will generate your xml file. Obviously I don't know the specifics but look at wizards that define reports on records (i.e wizards in the right pane of an object), step through them, you will see model and id's of calling object passed in context.

_________________
Graeme


Top
 Profile  
 
 Post subject: Re: Ask for extra data to write on action
PostPosted: Mon Jul 11, 2011 1:44 pm 
Offline

Joined: Thu Mar 31, 2011 8:45 am
Posts: 242
Location: Málaga, Spain
I see, i created the wizard, and it shows the form, but, can i call a function/method from the parent object when i press Ok on the wizard or should i implement the function in the wizard?

I mean i want to call the method i called in my button at first time, because that method check some values in the object and call another method with a parameter. I use that method in various buttons and the parameter defines which type of structure it should be used to create the xml file.

_________________
Desarrollo Compuservice
Parque Tecnológico de Andalucía


Top
 Profile  
 
 Post subject: Re: Ask for extra data to write on action
PostPosted: Mon Jul 11, 2011 2:23 pm 
Offline

Joined: Wed Jan 27, 2010 6:21 pm
Posts: 797
Location: Auckland, NZ
yes you can call whatever function you like. From memory their is a good example in stock module, wizard folder. It is called stock_onshipping_invoice or something like that. That gets a couple of inputs like date, and journal then calls the invoice create function of stock.picking before returning True.

It is the wizard called when you create invoice from picking.

_________________
Graeme


Top
 Profile  
 
 Post subject: Re: Ask for extra data to write on action
PostPosted: Tue Jul 12, 2011 4:32 pm 
Offline

Joined: Thu Mar 31, 2011 8:45 am
Posts: 242
Location: Málaga, Spain
I have searched, looked at sotck module and tryied to call the main function when i press ok on the wizard, but i don't really know how to, it always launch some exception, maybe i'm calling the function in the wrong part of the code, where should i call the function or how? I tried with something like my_module.my_object.my_function on the wizard action, but it doesn't work

Any hint?

_________________
Desarrollo Compuservice
Parque Tecnológico de Andalucía


Top
 Profile  
 
 Post subject: Re: Ask for extra data to write on action
PostPosted: Tue Jul 12, 2011 9:20 pm 
Offline

Joined: Wed Jan 27, 2010 6:21 pm
Posts: 797
Location: Auckland, NZ
Code:
your_obj = self.pool.get('your.object')
active_ids = context.get('active_ids', [])
return_value = your_obj.your_function(cr, uid, active_ids, context=context)


Is basically it. No different to any other module except accessing ids from context. I assumed a standard signature but you get the idea.

_________________
Graeme


Top
 Profile  
 
 Post subject: Re: Ask for extra data to write on action
PostPosted: Mon Jul 18, 2011 1:18 pm 
Offline

Joined: Thu Mar 31, 2011 8:45 am
Posts: 242
Location: Málaga, Spain
Many thanks, now the function launches well when i press Ok button in the wizard, but now, how i can read the fields i entered in the wizard?
Is there an example in any module?

By the way i am getting this error TypeError: read() got an unexpected keyword argument 'load' when i try to read values, i overloaded the read method which is causing that exception, but it works well by itself.

_________________
Desarrollo Compuservice
Parque Tecnológico de Andalucía


Top
 Profile  
 
 Post subject: Re: Ask for extra data to write on action
PostPosted: Mon Jul 18, 2011 11:01 pm 
Offline

Joined: Wed Jan 27, 2010 6:21 pm
Posts: 797
Location: Auckland, NZ
This is the standard way

data = self.read(cr, uid, ids, context=context)[0]

then you just refer to fields like

field_x = data['field_x']

_________________
Graeme


Top
 Profile  
 
 Post subject: Re: Ask for extra data to write on action
PostPosted: Tue Jul 19, 2011 9:33 am 
Offline

Joined: Thu Mar 31, 2011 8:45 am
Posts: 242
Location: Málaga, Spain
Ok, i tried that but still getting exceptions, to prevent the (TypeError: read() got an unexpected keyword argument 'load') i comented my overloaded read method, then with field_x = data['field_x'] i got ,KeyError: 'field_x'

I don't know what i am doing wrong here is my code:

Code:
from osv import osv, fields

class wiz_unsu(osv.osv_memory):
   _name = 'club.wizard.unsu'
   _columns = {
      'reasons': fields.char('Reasons to unsuscribe', size=140, required=True),
      'actions': fields.char('Actions', size=210, required=True),
   }
      def unsuscribe(self, cr, uid, data, context=None):
      pooldata = self.pool.get('club.activees')
      active_ids = context.get('active_ids', [])
      values ={'type':'ir.actions.act_window_close'}
      pooldata.send_unsu(cr, uid, active_ids, context=context)
      return values
wiz_unsu()   


send_usu function, part of club.activees object which calls the wizard :
Code:
         data = self.read(cr, uid, ids, context=context)[0]
         field_x = data['reasons']

So ther i got -> KeyError: reasons

And this is my read overloaded method which causes the first exception TypeError: read() got an unexpected keyword argument 'load'
Code:
   def read(self, cr, uid, ids, fields=None, context=None):
      values = super(club_activees, self).read(cr, uid, ids, fields, context)
      finality=values[0].get('finality', False)
      try:
         fin_list = finality.split(';')
         values[0]['n_fin'] = len(fin_list)
         for f in fin_list : values[0]['f'+f] = True
      except: values[0]['n_fin'] = 0
      return values

_________________
Desarrollo Compuservice
Parque Tecnológico de Andalucía


Top
 Profile  
 
 Post subject: Re: Ask for extra data to write on action
PostPosted: Tue Jul 19, 2011 8:59 pm 
Offline

Joined: Wed Jan 27, 2010 6:21 pm
Posts: 797
Location: Auckland, NZ
You need to read your wizard values in the wizard, and then pass to your function so more like

Code:
def unsuscribe(self, cr, uid, data, context=None):
      pooldata = self.pool.get('club.activees')
      active_ids = context.get('active_ids', [])
      wiz_data = self.read(cr, uid, ids, context=context)[0]
      values ={'type':'ir.actions.act_window_close'}
      pooldata.send_unsu(cr, uid, active_ids, wiz_data, context=context)
      return values


or else pass in context and access there

Code:
def unsuscribe(self, cr, uid, data, context=None):
      pooldata = self.pool.get('club.activees')
      active_ids = context.get('active_ids', [])
      context['wiz_data'] = self.read(cr, uid, ids, context=context)[0] #or use context.update (note you are defaulting context to None so you might need to check and initialise to empty list first although you should do this already or your context.get call could be buggy)
      values ={'type':'ir.actions.act_window_close'}
      pooldata.send_unsu(cr, uid, active_ids, context=context)
      return values

_________________
Graeme


Top
 Profile  
 
 Post subject: Re: Ask for extra data to write on action
PostPosted: Wed Jul 20, 2011 9:18 am 
Offline

Joined: Thu Mar 31, 2011 8:45 am
Posts: 242
Location: Málaga, Spain
Ok, i got it, it works well now, btw i solved the problem caused by overloading read method changing all the uses of .read and .browse methods in my code with direct Select's to data base.

_________________
Desarrollo Compuservice
Parque Tecnológico de Andalucía


Top
 Profile  
 
 Post subject: Re: [Solved] Ask for extra data to write on action
PostPosted: Thu Jul 21, 2011 5:04 am 
Offline

Joined: Wed Jan 27, 2010 6:21 pm
Posts: 797
Location: Auckland, NZ
Glad you got there in the end.

Personally I hate direct selects, and I can honestly say I have never found a reason to use them over the ORM, excepting some sql views and reports, and I've written a decent amount of code. Additionally I have never found any reason to change the function signature of any ORM method. If you are in a situation where you really need to extend it, then adding to context and testing in your overload is usually the most you need to do and often not even that. Haven't done for read or browse, but certainly for write, unlink, copy, name_get, name_search so I imagine the principal is the same.

_________________
Graeme


Top
 Profile  
 
 Post subject: Re: [Solved] Ask for extra data to write on action
PostPosted: Thu Jul 21, 2011 9:19 am 
Offline

Joined: Thu Mar 31, 2011 8:45 am
Posts: 242
Location: Málaga, Spain
I preffer also use ORM methods of course, but i really needed to overload read, create, write and unlink methods and when i overloaded the read method all reads i did in other parts of my code causes the exception, so i decided to use selects.

_________________
Desarrollo Compuservice
Parque Tecnológico de Andalucía


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