Odoo Help

0

how to return a value from wizard form ?

By
Ajeng Shilvie
on 12/25/14, 1:40 AM 2,334 views

i have added a button wizard in purchase order form that contain reject button and special cancel button.

as soon as i click that button , the wizard form show up. Then after i fill every field in that wizard i have to click the reject button to execute the method. but my method doesn't return anything. did i put the wrong return ?

here's the code :

class reason_reject_approval(osv.osv_memory):
    _name = "reason.reject.approval"
    _columns = {
                'reason':fields.text('Reason')
                }
    
    def wtc_reject_approval(self, cr, uid, ids, context=None):
        val = self.browse(cr, uid, ids, context=context)
        user = self.pool.get("res.users").browse(cr, uid, uid)['groups_id']
        line = self.pool.get("purchase.order").browse(cr,uid,ids,context=context)
        
        for x in line.app_line :
            for y in user:
                    if y == x.group_id :
                        for z in line.app_line :
                                z.write(cr,uid,z.id,{
                                        'reason':val.reason,
                                        'value':line.amount_total,
                                        'sts':'3',
                                        'pelaksana':uid,
                                        'tanggal':datetime.today()
                                        })   
                                
        self.pool.get("purchase.order").action_cancel(cr, uid,ids)
        self.pool.get("purchase.order").write(cr, uid, ids, {'approval_state':'r'})
                                                      
        return True

--------------------------------------------------------------------------------------------------------------------------------------------------------------------

do you know how to solve it ? thanks.

@ajeng what value you want to return and how will you use that returned value? what is your exact purpose? Also in the getting the browse record for 'purchase.order' you have directly use 'ids' which is wrong you should have used context.get('active_id')

Emipro Technologies Pvt. Ltd.
on 12/25/14, 1:51 AM

in approval , there are 2 condition ,, approve and reject . if the reason is reject there must be a reason. I want that reason to show up in purchase order form .

Ajeng Shilvie
on 12/25/14, 2:23 AM

previously i have added one2many field on purchase order called app_line it contain many fields , such as reason, value , sts, pelaksana, tanggal, etc. i have added two button approve and reject , reject is a wizard that i mean.

Ajeng Shilvie
on 12/25/14, 2:25 AM

@Ajeng what have you used on the wizard to get the reason from the user? Is it just a text box? and if yes where exactly you want that value to be saved? If possible try posting some images of your screen so can better idea.

Emipro Technologies Pvt. Ltd.
on 12/25/14, 4:23 AM

if you don't mind can i know your email ? i will sent directly by email

Ajeng Shilvie
on 12/25/14, 4:32 AM

@emipro this is the link for what i mean https://berbagiopenerp.wordpress.com/2014/12/25/approval-purchase-order/

Ajeng Shilvie
on 12/25/14, 4:53 AM
1

Hello,

Please see the below function which is you need to correct which is called when you press "Reject" button on wizard.

import netsvc

def wtc_reject_approval(self, cr, uid, ids, context=None):
        val = self.browse(cr, uid, ids, context=context)
        user = self.pool.get("res.users").browse(cr, uid, uid)['groups_id']

        po_id = context.get('active_id',False) #When you call any wizard then in this function ids parameter contain the list of ids of the current wizard record. So, to get the purchase order ID you have to get it from context.
        line = self.pool.get("purchase.order").browse(cr,uid,po_id,context=context)
        
        for x in line.app_line :
            for y in user:
                    if y == x.group_id :
                        for z in line.app_line :
                                z.write(cr,uid,z.id,{
                                        'reason':val.reason,
                                        'value':line.amount_total,
                                        'sts':'3',
                                        'pelaksana':uid,
                                        'tanggal':datetime.today()
                                        })   
                                
        wf_service = netsvc.LocalService("workflow")

        wf_service.trg_validate(uid, 'purchase.order', po_id, 'purchase_cancel', cr)        

        self.pool.get("purchase.order").write(cr, uid, po_id, {'approval_state':'r'})
                                                      
        return True

I hope this function may setisfy your need.

@Emipro , i am sorry , it still error , it said..... write() takes exactly 2 arguments (5 given)

Ajeng Shilvie
on 12/25/14, 5:27 AM

@Emipro ... yeayyyy i did it !!! thank you so muchhh emipro .. i rewrite z.write{xxxxx} instead z.write{cr,uid,z.id} it works, thanks !!

Ajeng Shilvie
on 12/25/14, 5:30 AM

Ohh, your z.write(...) called from browse object so you do not pass cr, uid, z.id. It may fix.

Emipro Technologies Pvt. Ltd.
on 12/25/14, 5:30 AM

yes , it all thanks too you ..

Ajeng Shilvie
on 12/25/14, 5:32 AM
This is the result <img goomoji="360" style="margin: 0px 0.2ex; vertical-align: middle;" src="cid:360@goomoji.gmail"> , Big Thanks for your Big HELP !! <img goomoji="330" style="margin: 0px 0.2ex; vertical-align: middle;" src="cid:330@goomoji.gmail">



2014-12-25 17:30 GMT+07:00 Emipro Technologies <erp@emiprotechnologies.com>:

Ohh, your z.write(...) called from browse object so you do not pass cr, uid, z.id. It may fix.

Emipro Technologies is best in Odoo & eCommerce Application development based outsourcing software firm. We deliver any kind of complex solutions in the domain of Odoo and eCommerce to customers accross the globe. Being in IT business since 2011, We have a strong team of skilled experienced IT experts.Our customers are companies of all sizes ranging from startups to large enterprises who realize that they need a professional internet solution to generate revenue streams, establish communication channels or streamline business operations.

Our Services in Odoo includes,
  • Installation
  • Customization
  • Configuration
  • Software Training
  • After Sale Support
  • Maintenance
  • Consulting
Contact info@emiprotechnologies.com for any kind of queries in Odoo. Visit www.emiprotechnologies.com for more details.




 

Sent by Odoo S.A. using Odoo about Forum Post False

Ajeng Shilvie
on 12/25/14, 5:36 AM

@ Emipro i have different issue , if i use this method on purchase.requisition the workflow doesn't go to cancel state , did i have to use different code instead of this ? wf_service.trg_validate(uid, 'purchase.requisition', pr_id, 'tender_cancel', cr)

Ajeng Shilvie
on 12/25/14, 6:10 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)

Stats

Asked: 12/25/14, 1:40 AM
Seen: 2334 times
Last updated: 3/16/15, 8:10 AM