[ADD]hr_employee_stats_sheet_lunch_voucher
This commit is contained in:
1
hr_employee_stats_sheet_lunch_voucher/models/__init__.py
Normal file
1
hr_employee_stats_sheet_lunch_voucher/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import hr_employee_stats, hr_timesheet_sheet, res_config, res_company
|
@@ -0,0 +1,19 @@
|
||||
from odoo import fields, models, api
|
||||
|
||||
class HrEmployeeStats(models.Model):
|
||||
_inherit = "hr.employee.stats"
|
||||
|
||||
lunch_voucher = fields.Integer("Lunch Voucher", compute="_compute_lunch_voucher")
|
||||
|
||||
@api.depends("total_hours")
|
||||
def _compute_lunch_voucher(self):
|
||||
for stat in self:
|
||||
stat.lunch_voucher = 0
|
||||
if stat.date and stat.employee_id:
|
||||
stat._get_lunch_voucher()
|
||||
|
||||
def _get_lunch_voucher(self):
|
||||
#do not factorize this method with _compute_lunch_voucher to be used in other modules
|
||||
self.ensure_one()
|
||||
if self.total_hours >= self.env.company.lunch_voucher_min_worked_hours:
|
||||
self.lunch_voucher = 1
|
@@ -0,0 +1,15 @@
|
||||
from odoo import fields, models, api
|
||||
|
||||
class HrTimesheetSheet(models.Model):
|
||||
_inherit = "hr_timesheet.sheet"
|
||||
|
||||
lunch_voucher_count = fields.Integer("Lunch voucher Count", compute="_compute_lunch_voucher_count")
|
||||
|
||||
@api.depends("employee_stats_ids.lunch_voucher")
|
||||
def _compute_lunch_voucher_count(self):
|
||||
for sheet in self:
|
||||
sheet.lunch_voucher_count = 0
|
||||
if sheet.employee_stats_ids:
|
||||
for stat in sheet.employee_stats_ids:
|
||||
sheet.lunch_voucher_count += stat.lunch_voucher
|
||||
|
@@ -0,0 +1,7 @@
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class ResCompany(models.Model):
|
||||
_inherit = "res.company"
|
||||
|
||||
lunch_voucher_min_worked_hours = fields.Float(default=5)
|
14
hr_employee_stats_sheet_lunch_voucher/models/res_config.py
Normal file
14
hr_employee_stats_sheet_lunch_voucher/models/res_config.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class ResConfigSettings(models.TransientModel):
|
||||
_inherit = "res.config.settings"
|
||||
|
||||
lunch_voucher_min_worked_hours = fields.Float(
|
||||
related="company_id.lunch_voucher_min_worked_hours",
|
||||
required=True,
|
||||
string="Minimal number of hours worked in a day to get a lunch voucher",
|
||||
domain="[('company_id', '=', company_id)]",
|
||||
readonly=False,
|
||||
help="5h by default, meaning that if an employee works 5h or more in a day, he will get a lunch voucher",
|
||||
)
|
Reference in New Issue
Block a user