This question has been flagged
3 Replies
10150 Views

i already stack to get user current group id ,

i use this method to get current user group id :

    def cek_group(self,cr,uid,ids,context=None):
        x={}
        for rec in self.browse(cr,uid,ids) :
            x[rec.id] = self.pool.get("res.users").browse(cr, uid, uid)['groups_id']
        return x

but i don't know how to call it in my act_window. XML code shown below :

        <record model="ir.actions.act_window" id="approval_portal_action">
            <field name="name">Portal Approval Matrix Biaya</field>
            <field name="res_model">wtc.approval.line</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree</field>
            <field name="domain">[('sts','=','1'),('group_id','=',%(cek_group)d]</field>
        </record>

i got an error .. Error: % undefined as prefix

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

EDIT

my python code shown below :

class wtc_approval_line(osv.osv):
    _name="wtc.approval.line"

    
    def _get_transaction_no(self, cr, uid, ids, field_name, args, context=None):
        x={}
        for rec in self.browse(cr,uid,ids) :
            x[rec.id] = self.pool.get(rec.form.model).browse(cr,uid,rec.transaction_id).name
        return x
    
    _columns={
              'transaction_id' :fields.integer('Transaction ID'),
              'value':fields.float('Value',digits=(12,2)),
              'form':fields.many2one('ir.model','Form'),
              'group_id':fields.many2one('res.groups','Group', select=True),
              'cabang_id': fields.many2one('res.partner','Branch',select=True),
              'divisi_id': fields.selection([('t','Unit'),('s','Sparepart'),('u','Umum'),('f','Finance')],'Division',change_default=True),
              'wewenang':fields.float('Limit', digits=(12,2)),
              'sts':fields.selection([('1','Belum Approve'),('2','Approved'),('3','Rejected')],'Status',change_default=True),
              'pelaksana':fields.many2one('res.users','Pelaksana', size=128),
              'tanggal':fields.datetime('Tanggal'),
              'reason':fields.text('Reason'),
              'transaction_no':fields.function(_get_transaction_no, string="Transaction No", type="char")
              
              }
    _defaults={
              'sts' : '1'
              }

    def wtc_ambil_group(self,cr,uid,ids,context=None):
        x={}
        for rec in self.browse(cr,uid,ids) :
            x[rec.id] = self.pool.get("res.user").browse(cr, uid, uid)['groups_id']
        return x

    def wtc_approval_change(self,cr,uid,ids,context=None):
        val = self.browse(cr, uid, ids, context=context)     
        a = val.form.id
        if a == '333' :
            move_obj = self.pool.get('purchase.order')
            move_ids = context['active_ids']
            for data in self.browse(cr, uid, ids):
                move_obj.wtc_approval(cr, uid, move_ids,id=data.id,context=context)
        else :
            print "dffffffffffffff",a   
                                              
        return {'type': 'ir.actions.act_window_close'}
    
    def wtc_get_transaction(self,cr,uid,ids,context=None):  
        a = self.browse(cr,uid,ids)
        return {
            'name': 'Purchase Order',
            'view_type': 'form',
            'view_mode': 'form',
            'res_model': 'purchase.order',
            'type': 'ir.actions.act_window',
            'nodestroy': True,
            'target': 'new',
            'res_id': a.transaction_id  or False
            }

    def default_get(self, cr, uid, fields, context=None):
        if context is None:
            context = {}
        res = super(wtc_approval_line, self).default_get(cr, uid, fields, context=context)
        if not context.has_key('active_ids'):
            approval_ids = self.pool.get("res.user").browse(cr, uid, [])['groups_id']
        else:
            approval = context.get('active_ids')
            approval_ids = self.pool.get("res.user").browse(cr, uid, approval)['groups_id']
        if 'group_id' in fields:
            res.update({'group_id': approval_ids})
        return res

my xml code :

        <record model="ir.ui.view" id="approval_line_tree_view">
            <field name="name">approval.line.tree</field>
            <field name="model">wtc.approval.line</field>
            <field name="arch" type="xml">
                                
                <tree string="Approval Matrix Biaya" >
                    <field name="transaction_no"/>
                    <field name="form"/>
                    <field name="cabang_id"/>
                    <field name="divisi_id"/>
                    <field name="group_id"/>
                    <field name="value"/>
                    <field name="tanggal"/>
                    <field name="sts" />                    
                    <button name="wtc_get_transaction" type="object" string="Indext" icon="gtk-index"/>
                    <button name="wtc_approval_change" type="object" string="Approved" icon="gtk-apply" attrs="{'invisible':[('sts','!=','1')]}"/>
                    <button name="%(wtc_reject_list_action)d" type="action" string="Reject" icon="gtk-cancel" attrs="{'invisible':[('sts','!=','1')]}"/>

                </tree>
             </field>
        </record>

        <record model="ir.actions.act_window" id="approval_portal_action">
            <field name="name">Portal Approval Matrix Biaya</field>
            <field name="res_model">wtc.approval.line</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree</field>
            <field name="domain">[('sts','=','1'),('group)id','=',default_get)]</field>
        </record>

Avatar
Discard
Best Answer

@Ajeng

You can fulfill your purpose in "default_get" method under your wizard. There you can check out about the group. If your condition gets fulfilled you can continue loading the wizard else raise an exception.

 

Hope this helps !!.

Avatar
Discard
Author

@Emipro , do i have to write ... [('sts','=','1'),('group_id','=',default_get] ??

@Ajeng you can check both the condition or any more conditions in the "default_get" so i think you don't need it in the action definition. You can check these conditions in the method itself.

Author

i just want to filter list view by current user group , but i don't know how . better i use a method or something else. Like uid .

@Ajeng Can you post some code or image, so that we can better idea, what exactly you want to do.

Author

@Emipro , i have edited my post above ..

@Ajeng is "wtc.approval.line" model a temporay model or permanent. If it is a permanent model than how are you loading those values in it? I mean from those lines get filled up?

Author

it is a permanent model , i filled up depend on purchase order form

Best Answer

You cannot directly use method in domain.  But you can make the cek_group to be a function field and use the function field in the domain.

Avatar
Discard
Author Best Answer

I try to make function field .

    def _get_groups(self, cr, uid, ids, field_name, args, context=None):
        x = self.pool.get("res.users").browse(cr, uid, uid)['groups_id']
        #is self.group_id in x ?
        return self.group_id in x
    
    def _cek_groups(self, cr, uid, obj, name, args, context=None):
        res = []
        x = self.pool.get("res.users").browse(cr, uid, uid)['groups_id']
        ids = obj.search(cr,uid,[]) # ids of visits
        for v in self.browse(cr, uid, ids): # foreach visit
            if all(v.group_id == y[0] for y in x) :
                res.append(v.id)          
        return [('id','in',res)]

columns :

        'abc':fields.function(_get_groups, string="ABC", type="boolean", fnct_search=_cek_groups)

 

my xml code shown below :

        <record model="ir.actions.act_window" id="approval_portal_action">
            <field name="name">Portal Approval Matrix Biaya</field>
            <field name="res_model">wtc.approval.line</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree</field>
            <field name="domain">[('sts','=','1'),('abc','=',True)]</field>
        </record>

but it didn't return anything ..

Avatar
Discard