shcool/yuthon_wage/wizards/payslip_generate.py
2026-08-03 09:57:51 +08:00

42 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- coding: utf-8 -*-
from odoo import fields, models, api
class PayslipGenerateWizard(models.TransientModel):
"""生成月度工资条向导:批量给选定教职工创建 yuthon.payslip。
教学要点TransientModel向导模型数据临时、自动清理+ 批量创建。
"""
_name = 'yuthon.payslip.generate.wizard'
_description = '生成月度工资条向导'
period_start = fields.Date(string='起始日期', required=True)
period_end = fields.Date(string='结束日期', required=True)
allowance = fields.Float(string='津贴/补贴', default=0.0)
employee_ids = fields.Many2many(
'yuthon.employee',
string='教职工',
)
def action_generate(self):
"""为每位选定教职工创建一条工资条(带默认值,算出迟到/缺勤/实发)。"""
self.ensure_one()
Payslip = self.env['yuthon.payslip']
employees = self.employee_ids or self.env['yuthon.employee'].search([])
created = Payslip
for emp in employees:
created |= Payslip.create({
'employee_id': emp.id,
'period_start': self.period_start,
'period_end': self.period_end,
'allowance': self.allowance,
})
# 返回刚生成的工资条列表视图
return {
'type': 'ir.actions.act_window',
'name': '工资条',
'res_model': 'yuthon.payslip',
'view_mode': 'list,form',
'domain': [('id', 'in', created.ids)],
}