Odoo Help


How to call a method in domain act_window ?

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

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



my python code shown below :

class wtc_approval_line(osv.osv):

    def _get_transaction_no(self, cr, uid, ids, field_name, args, context=None):
        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
              'transaction_id' :fields.integer('Transaction ID'),
              '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),
              'transaction_no':fields.function(_get_transaction_no, string="Transaction No", type="char")
              'sts' : '1'

    def wtc_ambil_group(self,cr,uid,ids,context=None):
        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']
            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')]}"/>


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




| 5 3 6
Jakarta, Indonesia
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.


Emipro Technologies Pvt. Ltd.

--Emipro Technologies Pvt. Ltd.--
| 6 7 8
Rajkot, India
--Emipro Technologies Pvt. Ltd.--

Being an emerging leader in IT market since 2011, Emipro Technologies Pvt. Ltd. has been providing a wide range of business solutions in Odoo & Magento. We are pleased to have a large pool of contented customers with our meticulous work in the domain of ERP & e-Commerce. A ray of relief & satisfaction to  our customers heart by our successful deployment in their organization, purely represents our success in Odoo platform. Hence, we take pride for being an Odoo partner with a vision of expanding our strategic alliances with our customers to offer them high value-added, trustworthy & cost effective solutions.


Since establishment, our business has span across 11 countries of the world. Our customers are companies of all sizes ranging from start-ups to large enterprises, who realize that they need a professional business solutions to generate revenue streams, establish proper communication channels or streamline business operations. Standing with strong determination of customer satisfaction, observing each minute detail of their business processes, providing proper guidance and moving forth to develop product accordingly adds our value and reliability among our customers. 


We are blessed with efficient, passionate & eclectic young developers who have come across almost all kinds of business profiles, working with full dedication, applying creativity & new features in existing modules and completing customer's projects successfully on predefined target. Our in-depth knowledge while giving business solutions in Odoo allows us to offer following services to our customers :


  • Consulting
  • Installation, Configuration & Customization
  • Training & Support
  • Maintenance
  • Upgradation
  • Documentation
  • Crafting community modules
  • Drafting videos on demand
  • Smart Apps development

We will be :) to welcome you @ www.emiprotechnologies.com to solve any kind of your business needs around Odoo. However we are just an inch away from you by email info@emiprotechnologies.com or a tweet to @EmiproTech

Emipro Technologies Pvt. Ltd.
On 12/28/14, 11:54 PM


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
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) :
        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>

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.


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)


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