Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Odoo client error

By
chainika
on 3/17/16, 3:36 AM 296 views

i made some custom fields in HR Module.

it is properly working in terms of functionality but when i open a employee form then a odoo client occur.

Please suggest.

Error: Field 'undefined' specified in view could not be found.
http://localhost:8069/web/static/src/js/view_form.js:1254

can you post your code ?

Jignesh Mehta
on 3/17/16, 4:10 AM
0
chainika
On 3/17/16, 5:16 AM

from openerp.osv import fields, osv

import time

from openerp.tools import DEFAULT_SERVER_DATE_FORMAT,DEFAULT_SERVER_DATETIME_FORMAT

import re

import base64, urllib

import os

import math

from openerp.tools.translate import _

class emp_year(osv.osv):

_name="emp.year"

def _check_year(self, cr, uid, ids, context=None):

str="^-?[0-9]+$"

obj=self.browse(cr, uid, ids)[0]

ph=obj.name

if ph and len(ph)!= 4:

raise osv.except_osv(_('Invalid Year'), _(' Year must contain 4 digits only.'))

if ph and re.match(str, ph) == None:

return False

return True

_columns = {

'name' :fields.char('Name',size=4, select=True),

}

_constraints = [

(_check_year, 'Must contain only integer values', [' Year ']),

]

_sql_constraints=[('unique_year','unique(name)','Year must be unique !')]

class qualification_list(osv.osv):

_name="qualification.list"

_columns = {

'name':fields.char('Name',size=64,select=True),

}

class qualification(osv.osv):

_name="qualification"

_columns = {

'name':fields.many2one('qualification.list','Qualification',select=True),

'college' :fields.char('College Name', size=64,select=True),

'employee_id':fields.many2one('hr.employee','Employee',select=True),

'year':fields.many2one('emp.year','Year'),

}

class experience(osv.osv):

_name="experience"

_columns = {

'name' :fields.char('Company Name', size=64,select=True),

'address' :fields.char('Company Address', size=512,select=True),

'employee_id':fields.many2one('hr.employee','Employee',select=True),

'year1':fields.many2one('emp.year','From Year'),

'year2':fields.many2one('emp.year','To Year'),

}

class salary(osv.osv):

_name="salary"

def onchange_food_amt(self,cr,uid,ids,basic,hra,convenience,medical,food_amt,context=None):

result={}

if context:

gross = basic + hra + convenience + medical + food_amt

result['value'] ={'gross':gross}

return result

def onchange_basic(self,cr,uid,ids,basic,hra,convenience,medical,context=None):

result={}

if context:

gross = basic + hra + convenience + medical

result['value'] = {'gross':gross}

return result

def onchange_hra(self,cr,uid,ids,basic,hra,convenience,medical,context=None):

result={}

if context:

gross = basic + hra + convenience + medical

result['value'] = {'gross':gross}

return result

def onchange_convenience(self,cr,uid,ids,basic,hra,convenience,medical,context=None):

result={}

if context:

gross = basic + hra + convenience + medical

result['value'] = {'gross':gross}

return result

def onchange_medical(self,cr,uid,ids,basic,hra,convenience,medical,context=None):

result={}

if context:

gross = basic + hra + convenience + medical

result['value'] = {'gross':gross}

return result

def onchange_esi(self,cr,uid,ids,basic,hra,convenience,esi,context=None):

result={}

if context:

amt = basic+hra+convenience

esi_amt = (amt * esi)/100

print"esi_amt",esi_amt

result['value'] = {'esi_amt':math.ceil(esi_amt)}

return result

def onchange_epf(self,cr,uid,ids,basic,epf,context=None):

result={}

if context:

epf_amt = (basic * epf)/100

result['value'] = {'epf_amt':math.ceil(epf_amt)}

return result

def onchange_esi_com(self,cr,uid,ids,basic,hra,convenience,esi_com,gross,context=None):

result={}

if context:

esi_amt_comp = ((basic+hra+convenience) * esi_com)/100

ctc = gross + esi_amt_comp

result['value'] = {'esi_amt_comp':math.ceil(esi_amt_comp), 'ctc':ctc}

return result

def onchange_epf_com(self,cr,uid,ids,basic,epf_com,context=None):

result={}

if context:

epf_amt_comp = (basic * epf_com)/100

result['value'] = {'epf_amt_comp':math.ceil(epf_amt_comp)}

return result

