Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
3 Відповіді
16338 Переглядів

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

Аватар
Відмінити
Найкраща відповідь

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
Аватар
Відмінити
Найкраща відповідь

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.

Аватар
Відмінити
Найкраща відповідь

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



Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
1
бер. 15
8949
5
вер. 20
12788
2
трав. 18
4459
2
бер. 15
7458
1
бер. 15
5241