#
##############################################################################
-import addons
+from openerp import addons
import logging
-from osv import fields, osv
-import tools
+from openerp.osv import fields, osv
+from openerp import tools
_logger = logging.getLogger(__name__)
class hr_employee_category(osv.osv):
return True
_constraints = [
- (_check_recursion, 'Error ! You cannot create recursive Categories.', ['parent_id'])
+ (_check_recursion, 'Error! You cannot create recursive Categories.', ['parent_id'])
]
hr_employee_category()
_name = "hr.job"
_description = "Job Description"
+ _inherit = ['mail.thread']
_columns = {
'name': fields.char('Job Name', size=128, required=True, select=True),
- 'expected_employees': fields.function(_no_of_employee, string='Total Employees',
+ 'expected_employees': fields.function(_no_of_employee, string='Total Forecasted Employees',
help='Expected number of employees for this job position after new recruitment.',
store = {
'hr.job': (lambda self,cr,uid,ids,c=None: ids, ['no_of_recruitment'], 10),
'hr.employee': (_get_job_position, ['job_id'], 10),
},
multi='no_of_employee'),
- 'no_of_employee': fields.function(_no_of_employee, string="Number of Employees",
+ 'no_of_employee': fields.function(_no_of_employee, string="Current Number of Employees",
help='Number of employees currently occupying this job position.',
store = {
'hr.employee': (_get_job_position, ['job_id'], 10),
'requirements': fields.text('Requirements'),
'department_id': fields.many2one('hr.department', 'Department'),
'company_id': fields.many2one('res.company', 'Company'),
- 'state': fields.selection([('open', 'In Position'), ('recruit', 'In Recruitement')], 'Status', readonly=True, required=True,
+ 'state': fields.selection([('open', 'No Recruitment'), ('recruit', 'Recruitement in Progress')], 'Status', readonly=True, required=True,
help="By default 'In position', set it to 'In Recruitment' if recruitment process is going on for this job position."),
}
_defaults = {
- 'expected_employees': 1,
'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'hr.job', context=c),
'state': 'open',
}
def _get_image(self, cr, uid, ids, name, args, context=None):
result = dict.fromkeys(ids, False)
for obj in self.browse(cr, uid, ids, context=context):
- resized_image_dict = tools.get_resized_images(obj.image)
- result[obj.id] = {
- 'image_medium': resized_image_dict['image_medium'],
- 'image_small': resized_image_dict['image_small'],
- }
+ result[obj.id] = tools.image_get_resized_images(obj.image)
return result
def _set_image(self, cr, uid, id, name, value, args, context=None):
- return self.write(cr, uid, [id], {'image': tools.resize_image_big(value)}, context=context)
-
- def onchange_image(self, cr, uid, ids, value, context=None):
- return {'value': tools.get_resized_images(value)}
+ return self.write(cr, uid, [id], {'image': tools.image_resize_image_big(value)}, context=context)
_columns = {
+ #we need a related field in order to be able to sort the employee by name
+ 'name_related': fields.related('resource_id', 'name', type='char', string='Name', readonly=True, store=True),
'country_id': fields.many2one('res.country', 'Nationality'),
'birthday': fields.date("Date of Birth"),
'ssnid': fields.char('SSN No', size=32, help='Social Security Number'),
'work_location': fields.char('Office Location', size=32),
'notes': fields.text('Notes'),
'parent_id': fields.many2one('hr.employee', 'Manager'),
- 'category_ids': fields.many2many('hr.employee.category', 'employee_category_rel', 'emp_id', 'category_id', 'Categories'),
+ 'category_ids': fields.many2many('hr.employee.category', 'employee_category_rel', 'emp_id', 'category_id', 'Tags'),
'child_ids': fields.one2many('hr.employee', 'parent_id', 'Subordinates'),
'resource_id': fields.many2one('resource.resource', 'Resource', ondelete='cascade', required=True),
'coach_id': fields.many2one('hr.employee', 'Coach'),
'job_id': fields.many2one('hr.job', 'Job'),
+ # image: all image fields are base64 encoded and PIL-supported
'image': fields.binary("Photo",
- help="This field holds the image used as a photo for the "\
- "employee. The image is base64 encoded, and PIL-supported. "\
- "It is limited to a 12024x1024 px image."),
+ help="This field holds the image used as photo for the employee, limited to 1024x1024px."),
'image_medium': fields.function(_get_image, fnct_inv=_set_image,
string="Medium-sized photo", type="binary", multi="_get_image",
store = {
'hr.employee': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10),
},
help="Medium-sized photo of the employee. It is automatically "\
- "resized as a 180x180px image, with aspect ratio kept. "\
+ "resized as a 128x128px image, with aspect ratio preserved. "\
"Use this field in form views or some kanban views."),
'image_small': fields.function(_get_image, fnct_inv=_set_image,
string="Smal-sized photo", type="binary", multi="_get_image",
'hr.employee': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10),
},
help="Small-sized photo of the employee. It is automatically "\
- "resized as a 50x50px image, with aspect ratio keps. "\
+ "resized as a 64x64px image, with aspect ratio preserved. "\
"Use this field anywhere a small image is required."),
- 'active': fields.boolean('Active'),
'passport_id':fields.char('Passport No', size=64),
'color': fields.integer('Color Index'),
'city': fields.related('address_id', 'city', type='char', string='City'),
'last_login': fields.related('user_id', 'date', type='datetime', string='Latest Connection', readonly=1),
}
+ _order='name_related'
+
+ def create(self, cr, uid, data, context=None):
+ employee_id = super(hr_employee, self).create(cr, uid, data, context=context)
+ try:
+ (model, mail_group_id) = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'mail', 'group_all_employees')
+ employee = self.browse(cr, uid, employee_id, context=context)
+ self.pool.get('mail.group').message_post(cr, uid, [mail_group_id],
+ body='Welcome to %s! Please help them take the first steps with OpenERP!' % (employee.name),
+ subtype='mail.mt_comment', context=context)
+ except:
+ pass # group deleted: do not push a message
+ return employee_id
+
def unlink(self, cr, uid, ids, context=None):
- resource_obj = self.pool.get('resource.resource')
resource_ids = []
for employee in self.browse(cr, uid, ids, context=context):
- resource = employee.resource_id
- if resource:
- resource_ids.append(resource.id)
- if resource_ids:
- resource_obj.unlink(cr, uid, resource_ids, context=context)
- return super(hr_employee, self).unlink(cr, uid, ids, context=context)
+ resource_ids.append(employee.resource_id.id)
+ return self.pool.get('resource.resource').unlink(cr, uid, resource_ids, context=context)
def onchange_address_id(self, cr, uid, ids, address, context=None):
if address:
address = self.pool.get('res.partner').browse(cr, uid, address, context=context)
- return {'value': {'work_email': address.email, 'work_phone': address.phone, 'mobile_phone': address.mobile}}
+ return {'value': {'work_phone': address.phone, 'mobile_phone': address.mobile}}
return {'value': {}}
def onchange_company(self, cr, uid, ids, company, context=None):
def onchange_user(self, cr, uid, ids, user_id, context=None):
work_email = False
if user_id:
- work_email = self.pool.get('res.users').browse(cr, uid, user_id, context=context).user_email
+ work_email = self.pool.get('res.users').browse(cr, uid, user_id, context=context).email
return {'value': {'work_email' : work_email}}
- def _get_photo(self, cr, uid, context=None):
- image_path = addons.get_module_resource('hr', 'images', 'photo.png')
- return tools.resize_image_big(open(image_path, 'rb').read().encode('base64'))
+ def _get_default_image(self, cr, uid, context=None):
+ image_path = addons.get_module_resource('hr', 'static/src/img', 'default_image.png')
+ return tools.image_resize_image_big(open(image_path, 'rb').read().encode('base64'))
_defaults = {
'active': 1,
- 'image': _get_photo,
- 'marital': 'single',
+ 'image': _get_default_image,
'color': 0,
}
return True
_constraints = [
- (_check_recursion, 'Error ! You cannot create recursive Hierarchy of Employees.', ['parent_id']),
+ (_check_recursion, 'Error! You cannot create recursive hierarchy of Employee(s).', ['parent_id']),
]
hr_employee()
'member_ids': fields.one2many('hr.employee', 'department_id', 'Members', readonly=True),
}
-hr_department()
-
+ def copy(self, cr, uid, ids, default=None, context=None):
+ if default is None:
+ default = {}
+ default = default.copy()
+ default['member_ids'] = []
+ return super(hr_department, self).copy(cr, uid, ids, default, context=context)
class res_users(osv.osv):
_name = 'res.users'
'user_id': user_id}, context=context)
except:
# Tolerate a missing shortcut. See product/product.py for similar code.
- _logger.debug('Skipped meetings shortcut for user "%s"', data.get('name','<new'))
+ _logger.debug('Skipped meetings shortcut for user "%s".', data.get('name','<new'))
return user_id
+ _columns = {
+ 'employee_ids': fields.one2many('hr.employee', 'user_id', 'Related employees'),
+ }
+
res_users()