Skip to Content
Menu
This question has been flagged
3 Replies
15212 Views

I have model: 


current_dep = fields.One2many('hr.department', compute="_current_dep", string="Managed departments of current user")

@api.multi

def _current_dep(self):

self.current_dep = self.env['hr.department'].search([('manager_id', '=', self.env.user.id)])


And view:


<record id="action_my_income_transfers" model="ir.actions.act_window">

<field name="name">Transfers</field>

<field name="res_model">employee.transfer</field>

<field name="view_mode">tree,form</field>

<field name="transfer_form_id" ref="create_transfer"/>

<field name="transfer_tree_id" ref="transfer_tree_view"/>

<field name="domain">[('stage', '=', 'confirmed_cur'),('department_new', '=', current_dep)]</field>

</record>



But i got the error "NameError: name 'current_dep' is not defined"
Odoo 10

Avatar
Discard
Best Answer

Hi, Andrey


You are getting this issue because "current_dep" is not defined inside the windows action and by default in Odoo you can't pass value in domain inside a XML file for windows action. You can only pass static value like you passed in a first argument.

('stage', '=', 'confirmed_cur')

In order to pass dynamic value for windows action you can create windows action through python file like below,

def view_categ_ids(self):
        return {
            'name': _('Product Categories'),
            'view_mode': 'tree,form',
            'res_model': 'product.category',
            'type': 'ir.actions.act_window',
            'domain': [('route_ids', 'in', self.ids)],
        }
Feel free to ask in case you have any doubt related to the above point.


Thanks,
Ashish Singh (Team Lead)
Webkul Software Private Limited
Avatar
Discard
Best Answer

I don't see the field current_dep being added to the view.  If it isn't in the view, you can't use it in the domain.

Avatar
Discard
Best Answer

Python knows the purposes of certain names (ex. built-in functions ). Other names are defined within the program (ex. variables). If Python encounters a name that it doesn't recognize, you'll probably get NameError: global name 'xx' is not defined error. In most cases, this error is triggered when Python sees a variable name (Global or Local) and doesn't know what it's for. These errors can happen if you forget to initialize a variable , if you misspell a variable, or if you misspell a reserved word such as "True". Before you use the global variable in your function for reading, it must be first initialized somewhere: either outside of the function or inside it.

http://net-informations.com/python/iq/global.htm



Avatar
Discard
Related Posts Replies Views Activity
1
Mar 15
8002
5
Sep 20
11369
2
May 18
3500
2
Mar 15
6105
1
Mar 15
4127