Skip to Content
Menu
This question has been flagged
4 Replies
5073 Views

Hello,

Someone can me explain how to understand this error ? employee_id is define in my model and  my view. I don't touch the javascript...

Tanks

python:

 # -*- coding: utf-8 -*-
import datetime
from dateutil.relativedelta import relativedelta

from openerp import api, fields, models, _

class HrExpenseMileageWizard(models.TransientModel):

    _name = 'hr.expense.mileage.wizard'
    _description = "wizard to put mileage compensation"


    date = fields.Date(string="Date",default=fields.Date.today())
    distance = fields.Integer(string="Distance")
    employee_id = fields.Many2one("hr.employee", default= lambda self:self.env['hr.employee'].search([('user_id', '=', self.env.user.id)]))
    reason = fields.Char('Reason')
    vehicle =  fields.Many2many('hr.vehicle', string="vehicle", readonly=True)
    product = fields.Many2one('fiscal.horsepower',ondelete='cascade')
    rp_invoice = fields.Boolean(string=u"Facture au nom de RP")

    @api.multi
    def submit_mileage(self):
        self.ensure_one()

        emp_id = self.employee_id.id
        horsepower_id = self.vehicle.horsepower_id.id

        expenses = self.get_level_mileage(self.employee_id,horsepower_id)
        if len(expenses)==3:
            record = self.env['hr.expense'].create(expenses[0])

            record_bis = self.env['hr.expense'].create(expenses[1])

        else:
            record = self.env['hr.expense'].create(expenses)