_columns = {

'select':fields.boolean('Select'),

'basic':fields.float('Basic'),

'hra':fields.float('HRA'),

'convenience':fields.float('Conveyance'),

'medical':fields.float('Medical'),

'esi':fields.float(' Employee ESI(%)'),

'esi_com':fields.float('Company ESI(%)'),

'epf_com':fields.float('Company EPF(%)'),

'esi_amt_comp':fields.float('Comapny ESI Amount', readonly=True),

'epf_amt_comp':fields.float('Company EPF Amount',readonly=True),

'esi_amt':fields.float(' Employee ESI Amount',readonly=True),

'epf':fields.float('Emoployee EPF(%)'),

'epf_amt':fields.float(' Employee EPF Amount',readonly=True),

'gross':fields.float('Gross'),

'ctc':fields.float('CTC'),

'food_tick':fields.boolean('Food'),

'other_tick':fields.boolean('Other Expenses'),

'other_amt':fields.float('Other Expenses Amount'),

'food_amt':fields.float('Food Amount'),

'employee_id':fields.many2one('hr.employee','Employee',select=True)

}

class skill(osv.osv):

_name="skill"

_columns = {

'name' :fields.char('Name', size=255,select=True),

'note':fields.text('Description '),

}

class hr_department(osv.osv):

_inherit = "hr.department"

def onchange_manager(self, cr, uid, ids, manager_id,context=None):

result={}

arg=[]

if manager_id:

manager = self.pool.get('hr.employee').browse(cr, uid, manager_id, context=context)

if manager:

result = {'value': {'manager_name': manager.name }}

return result

_columns = {

'department_code':fields.char('Department Code',size=64),

'manager_name':fields.char('Manager Name',size=256),

'manager_id': fields.many2one('hr.employee', 'Manager'),

}

def create(self, cr, uid, vals, context=None):

seq = self.pool.get('ir.sequence').get(cr, uid, 'hr.department')

print"seqqq",seq

vals['department_code'] = seq

print"vallll",vals

res = super(hr_department,self).create(cr, uid, vals, context)

print"resss",res

return res

class hr_employee(osv.osv):

_inherit = "hr.employee"

_order = 'emp_id'

def onchange_food_tick(self,cr,uid,ids,food_tick,context=None):

result={}

if context:

if context.get('food_tick') == True:

gross = gross + food_amt

result['value'] ={'gross':gross}

return result

def get_image(self, cr, uid, ids):

each = self.read(cr, uid, ids, ['image_url'])

try:

if each['image_url']:

(filename, header) = urllib.urlretrieve('file://'+os.getcwd()+'/Photo/Employee/'+each['image_url'])

f = open(filename , 'rb')

img = base64.encodestring(f.read())

f.close()

else:

(filename, header) = urllib.urlretrieve('file://'+os.getcwd()+'/addons/hr_employee/images/default.png')

f = open(filename , 'rb')

img = base64.encodestring(f.read())

f.close()

except:

(filename, header) = urllib.urlretrieve('file://'+os.getcwd()+'/addons/hr_employee/images/default.png')

f = open(filename , 'rb')

img = base64.encodestring(f.read())

f.close()

return img

def _get_image(self, cr, uid, ids, field_name, arg, context={}):

res = {}

for each in ids:

img = self.get_image(cr, uid, each)

res[each] = img

return res

def resize_image(self, cr, uid, ids, context=None):

for each in self.browse(cr, uid, self.search(cr, uid, [])):

img = self.get_image(cr, uid, each)

image_url = each.image_url

import io, StringIO, Image

image_stream = io.BytesIO(img.decode('base64'))

img = Image.open(image_stream)

img.thumbnail((240, 200), Image.ANTIALIAS)

img_stream = StringIO.StringIO()

img.save(img_stream, "JPEG")

bin = base64.decodestring(img_stream.getvalue().encode('base64'))

filename = str(os.getcwd()+'/Photo/Employee/'+image_url)

f = open(filename , 'wb')

f.write(bin)

return True

