Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

Call a field value from hr_employee to hr_attendance?

Subscriure's

Get notified when there's activity on this post

This question has been flagged
hremployeeattendanceinheritodoo8.0
7987 Vistes
Avatar
Uppili Arivukkannu

I'm trying to get hours base salary based on sign in and sign out data from attendance.

Now I'm getting hours based salary based on the worked hours from hr attendance.

I given the salary or wage as default value so it gives the value based on the default value.

Each employee has different salary so I have created a field named salary in employee.



class hr_employee(osv.osv):

_name = "hr.employee"

_description = "Employee"

_order = 'name_related'

_inherits = {'resource.resource': "resource_id"}

_inherit = ['mail.thread']

_mail_post_access = 'read'

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):

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.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', help='Social Security Number'),

'sinid': fields.char('SIN No', help="Social Insurance Number"),

'identification_id': fields.char('Identification No'),

'otherid': fields.char('Other Id'),

'gender': fields.selection([('male', 'Male'), ('female', 'Female')], 'Gender'),

'marital': fields.selection([('single', 'Single'), ('married', 'Married'), ('widower', 'Widower'), ('divorced', 'Divorced')], 'Marital Status'),

'department_id': fields.many2one('hr.department', 'Department'),

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

'address_home_id': fields.many2one('res.partner', 'Home Address'),

'bank_account_id': fields.many2one('res.partner.bank', 'Bank Account Number', domain="[('partner_id','=',address_home_id)]", help="Employee bank salary account"),

'work_phone': fields.char('Work Phone', readonly=False),

'mobile_phone': fields.char('Work Mobile', readonly=False),

'work_email': fields.char('Work Email', size=240),

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

'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', 'Tags'),

'child_ids': fields.one2many('hr.employee', 'parent_id', 'Subordinates'),

'resource_id': fields.many2one('resource.resource', 'Resource', ondelete='cascade', required=True, auto_join=True),

'coach_id': fields.many2one('hr.employee', 'Coach'),

'job_id': fields.many2one('hr.job', 'Job Title'),

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

# image: all image fields are base64 encoded and PIL-supported

'image': fields.binary("Photo",

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 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="Small-sized photo", type="binary", multi="_get_image",

store = {

'hr.employee': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10),

},

help="Small-sized photo of the employee. It is automatically "\

"resized as a 64x64px image, with aspect ratio preserved. "\

"Use this field anywhere a small image is required."),

'passport_id': fields.char('Passport No'),

'color': fields.integer('Color Index'),

'city': fields.related('address_id', 'city', type='char', string='City'),

'login': fields.related('user_id', 'login', type='char', string='Login', readonly=1),

'last_login': fields.related('user_id', 'date', type='datetime', string='Latest Connection', readonly=1),

}


I want to call this salary to hr_attendance so that every employee salary is computed based on the salary given in the hr_employee.

My code is:



class hr_attendance(osv.osv):

_name = "hr.attendance"

_description = "Attendance"

def _worked_hours_compute(self, cr, uid, ids, fieldnames, args, context=None):

"""For each hr.attendance record of action sign-in: assign 0.

For each hr.attendance record of action sign-out: assign number of hours since last sign-in.

"""

res = {}

for obj in self.browse(cr, uid, ids, context=context):

if obj.action == 'sign_in':

res[obj.id] = 0

elif obj.action == 'sign_out':

# Get the associated sign-in

last_signin_id = self.search(cr, uid, [

('employee_id', '=', obj.employee_id.id),

('name', '<', obj.name), ('action', '=', 'sign_in')

], limit=1, order='name DESC')

if last_signin_id:

last_signin = self.browse(cr, uid, last_signin_id, context=context)[0]

# Compute time elapsed between sign-in and sign-out

last_signin_datetime = datetime.strptime(last_signin.name, '%Y-%m-%d %H:%M:%S')

signout_datetime = datetime.strptime(obj.name, '%Y-%m-%d %H:%M:%S')

workedhours_datetime = (signout_datetime - last_signin_datetime)

res[obj.id] = ((workedhours_datetime.seconds) / 60) / 60.0

else:

res[obj.id] = False

return res


def _per_hour_compute(self, cr, uid, ids, fieldnames, args, context=None):

res = {}

for obj in self.browse(cr, uid, ids, context=context):

if obj.action == 'sign_in':

res[obj.id] = 0

elif obj.action == 'sign_out': 

last_signin_id = self.search(cr, uid, [

('employee_id', '=', obj.employee_id.id),

('name', '<', obj.name), ('action', '=', 'sign_in')

], limit=1, order='name DESC')

salary_id = self.search(cr, uid, [('employee_id', '=', obj.employee_id.id), ('salary')], limit=1)

if last_signin_id:

last_signin = self.browse(cr, uid, last_signin_id, context=context)[0]

salary_ids = self.browse(cr, uid, salary_id, context=context)[0] 

per_hour_wage = float(salary_ids.salary)

last_signin_datetime = datetime.strptime(last_signin.name, '%Y-%m-%d %H:%M:%S')

signout_datetime = datetime.strptime(obj.name, '%Y-%m-%d %H:%M:%S')

workedhours_datetime = (signout_datetime - last_signin_datetime)

total_hours = (((workedhours_datetime.seconds) / 60) / 60.0)

total_hours1 = 9.00 - 0.50

if total_hours > 9.50 and total_hours < 12.00:

res[obj.id] = (total_hours1 + 1.00) * (per_hour_wage)

else:

res[obj.id] = (total_hours1) * (per_hour_wage)

if total_hours < 9.50:

res[obj.id] = (total_hours) * (per_hour_wage)

else:

res[obj.id] = False

return res


But it shows error as

ValidateError

Field(s) `action` failed against a constraint: Error ! Sign in (resp. Sign out) must follow Sign out (resp. Sign in)

Error details:

Invalid leaf salary.

So I tried to inherit hr.employee


class hr_attendance(osv.osv):

_name = "hr.attendance"

_description = "Attendance"

_inherit = "hr.employee"


But it shows error


Integrity Error

The operation cannot be completed, probably due to the following:

- deletion: you may be trying to delete a record while other records still reference it

- creation/update: a mandatory field is not correctly set

[object with reference: name - name]


How can I achieve this. I want to call a value of a field(salary) in hr_employee to hr_attendance to compute the salary(per_hour_wage)?

Give me some solutions



0
Avatar
Descartar
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registrar-se
Related Posts Respostes Vistes Activitat
Despite correct terminal outputs, Odoo's frontend displays a different value of check-out hours (a TZ problem)
hr employee attendance timezones
Avatar
0
de maig 23
2899
Flexible Working Hours
hr employee payroll attendance working_time
Avatar
0
de nov. 23
80
I want to store attendance for whole month for all the employee. Solved
hr employee attendance gridview v12
Avatar
Avatar
1
de des. 19
4247
Sync/Copy data between models in Odoo 8
hr on_change employee inherit applicants
Avatar
0
d’abr. 17
4820
Connect fingerprint devices to Odoo Solved
hr attendance
Avatar
Avatar
1
de maig 25
2066
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now