# Warning
    @api.onchange('date')
    @api.multi
    def onchange_date_mileage(self):
        current_date = self.date
        current_year = datetime.datetime.now().strftime('%Y')
        end_fiscal_year = datetime.datetime.strptime(current_year + "-" + str(self.employee_id.company_id.fiscalyear_last_month) + "-" + str(self.employee_id.company_id.fiscalyear_last_day), '%Y-%m-%d').date()
        current_date_str = datetime.datetime.strptime(current_date,"%Y-%m-%d").date()
        start_fiscal_year = end_fiscal_year+relativedelta(years=-1)
        res = {}
        if current_date_str > end_fiscal_year or current_date_str < start_fiscal_year:
            res = {'warning': {
                'title': _('Warning, Mileage too old'),
                'message': _('Sorry, you set a too old mileage compensation. To more informations, contact gestion@reunionportage.com.')
            }}
            return res

    @api.multi
    def get_level_mileage(self, employee,horsepower_id):
        """Computes the level of mileage in the current year"""
        coeff = 0
        fixed = 0
        formula = 0
        two_expense = False
        employee_id = employee.id
        current_trip = self.distance
        product_id = self.env['product.product'].search([('default_code','=','MC')]).id
        mileages_and_accumulation = self.env['hr.employee.mileage'].get_mileage_accumulation(employee)
        mileages = mileages_and_accumulation[0]
        current_date = self.date
        current_year = datetime.datetime.now().strftime('%Y')
        end_fiscal_year = datetime.datetime.strptime(current_year + "-" + str(employee.company_id.fiscalyear_last_month) + "-" + str(employee.company_id.fiscalyear_last_day), '%Y-%m-%d').date()
        current_date_str = datetime.datetime.strptime(current_date,'%Y-%m-%d').date()
        start_fiscal_year = end_fiscal_year+relativedelta(years=-1)
        last_accumulation = mileages_and_accumulation[1]
        accumulation = last_accumulation + current_trip
        km_ranges = self.env['km.range'].search([('fisc_hp_id','=',horsepower_id)])

        #maybe : put a condition if in fical year ?

        if last_accumulation == 0 :
            last_trip = 0
        else:
            last_trip = mileages[0].quantity
        #bike
        if horsepower_id == self.env['fiscal.horsepower'].search([('vehicle_type','=','bike')]).id :
            if accumulation < km_range[0].kim_min:
                coeff = km_ranges[0].coeff
        #others (car,motorbike...)
        else:
            for range in km_ranges :
                i=0
                km_max = range.km_max
                km_min = range.km_min
                if range.km_max == 0:
                    if accumulation >= range.km_min :
                        if last_accumulation == 0 :
                            coeff = range.coeff
                            fixed = range.fixed
                        else:
                            coeff = range.coeff

                        if last_accumulation < range.km_min :
                            two_expense = True
                            km_up = accumulation - range.km_min
                            km_down = current_trip -km_up
                            coeff_bis = km_ranges[i-2].coeff
                else:
                    if accumulation >= range.km_min and  accumulation <= range.km_max :
                        if last_accumulation == 0 :
                            coeff = range.coeff
                            fixed = range.fixed
                        else:
                            coeff = range.coeff

                        if last_accumulation < range.km_min :
                            two_expense = True
                            km_up = accumulation - range.km_min
                            km_down = current_trip -km_up
                            coeff_bis = km_ranges[i-3].coeff
                i+=1

        if two_expense:
            values = {}
            values_bis = {}
            values.update({
                'name' : self.reason,
                'unit_amount': coeff,
                'fiscal_horsepower': horsepower_id,
                'quantity': km_down,
                'is_mileage': True,
                'employee_id':employee_id ,
                'product_id':product_id,
                'fixed': fixed,
                'date':current_date})

            values_bis.update({
                'name' : self.reason,
                'unit_amount': coeff_bis,
                'fiscal_horsepower': horsepower_id,
                'quantity': km_up,
                'is_mileage': True,
                'employee_id':employee_id ,
                'product_id':product_id,
                'fixed': fixed_bis,
                'date':current_date
            })
            return (values, values_bis, two_expense)

        else:
            values = {}
            values.update({
                'name' : self.reason,
                'unit_amount': coeff,
                'fiscal_horsepower': horsepower_id,
                'quantity': current_trip,
                'is_mileage': True,
                'employee_id':employee_id ,
                'product_id':product_id,
                'fixed': fixed,
                'date':current_date})
            return (values

Xml:

<?xml version="1.0" encoding="utf-8"?>
<odoo>

  <record id="hr_expense_mileage_wizard_form" model="ir.ui.view">
    <field name="name">Input your mileage compensation</field>
    <field name="model">hr.expense.mileage.wizard</field>
    <field name="priority">1</field>
    <field name="type">form</field>
    <field name="arch" type="xml">
      <form string="Mileage Compensation">
        <sheet>
          <group>
            <group colspan="4" col="4">
              <field name="date" required="1"/>
              <field name="reason" required="1"/>
            </group>
            <field name="employee_id" groups="rp_base.group_rp_staff"/>
            <group colspan="4" col="4">
              <field name="vehicle" class="oe_inline" required="1" context="{'employee_id': active_id}" domain="[('hr_employee_id', '=', employee_id)]">
                <tree name="tree personnel vehicle">
                  <field name="name"/>
                  <field name="vehicle_type"/>
                  <field name="horsepower_id">
                    <field name="range_ids">
                      <field name="fisc_hp_id"/>
                    </field>
                  </field>
                </tree>
              </field>
              <label for="distance"/>
              <div>
                <field name="distance" required="1" class="oe_inline"/> Km
              </div>
            </group>
            <p class="text-muted" colspan="2">
              <i>Make sure your vehicle informations are saved.</i>
            </p>
          </group>
        </sheet>
        <footer>
          <button string="Validate" class="oe_highlight" type="object" name="submit_mileage"/>
          <button string="Cancel" special="cancel"/>
        </footer>
      </form>
    </field>
  </record>

  <record id="change_expense_sheet_action" model="ir.actions.act_window">
    <field name="name">Input your mileage compensation</field>
    <field name="type">ir.actions.act_window</field>
    <field name="res_model">hr.expense.mileage.wizard</field>
    <field name="view_type">form</field>
    <field name="view_id" ref="hr_expense_mileage.hr_expense_mileage_wizard_form"/>
    <field name="view_mode">form</field>
    <field name="target">new</field>
  </record>

  <record model="ir.ui.view" id="vehicle_search_view">
           <field name="name">vehicle.search</field>
           <field name="model">hr.expense.mileage.wizard</field>
           <field name="arch" type="xml">
               <search string="Choose your vehicle">
                 <field name="vehicle" >
                     <field name="name"/>
                     <field name="horsepower_id">
                       <field name="range_ids">
                         <field name="fisc_hp_id"/>
                       </field>
                     </field>
                 </field>
               </search>
           </field>
       </record>

</odoo>



Error: NameError: name 'employee_id' is not defined
http://localhost:8021/web/content/19292-4c785c0/web.assets_backend.js:1326
Retraçage :
PY_ensurepy@http://localhost:8021/web/content/19292-4c785c0/web.assets_backend.js:1326:65
py.evaluate@http://localhost:8021/web/content/19292-4c785c0/web.assets_backend.js:1441:8
py.evaluate@http://localhost:8021/web/content/19292-4c785c0/web.assets_backend.js:1450:191
py.eval@http://localhost:8021/web/content/19292-4c785c0/web.assets_backend.js:1454:281
eval_contexts/<@http://localhost:8021/web/content/19292-4c785c0/web.assets_backend.js:1593:107
iterator@http://localhost:8021/web/content/19275-ef5d375/web.assets_common.js:14:183
createReduce/<@http://localhost:8021/web/content/19275-ef5d375/web.assets_common.js:17:8
_.mixin/</_.prototype[name]@http://localhost:8021/web/content/19275-ef5d375/web.assets_common.js:69:521
eval_contexts@http://localhost:8021/web/content/19292-4c785c0/web.assets_backend.js:1591:124
eval_contexts/<@http://localhost:8021/web/content/19292-4c785c0/web.assets_backend.js:1593:253
iterator@http://localhost:8021/web/content/19275-ef5d375/web.assets_common.js:14:183
createReduce/<@http://localhost:8021/web/content/19275-ef5d375/web.assets_common.js:17:8
_.mixin/</_.prototype[name]@http://localhost:8021/web/content/19275-ef5d375/web.assets_common.js:69:521
eval_contexts@http://localhost:8021/web/content/19292-4c785c0/web.assets_backend.js:1591:124
pyeval@http://localhost:8021/web/content/19292-4c785c0/web.assets_backend.js:1608:24
do_action@http://localhost:8021/web/content/19292-4c785c0/web.assets_backend.js:1655:213
do_action@http://localhost:8021/web/content/19292-4c785c0/web.assets_backend.js:1716:4405
do_action@http://localhost:8021/web/content/19292-4c785c0/web.assets_backend.js:1724:414
OdooClass.extend/</prototype[name]</<@http://localhost:8021/web/content/19275-ef5d375/web.assets_common.js:3010:556
on_menu_clicked/</<@http://localhost:8021/web/content/19292-4c785c0/web.assets_backend.js:1728:904
Mutex.prototype.exec/<@http://localhost:8021/web/content/19275-ef5d375/web.assets_common.js:3202:136
then/</</<@http://localhost:8021/web/content/19275-ef5d375/web.assets_common.js:547:678
fire@http://localhost:8021/web/content/19275-ef5d375/web.assets_common.js:541:281
add@http://localhost:8021/web/content/19275-ef5d375/web.assets_common.js:542:467
then/</<@http://localhost:8021/web/content/19275-ef5d375/web.assets_common.js:547:631
each@http://localhost:8021/web/content/19275-ef5d375/web.assets_common.js:370:758
then/<@http://localhost:8021/web/content/19275-ef5d375/web.assets_common.js:547:553
Deferred@http://localhost:8021/web/content/19275-ef5d375/web.assets_common.js:548:189
then@http://localhost:8021/web/content/19275-ef5d375/web.assets_common.js:547:518
Mutex.prototype.exec@http://localhost:8021/web/content/19275-ef5d375/web.assets_common.js:3202:98
on_menu_clicked/<@http://localhost:8021/web/content/19292-4c785c0/web.assets_backend.js:1728:836
then/</</<@http://localhost:8021/web/content/19275-ef5d375/web.assets_common.js:547:678
fire@http://localhost:8021/web/content/19275-ef5d375/web.assets_common.js:541:281
fireWith@http://localhost:8021/web/content/19275-ef5d375/web.assets_common.js:546:198
Deferred/</deferred[tuple[0]]@http://localhost:8021/web/content/19275-ef5d375/web.assets_common.js:548:31
add/<@http://localhost:8021/web/content/19275-ef5d375/web.assets_common.js:3218:259
fire@http://localhost:8021/web/content/19275-ef5d375/web.assets_common.js:541:281
fireWith@http://localhost:8021/web/content/19275-ef5d375/web.assets_common.js:546:198
then/</</<@http://localhost:8021/web/content/19275-ef5d375/web.assets_common.js:547:849
fire@http://localhost:8021/web/content/19275-ef5d375/web.assets_common.js:541:281
fireWith@http://localhost:8021/web/content/19275-ef5d375/web.assets_common.js:546:198
then/</</<@http://localhost:8021/web/content/19275-ef5d375/web.assets_common.js:547:849
fire@http://localhost:8021/web/content/19275-ef5d375/web.assets_common.js:541:281
fireWith@http://localhost:8021/web/content/19275-ef5d375/web.assets_common.js:546:198
Deferred/</deferred[tuple[0]]@http://localhost:8021/web/content/19275-ef5d375/web.assets_common.js:548:31
fire@http://localhost:8021/web/content/19275-ef5d375/web.assets_common.js:541:281
fireWith@http://localhost:8021/web/content/19275-ef5d375/web.assets_common.js:546:198
then/</</<@http://localhost:8021/web/content/19275-ef5d375/web.assets_common.js:547:849
fire@http://localhost:8021/web/content/19275-ef5d375/web.assets_common.js:541:281
fireWith@http://localhost:8021/web/content/19275-ef5d375/web.assets_common.js:546:198
then/</</<@http://localhost:8021/web/content/19275-ef5d375/web.assets_common.js:547:849
fire@http://localhost:8021/web/content/19275-ef5d375/web.assets_common.js:541:281
fireWith@http://localhost:8021/web/content/19275-ef5d375/web.assets_common.js:546:198
done@http://localhost:8021/web/content/19275-ef5d375/web.assets_common.js:937:86
callback@http://localhost:8021/web/content/19275-ef5d375/web.assets_common.js:957:15

Avatar
Discard

Please add your Python code, how you import it etc. Without this we can't see what is (possible) wrong.

Hello karim bryant,

Can you share your code.

Author

When I change my computer, I do not have an error...

Author Best Answer

My first error is in admin mode (superuser) and when I change in user i have a other error...

(On other computer my code works...)

Tanks for your explanations.

 File "/home/ubuntu/dev21/odoo/odoo/http.py", line 638, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/home/ubuntu/dev21/odoo/odoo/http.py", line 675, in dispatch
result = self._call_function(**self.params)
File "/home/ubuntu/dev21/odoo/odoo/http.py", line 331, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/home/ubuntu/dev21/odoo/odoo/service/model.py", line 101, in wrapper
return f(dbname, *args, **kwargs)
File "/home/ubuntu/dev21/odoo/odoo/http.py", line 324, in checked_call
result = self.endpoint(*a, **kw)
File "/home/ubuntu/dev21/odoo/odoo/http.py", line 933, in __call__
return self.method(*args, **kw)
File "/home/ubuntu/dev21/odoo/odoo/http.py", line 504, in response_wrap
response = f(*args, **kw)
File "/home/ubuntu/dev21/odoo/addons/web/controllers/main.py", line 885, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/home/ubuntu/dev21/odoo/addons/web/controllers/main.py", line 877, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/home/ubuntu/dev21/odoo/odoo/api.py", line 679, in call_kw
return call_kw_model(method, model, args, kwargs)
File "/home/ubuntu/dev21/odoo/odoo/api.py", line 664, in call_kw_model
result = method(recs, *args, **kwargs)
File "/home/ubuntu/dev21/odoo/odoo/models.py", line 1932, in read_group
result = self._read_group_raw(domain, fields, groupby, offset=offset, limit=limit, orderby=orderby, lazy=lazy)
File "/home/ubuntu/dev21/odoo/odoo/models.py", line 1965, in _read_group_raw
self._apply_ir_rules(query, 'read')
File "/home/ubuntu/dev21/odoo/odoo/models.py", line 4075, in _apply_ir_rules
where_clause, where_params, tables = Rule.domain_get(self._name, mode)
File "/home/ubuntu/dev21/odoo/odoo/addons/base/ir/ir_rule.py", line 124, in domain_get
dom = self._compute_domain(model_name, mode)
File "<decorator-gen-54>", line 2, in _compute_domain
File "/home/ubuntu/dev21/odoo/odoo/tools/cache.py", line 87, in lookup
value = d[key] = self.method(*args, **kwargs)
File "/home/ubuntu/dev21/odoo/odoo/addons/base/ir/ir_rule.py", line 96, in _compute_domain
rule_domain = {vals['id']: vals['domain'] for vals in rules.read(['domain'])}
File "/home/ubuntu/dev21/odoo/odoo/models.py", line 3021, in read
values[name] = field.convert_to_read(record[name], record, use_name_get)
File "/home/ubuntu/dev21/odoo/odoo/models.py", line 5211, in __getitem__
return self._fields[key].__get__(self, type(self))
File "/home/ubuntu/dev21/odoo/odoo/fields.py", line 870, in __get__
self.determine_value(record)
File "/home/ubuntu/dev21/odoo/odoo/fields.py", line 981, in determine_value
self.compute_value(recs)
File "/home/ubuntu/dev21/odoo/odoo/fields.py", line 936, in compute_value
self._compute_value(records)
File "/home/ubuntu/dev21/odoo/odoo/fields.py", line 927, in _compute_value
getattr(records, self.compute)()
File "/home/ubuntu/dev21/odoo/odoo/addons/base/ir/ir_rule.py", line 53, in _force_domain
rule.domain = expression.normalize_domain(safe_eval(rule.domain_force, eval_context))
File "/home/ubuntu/dev21/odoo/odoo/tools/safe_eval.py", line 301, in safe_eval
return unsafe_eval(c, globals_dict, locals_dict)
File "", line 1, in <module>
ValueError: <type 'exceptions.NameError'>: "name 'uid' is not defined" while evaluating
u"[('employee_id.user_id', '=', uid)]"

Avatar
Discard
Author

this it's fixe. It's because I have a folder linked in my trash. I remove it and it's works.

Related Posts Replies Views Activity
2
Nov 24
25067
2
May 24
5513
3
Mar 24
4962
0
Mar 24
261
3
Feb 24
11415