_columns={

'jdate':fields.date('Joining Date'),

'local_address':fields.char('Local Address'),

'permanent_address':fields.char('Permanent Address'),

'category1':fields.selection([('worker','WORKER'),('other','OTHER'),('office_staff','OFFICE STAFF')],'Employee Type'),

'category2':fields.selection([('semi','Semi Skilled'),('skill','Skilled'),('super','Super Skilled'),('nskill','Non Skill')],'Employee Skill'),

'father_name':fields.char('Father Name',size=64),

'emp_id':fields.char('Employee ID',readonly=True),

'shift_lines':fields.one2many('hr.shift.line','employee_id','Master Shift'),

'shift_id':fields.many2one('attendance.shift','Shift',ondaelete="cascade"),

'image_medium':fields.function(_get_image, type="binary", method=True),

'image_url':fields.char('Image URL' , size=256, help="Specify complete path to image when, you are importing images from CSV file. example for local system path=file:///home/directoryname/imagedirectoryname/image.jpg",readonly=True),

'education_id':fields.one2many('qualification','employee_id','Degree/Diploma'),

'experience_id':fields.one2many('experience','employee_id','Experience'),

'salary_lines':fields.one2many('salary','employee_id','Salary'),

'skill_id':fields.many2many('skill','emp_skill_rel','skill_id','name','Skills'),

'daily':fields.boolean('Daily'),

'monthly':fields.boolean('Monthly'),

'new_salary':fields.float('Joining Salary'),

'salary':fields.float('Current Salary'),

'parent_id':fields.many2one('hr.employee','Reporting Officer'),

'job_id':fields.many2one('hr.job','Designation'),

'work_phone': fields.char('Work Phone'),

'emp_status':fields.selection([('working','Working'),('left','Left')],'Employee Status'),

'mobile_phone': fields.char('Work Mobile'),

'work_location': fields.char('Office Location'),

'address_id': fields.many2one('res.partner', 'Working Address'),

'card_no':fields.char('Employee Machine No'),

'nominee_name':fields.char('Nominee Name', size=64),

'nominee_rel':fields.char('Nominee Relation', size=64),

'bank_name':fields.char('Bank Name', size=64),

'account_number':fields.char('Bank Account Number', size=64),

'ifsc_code':fields.char('IFSC Code', size=64),

'leave_date':fields.date('Leaving Date'),

'ot_tick':fields.boolean('OT'),

'select_salary':fields.boolean('Select'),

}

def create(self, cr, uid, vals, context=None):

if 'category1' in vals and vals['category1']:

if vals['category1'] == 'office_staff':

seq = self.pool.get('ir.sequence').get(cr, uid, 'hr.employee.staff')

vals['emp_id'] = seq

if vals['category1'] in ('worker'):

seq = self.pool.get('ir.sequence').get(cr, uid, 'hr.employee.worker')

vals['emp_id'] = seq

if vals['category1'] == 'other':

seq = self.pool.get('ir.sequence').get(cr, uid, 'hr.employee.other')

vals['emp_id'] = seq

res = super(hr_employee,self).create(cr, uid, vals, context)

return res

class wiz_image_hr(osv.TransientModel):

_name = 'wiz.image.hr'

_columns = {

'image':fields.binary('Image'),

'image_name':fields.char('Image Name',size=64,required=True,readonly=True),

}

def default_get(self, cr, uid, fields, context=None):

if not context:

context = {}

ids = context.get('active_ids',[])

res = super(wiz_image_hr, self).default_get(cr, uid, fields, context=context)

for line in self.pool.get('hr.employee').browse(cr, uid, ids):

if 'image_name' in fields:

res.update({'image_name':line.emp_id+'.jpg'})

return res

def clear_image(self, cr, uid, ids, context=None):

if not context:

context = {}

hr_ids = context.get('active_ids',[])

model = context.get('active_model')

if model == None:

return {'type':'ir.actions.act_window_close'}

try:

self.pool.get('hr.employee').write(cr, uid, hr_ids, {'image_url':False})

except:

pass

return {'type':'ir.actions.act_window_close'}

def create_image(self, cr, uid, ids, context=None):

if not context:

context = {}

hr_ids = context.get('active_ids',[])

each = self.read(cr, uid, ids, ['image_name','image'])

if each[0]['image_name'] and not each[0]['image']:

raise osv.except_osv(_('UserError'), _('Please select the image..'))

try:

if each[0]['image_name'] and each[0]['image']:

import io, StringIO, Image

image_stream = io.BytesIO(each[0]['image'].decode('base64'))

img = Image.open(image_stream)

img.thumbnail((240, 200), Image.ANTIALIAS)

img_stream = StringIO.StringIO()

img.save(img_stream, "JPEG")

bin = base64.decodestring(img_stream.getvalue().encode('base64'))

filename = str(os.getcwd()+'/Photo/Employee/'+each[0]['image_name'])

f = open(filename , 'wb')

f.write(bin)

self.pool.get('hr.employee').write(cr, uid, hr_ids, {'image_url':each[0]['image_name']})

except:

pass

return {'type':'ir.actions.act_window_close'}


hello, error in your custom xml file.

Jignesh Mehta
on 3/17/16, 7:34 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 3/17/16, 3:36 AM
Seen: 296 times
Last updated: 3/17/16, 5:16 AM