Odoo Help

Welcome!

This community 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.

0

How to pass active id to a popup

By
Luis Filipe Castanheira
on 4/4/14, 12:49 PM 3,258 views

Hi, I am trying to pass the active id to a popup window so that in my function I can access the actual state of the caller object.

For that, I'm doing the following. In XML view:

<page string="Opinions">
    <field name="opinion_ids" context="{'generic_request_id': active_id}" >
        <tree delete="false"> 
            <field name="request_state" />
            <field name="opinion_request_date" />
            <field name="requestor" />
        (...)

In python I have:

_defaults={
    'state': 'requested',
    'opinion_request_date': lambda *a: datetime.date.today().strftime('%Y-%m-%d'),
    'request_state': lambda self, cr, uid, context: self._get_request_state(cr, uid, context=context), #store the state of the request when opinion was asked
    (...)
}
(...)
def _get_request_state(self, cr, uid, context=None):
    ids = context.get('generic_request_id', False)
    #import pdb; pdb.set_trace()        
    return self.pool.get('generic.request').browse(cr, uid, ids, context).state

In pdb I realize that "ids" is False because there is no generic_request_id variable in context...

(Pdb) p ids
False

(Pdb) p context
{'lang': 'en_US', 'no_store_function': True, 'tz': False, 'uid': 1}

Anyone knows a way to do this?

0

I finally managed to solve this in a very tortuous way. If anyone has a more straight forward way to do this, please help!

So, what I did was, create and save the opinion request and, in the function called by the workflow (request_opinion), I call an other function that checks the id of the request associated to this opinion an then it's actual state and, finally, updates the value in the opinion table.

Here is the code:

class opinion(osv.osv):
    _name='opinion'
    _description='opinion'
    _columns={
    (...)
        'state': fields.selection([('requested','Requested'),
            ('reviewing','Reviewing'),
            ('issued','Issued'),
            ('added','Added to the request')],
            'Status', readonly=True, track_visibility='onchange',
        ),
    (...)
        'request_state': fields.selection([('draft','Draft'),
            ('submitted','Submitted - Waiting for confirmation'),
            ('req_reformulation', 'Reformulation'),
            ('confirmed', 'Confirmed - Processing'),
            ('treatment', 'Processing'),
            ('wauth', 'Awaiting authorization'),
            ('wappr', 'Awaiting approval'),
            ('authorized','Authorized'),
            ('closed', 'Request closed'),
            ('closed_auth', 'Closed - Authorized'),
            ('closed_appr', 'Closed - Approved'),
            ('closed_disappr', 'Closed - Disapproved'),
            ('closed_nconf', 'Closed - Not confirmed'),
            ('closed_ref', 'Closed - Refused'),
            ('denied','Denied')],
            'Request Status', help="Status of the request when the opinion was requested", readonly=True, track_visibility='onchange',
        ),
        'generic_request_id': fields.many2one('generic.request', 'Request', required=True),
    }

    def _get_request_state(self, cr, uid, ids, context=None):
        res={}
        op = self.browse(cr, uid, ids, context=context)
        req_id = op[0].generic_request_id.id
        req = self.pool.get('generic.request').browse(cr, uid, req_id, context)
        #import pdb; pdb.set_trace()
        self.write(cr, uid, ids, {'request_state': req.state })
        return True

    def request_opinion(self, cr, uid, ids, context=None):
        self.write(cr, uid, ids, {'state': 'requested'})
        self._get_request_state(cr, uid, ids, context=context)
        return True

As I said before, if someone has a better sugestion to do this a more effective way, feel free to share!


Edit:

Changed it to be a little more effective (no need to call the _get_request_state() anymore). But still if anyone has better way to do this, fill free to share!

def request_opinion(self, cr, uid, ids, context=None):
    self.write(cr, uid, ids, {'state': 'requested', 'request_state': self.browse(cr, uid, ids, context=context)[0].generic_request_id.state })
    #self._get_request_state(cr, uid, ids, context=context)
    return True
0
Weste
On 4/4/14, 12:58 PM

I think you have to put your context="{'generic_request_id': active_id}" in the button that calls the wizard.

Thanks for the quick answer, but in this case I have no buttons... The popup is opened by the "Add an item" present in the tree view of the page refering to "opinion" in my "generic request" form view.

Luis Filipe Castanheira
on 4/4/14, 1:13 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 4/4/14, 12:49 PM
Seen: 3258 times
Last updated: 3/16/15, 8:10 AM