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>
Odoo Erreur (côté interface)
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
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.
When I change my computer, I do not have an error...