67 lines
2.8 KiB
Python
67 lines
2.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
from odoo import models, fields, api
|
|
|
|
|
|
class SalaryStructure(models.Model):
|
|
"""薪资结构 - 定义不同岗位/职称的薪资构成"""
|
|
_name = 'yuthon.salary.structure'
|
|
_description = '薪资结构'
|
|
_order = 'name'
|
|
|
|
name = fields.Char(string='结构名称', required=True)
|
|
code = fields.Char(string='结构编码', required=True)
|
|
description = fields.Text(string='说明')
|
|
# 适用对象
|
|
applicable_type = fields.Selection([
|
|
('teacher', '任课教师'),
|
|
('admin', '行政人员'),
|
|
('leadership', '领导班子'),
|
|
('support', '后勤人员'),
|
|
('intern', '实习教师'),
|
|
('all', '全体适用'),
|
|
], string='适用类型', required=True, default='teacher')
|
|
# 适用学校类型
|
|
school_type = fields.Selection([
|
|
('kindergarten', '幼儿园'),
|
|
('primary', '小学'),
|
|
('junior', '初中'),
|
|
('senior', '高中'),
|
|
('vocational', '职业院校'),
|
|
('university', '高等院校'),
|
|
('all', '全部适用'),
|
|
], string='适用学校类型', required=True, default='all')
|
|
line_ids = fields.One2many('yuthon.salary.structure.line', 'structure_id', string='薪资项目明细')
|
|
active = fields.Boolean(string='启用', default=True)
|
|
company_id = fields.Many2one('res.company', string='学校', default=lambda self: self.env.company)
|
|
|
|
# 合计字段
|
|
total_basic = fields.Float(string='基本收入合计', compute='_compute_totals', store=True)
|
|
total_deduction = fields.Float(string='扣款合计', compute='_compute_totals', store=True)
|
|
total_net = fields.Float(string='实发合计', compute='_compute_totals', store=True)
|
|
|
|
@api.depends('line_ids.amount', 'line_ids.item_id.item_type')
|
|
def _compute_totals(self):
|
|
for structure in self:
|
|
income = sum(line.amount for line in structure.line_ids if line.item_id.item_type == 'income')
|
|
deduction = sum(line.amount for line in structure.line_ids if line.item_id.item_type == 'deduction')
|
|
structure.total_basic = income
|
|
structure.total_deduction = deduction
|
|
structure.total_net = income - deduction
|
|
|
|
_sql_constraints = [
|
|
('code_uniq', 'unique(code)', '结构编码必须唯一!'),
|
|
]
|
|
|
|
|
|
class SalaryStructureLine(models.Model):
|
|
"""薪资结构明细行"""
|
|
_name = 'yuthon.salary.structure.line'
|
|
_description = '薪资结构明细'
|
|
_order = 'sequence, id'
|
|
|
|
structure_id = fields.Many2one('yuthon.salary.structure', string='薪资结构', required=True, ondelete='cascade')
|
|
sequence = fields.Integer(string='排序', default=10)
|
|
item_id = fields.Many2one('yuthon.salary.item', string='薪资项目', required=True)
|
|
amount = fields.Float(string='默认金额', default=0.0)
|
|
note = fields.Char(string='备注')
|