添加功能
This commit is contained in:
@@ -166,6 +166,7 @@ class HrAttendanceMonthWizard(models.TransientModel):
|
||||
'年假': 'annual_leave',
|
||||
'事假': 'unpaid_leave',
|
||||
'补休': 'cop_leave',
|
||||
'产假': 'maternity_leave',
|
||||
}
|
||||
leave_days = {}
|
||||
year = int(self.current_year)
|
||||
|
||||
@@ -168,13 +168,63 @@ class YuthonHrEmployee(models.Model):
|
||||
is_salary = fields.Boolean(string="是否薪资计算", default=True)
|
||||
last_month_attendance_deduction = fields.Float(string="上月考勤扣款")
|
||||
last_month_base_salary_deduction = fields.Float(string="上月基本薪资扣款")
|
||||
last_month_performance_deduction = fields.Float(string="上月绩效扣款")
|
||||
last_month_commuting_deduction = fields.Float(string='上月通信扣款')
|
||||
last_month_performance_deduction = fields.Float(string="上月绩效扣款", compute='_compute_last_month_deductions')
|
||||
last_month_commuting_deduction = fields.Float(string='上月通信扣款', compute='_compute_last_month_deductions')
|
||||
commuting = fields.Float(string='通信补贴', compute='_compute_employee_salary')
|
||||
performance = fields.Float(string='绩效奖金', compute='_compute_employee_salary')
|
||||
medical_insurance_base = fields.Float(string='基本医疗费基数', compute='_compute_insurance_bases')
|
||||
pension_insurance_base = fields.Float(string='基本养老费基数', compute='_compute_insurance_bases')
|
||||
work_injury_insurance_base = fields.Float(string='工伤保险费基数', compute='_compute_insurance_bases')
|
||||
housing_fund_base = fields.Float(string='住房公积金基数', compute='_compute_insurance_bases')
|
||||
|
||||
def _compute_employee_salary(self):
|
||||
for record in self:
|
||||
# 获取上个月的时间范围
|
||||
now = datetime.now()
|
||||
last_month_start = (now.replace(day=1) - relativedelta(months=1))
|
||||
last_month_end = last_month_start + relativedelta(day=31)
|
||||
payslip_record = self.env['hr.payslip'].search([
|
||||
('employee_id', '=', record.id),
|
||||
('date_from', '>=', last_month_start),
|
||||
('date_to', '<=', last_month_end)
|
||||
])
|
||||
if payslip_record:
|
||||
record.commuting = payslip_record.commuting_allowance
|
||||
record.performance = payslip_record.performance_bonuses
|
||||
else:
|
||||
record.commuting = 0
|
||||
record.performance = 0
|
||||
|
||||
@api.depends('commuting', 'performance')
|
||||
def _compute_last_month_deductions(self):
|
||||
today = datetime.today()
|
||||
last_month = today - relativedelta(months=1)
|
||||
last_month_year = str(last_month.year)
|
||||
last_month_month = str(last_month.month)
|
||||
for record in self:
|
||||
# 查找上个月的考勤月度明细记录
|
||||
attendance_record = self.env['hr.attendance.month.detail'].search([
|
||||
('employee_id', '=', record.id),
|
||||
('current_year', '=', last_month_year),
|
||||
('current_month', '=', last_month_month)
|
||||
])
|
||||
if attendance_record:
|
||||
# 计算总产假天数
|
||||
maternity_leave = attendance_record.maternity_leave
|
||||
# 计算月天数
|
||||
if last_month.month in [1, 3, 5, 7, 8, 10, 12]:
|
||||
end_day = 31
|
||||
elif last_month.month in [4, 6, 9, 11]:
|
||||
end_day = 30
|
||||
elif (last_month.month % 4 == 0 and last_month.year % 100 != 0) or (last_month.year % 400 == 0):
|
||||
end_day = 29
|
||||
else:
|
||||
end_day = 28
|
||||
|
||||
# 计算扣款
|
||||
record.last_month_commuting_deduction = record.commuting / end_day * maternity_leave
|
||||
record.last_month_performance_deduction = record.performance / end_day * maternity_leave
|
||||
|
||||
@api.depends('social_base_on', 'social_base_off')
|
||||
def _compute_insurance_bases(self):
|
||||
current_month = datetime.now().month
|
||||
|
||||
@@ -147,6 +147,8 @@
|
||||
<field name="last_month_base_salary_deduction"/>
|
||||
<field name="last_month_performance_deduction"/>
|
||||
<field name="last_month_commuting_deduction"/>
|
||||
<field name="commuting" invisible="1"/>
|
||||
<field name="performance" invisible="1"/>
|
||||
<field name="is_salary"/>
|
||||
</group>
|
||||
<group name="overtime" string="加班" col="2">
|
||||
|
||||
Reference in New Issue
Block a user