Odoo Help

0

How to call a method in domain act_window ?

By
Ajeng Shilvie
on 12/27/14, 11:45 PM 2,058 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>

1
Ivan
On 12/29/14, 1:28 AM

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.

1

@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 !!.

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

Ajeng Shilvie
on 12/29/14, 12:12 AM

@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.

Emipro Technologies Pvt. Ltd.
on 12/29/14, 12:16 AM

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 Shilvie
on 12/29/14, 12:20 AM

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

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

@Emipro , i have edited my post above ..

Ajeng Shilvie
on 12/29/14, 12:36 AM

@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?

Emipro Technologies Pvt. Ltd.
on 12/29/14, 1:28 AM

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

Ajeng Shilvie
on 12/29/14, 1:51 AM
0
Ajeng Shilvie
On 12/29/14, 3:18 AM

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

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

1 follower(s)

Stats

Asked: 12/27/14, 11:45 PM
Seen: 2058 times
Last updated: 3/16/15, 8:10 AM