Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
3 Antworten
16246 Ansichten

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
Verwerfen
Beste Antwort

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
Verwerfen
Beste Antwort

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
Verwerfen
Beste Antwort

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
Verwerfen
Verknüpfte Beiträge Antworten Ansichten Aktivität
1
März 15
8868
5
Sept. 20
12712
2
Mai 18
4394
2
März 15
7358
1
März 15
5166