def get_by_record(self, cr, uid, record, context=None): if record.type in ('char', 'text', 'selection'): return record.value_text elif record.type == 'float': return record.value_float elif record.type == 'boolean': return bool(record.value_integer) elif record.type == 'integer': return record.value_integer elif record.type == 'binary': return record.value_binary elif record.type == 'many2one': if not record.value_reference: return browse_null() model, resource_id = record.value_reference.split(',') return self.pool.get(model).browse(cr, uid, int(resource_id), context=context) elif record.type == 'datetime': return record.value_datetime elif record.type == 'date': if not record.value_datetime: return False return time.strftime( '%Y-%m-%d', time.strptime(record.value_datetime, '%Y-%m-%d %H:%M:%S')) return False
def get_reference_calendar(self, cr, uid, employee_id, date=None, context=None): if date is None: date = fields.date.context_today(self, cr, uid, context=context) contract_pool = self.pool.get('hr.contract') active_contract_ids = contract_pool.search( cr, uid, [ '&', ('employee_id', '=', employee_id), '|', '&', ('date_start', '<=', date), '|', ('date_end', '>=', date), ('date_end', '=', False), '&', '&', ('trial_date_start', '!=', False), ('trial_date_start', '<=', date), '&', ('trial_date_end', '!=', False), ('trial_date_end', '>=', date), ], context=context) if len(active_contract_ids) > 1: lang_pool = self.pool['res.lang'] lang_id = lang_pool.search(cr, uid, [('code', '=', context.get('lang'))], context=context) lang_data = lang_pool.read(cr, uid, lang_id, ['date_format'], context=context) if lang_data: date_format = lang_data[0]['date_format'] else: date_format = DEFAULT_SERVER_DATE_FORMAT employee = self.pool.get('hr.employee').browse(cr, uid, employee_id, context=context) msg = _('Too many active contracts for employee %s at date %s') raise orm.except_orm( _('Error'), msg % (employee.name, datetime.strftime(date, date_format))) elif active_contract_ids: contract = contract_pool.browse(cr, uid, active_contract_ids[0], context=context) return contract.working_hours else: return orm.browse_null()
def get_reference_calendar( self, cr, uid, employee_id, date=None, context=None ): if date is None: date = fields.date.context_today(self, cr, uid, context=context) contract_pool = self.pool.get('hr.contract') active_contract_ids = contract_pool.search(cr, uid, [ '&', ('employee_id', '=', employee_id), '|', '&', ('date_start', '<=', date), '|', ('date_end', '>=', date), ('date_end', '=', False), '&', '&', ('trial_date_start', '!=', False), ('trial_date_start', '<=', date), '&', ('trial_date_end', '!=', False), ('trial_date_end', '>=', date), ], context=context) if len(active_contract_ids) > 1: lang_pool = self.pool['res.lang'] lang_id = lang_pool.search( cr, uid, [('code', '=', context.get('lang'))], context=context ) lang_data = lang_pool.read( cr, uid, lang_id, ['date_format'], context=context ) if lang_data: date_format = lang_data[0]['date_format'] else: date_format = DEFAULT_SERVER_DATE_FORMAT employee = self.pool.get('hr.employee').browse( cr, uid, employee_id, context=context) msg = _('Too many active contracts for employee %s at date %s') raise orm.except_orm( _('Error'), msg % (employee.name, datetime.strftime(date, date_format))) elif active_contract_ids: contract = contract_pool.browse( cr, uid, active_contract_ids[0], context=context) return contract.working_hours else: return orm.browse_null()
def get_reference_calendar(self, cr, uid, employee_id, date=None, context=None): if date is None: date = fields.date.context_today(self, cr, uid, context=context) contract_pool = self.pool.get("hr.contract") active_contract_ids = contract_pool.search( cr, uid, [ "&", ("employee_id", "=", employee_id), "|", "&", ("date_start", "<=", date), "|", ("date_end", ">=", date), ("date_end", "=", False), "&", "&", ("trial_date_start", "!=", False), ("trial_date_start", "<=", date), "&", ("trial_date_end", "!=", False), ("trial_date_end", ">=", date), ], context=context, ) if len(active_contract_ids) > 1: lang_pool = self.pool["res.lang"] lang_id = lang_pool.search(cr, uid, [("code", "=", context.get("lang"))], context=context) lang_data = lang_pool.read(cr, uid, lang_id, ["date_format"], context=context) if lang_data: date_format = lang_data[0]["date_format"] else: date_format = DEFAULT_SERVER_DATE_FORMAT employee = self.pool.get("hr.employee").browse(cr, uid, employee_id, context=context) msg = _("Too many active contracts for employee %s at date %s") raise orm.except_orm(_("Error"), msg % (employee.name, datetime.strftime(date, date_format))) elif active_contract_ids: contract = contract_pool.browse(cr, uid, active_contract_ids[0], context=context) return contract.working_hours else: return orm.browse_null()
def address_get(self, cr, uid, ids, adr_pref=None, context=None): """ Find contacts/addresses of the right type(s) by doing a depth-first-search through descendants within company boundaries (stop at entities flagged ``is_company``) then continuing the search at the ancestors that are within the same company boundaries. Defaults to partners of type ``'default'`` when the exact type is not found, or to the provided partner itself if no type ``'default'`` is found either. """ adr_pref = set(adr_pref or []) if 'default' not in adr_pref: adr_pref.add('default') result = {} visited = set() partner = orm.browse_null() for partner in self.browse(cr, uid, filter(None, ids), context=context): current_partner = partner while current_partner: to_scan = [current_partner] # Scan descendants, DFS while to_scan: record = to_scan.pop(0) visited.add(record) if record.type in adr_pref and not result.get(record.type): result[record.type] = record.id if len(result) == len(adr_pref): return result to_scan = [ c for c in record.child_ids if c not in visited if not c.is_company ] + to_scan # Continue scanning at ancestor if current_partner is not a commercial entity if current_partner.is_company or not current_partner.parent_id: break current_partner = current_partner.parent_id # default to type 'default' or the partner itself default = result.get('default', partner.id) for adr_type in adr_pref: result[adr_type] = result.get(adr_type) or default return result
def address_get(self, cr, uid, ids, adr_pref=None, context=None): """ Find contacts/addresses of the right type(s) by doing a depth-first-search through descendants within company boundaries (stop at entities flagged ``is_company``) then continuing the search at the ancestors that are within the same company boundaries. Defaults to partners of type ``'default'`` when the exact type is not found, or to the provided partner itself if no type ``'default'`` is found either. """ adr_pref = set(adr_pref or []) if 'default' not in adr_pref: adr_pref.add('default') result = {} visited = set() partner = orm.browse_null() for partner in self.browse(cr, uid, filter(None, ids), context=context): current_partner = partner while current_partner: to_scan = [current_partner] # Scan descendants, DFS while to_scan: record = to_scan.pop(0) visited.add(record) if record.type in adr_pref and not result.get(record.type): result[record.type] = record.id if len(result) == len(adr_pref): return result to_scan = [c for c in record.child_ids if c not in visited if not c.is_company] + to_scan # Continue scanning at ancestor if current_partner is not a commercial entity if current_partner.is_company or not current_partner.parent_id: break current_partner = current_partner.parent_id # default to type 'default' or the partner itself default = result.get('default', partner.id) for adr_type in adr_pref: result[adr_type] = result.get(adr_type) or default return result
def get_by_record(self, cr, uid, record, context=None): if record.type in ('char', 'text', 'selection'): return record.value_text elif record.type == 'float': return record.value_float elif record.type == 'boolean': return bool(record.value_integer) elif record.type == 'integer': return record.value_integer elif record.type == 'binary': return record.value_binary elif record.type == 'many2one': if not record.value_reference: return browse_null() model, resource_id = record.value_reference.split(',') return self.pool.get(model).browse(cr, uid, int(resource_id), context=context) elif record.type == 'datetime': return record.value_datetime elif record.type == 'date': if not record.value_datetime: return False return time.strftime('%Y-%m-%d', time.strptime(record.value_datetime, '%Y-%m-%d %H:%M:%S')) return False