Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
2 Risposte
15166 Visualizzazioni

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?

Avatar
Abbandona
Autore Risposta migliore

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
Avatar
Abbandona
Risposta migliore

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

Avatar
Abbandona
Autore

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.

Post correlati Risposte Visualizzazioni Attività
0
set 23
1703
1
gen 22
8598
1
gen 25
1518
1
apr 24
1893
2
dic 23
13005