添加功能

This commit is contained in:
zhouzhou
2024-12-13 21:32:24 +08:00
parent 308c535f5b
commit 5c06c1e244
3 changed files with 55 additions and 38 deletions
@@ -5,7 +5,7 @@ from odoo.exceptions import UserError
class YuthonSpecialApproval(models.Model):
_name = 'yuthon.special.approval'
_inherit = ['soong.workflow.mixin', 'mail.thread.main.attachment', 'mail.activity.mixin']
# _inherit = ['soong.workflow.mixin', 'mail.thread.main.attachment', 'mail.activity.mixin']
_description = '特殊加班'
yuthon_company = fields.Selection(related='users_id.employee_id.yuthon_company', string="公司")
@@ -13,49 +13,47 @@ class YuthonSpecialApproval(models.Model):
name = fields.Char(string="标题", readonly=False, default=lambda self: self.env.user.employee_id.resource_id.name)
reason_application = fields.Html(string="申请事由")
code = fields.Char(string="编号", default=lambda self: self.env['ir.sequence'].next_by_code('special_approval'))
resource_id = fields.Many2one('resource.resource', string="申请人",
resource_id = fields.Many2one('resource.resource', string="发起人",
default=lambda self: self.env.user.employee_id.resource_id.id)
template_id = fields.Many2one('planning.slot.template', string="加班模板", domain="[('department_id', '=', departments_id)]")
start_date = fields.Date(string="开始日期")
employee_ids = fields.Many2many('hr.employee', string="加班人员", domain="[('department_id.name', '=', '联安粮库')]")
slot_id = fields.Many2one('planning.slot', string="开始日期", domain="[('id', 'in', start_list_ids)]")
start_list_ids = fields.Many2many('planning.slot', string="班次列表")
documents_ids = fields.Many2many('ir.attachment', string="附件")
department_id = fields.Many2one('hr.department', string="部门", related='resource_id.employee_id.department_id')
departments_id = fields.Many2one('hr.department', string="部门")
active = fields.Boolean('Active', default=True, tracking=True)
is_issues = fields.Boolean(string='是否上会')
related_issues_id = fields.Many2one('issue.library', string="关联议题")
@api.onchange('department_id')
def _onchange_resource_ids(self):
target_departments = ['工程部', '保安部', '联安粮库']
current_department = self.department_id
while current_department:
if current_department.name in target_departments:
self.departments_id = current_department.id
break
current_department = current_department.parent_id
def button_special_approval(self):
role_a = self.env['planning.role'].search([('name', '=', self.departments_id.name)], limit=1)
start_datetime = datetime.combine(self.start_date, datetime.min.time())
start_hour = int(self.template_id.start_time)
end_hour = int(self.template_id.end_time)
start_time = start_datetime.replace(hour=start_hour) + timedelta(hours=16) - timedelta(days=1)
if self.template_id.end_time < self.template_id.start_time:
end_time = start_datetime.replace(hour=end_hour) + timedelta(days=1, hours=16) - timedelta(days=1)
else:
end_time = start_datetime.replace(hour=end_hour) + timedelta(hours=16) - timedelta(days=1)
self.env['planning.slot'].create({
'resource_id': self.resource_id.id,
'template_id': self.template_id.id,
'role_id': role_a.id,
'start_datetime': start_time,
'end_datetime': end_time,
'allocated_hours': 8,
})
role_a = self.env['planning.role'].search([('name', '=', '联安粮库')], limit=1)
role_template_b = self.env['planning.slot.template'].search([('planning_name', '=', '粮库值班'), ('role_id', '=', role_a.id)])
shift_id = self.slot_id
start_date = shift_id.start_datetime.date()
end_date = start_date + timedelta(days=1)
for employee_id in self.employee_ids:
slot_id = self.env['planning.slot'].search([
('resource_id', '=', employee_id.resource_id.id),
('start_datetime', '>=', start_date), # 大于等于起始日期
('start_datetime', '<', end_date), # 小于结束日期 (即下一天),
])
if slot_id:
slot_id.write({'template_id': role_template_b})
@api.onchange('resource_id', 'start_date', 'template_id')
@api.onchange('resource_id', 'slot_id')
def onchange_name(self):
for rec in self:
if rec.resource_id and rec.start_date and rec.template_id:
rec.name = rec.resource_id.name + str(rec.start_date) + rec.template_id.planning_name
if rec.resource_id and rec.slot_id:
rec.name = rec.resource_id.name +':'+ rec.slot_id.start_datetime.strftime("%m/%d")
@api.onchange("resource_id")
def _onchange_resource_ids(self):
for rec in self:
start_list_ids = self.env['planning.slot'].search([('resource_id', '=', rec.resource_id.id),
('template_id.planning_name', 'ilike', '%值班%'),
('start_datetime', '>', datetime.now())]).ids
if start_list_ids:
rec.start_list_ids = [(6, 0, start_list_ids)]
@@ -0,0 +1,19 @@
<odoo>
<record id="view_resource_resource_tree_inherit" model="ir.ui.view">
<field name="name">resource.resource.tree.inherit</field>
<field name="model">resource.resource</field>
<field name="inherit_id" ref="resource.resource_resource_tree"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='user_id']" position="before">
<field name="department_id"/>
</xpath>
</field>
</record>
<record id="all_data_write_resource_department" model="ir.actions.server">
<field name="name">批量更新员工</field>
<field name="model_id" ref="resource.model_resource_resource"/>
<field name="binding_model_id" ref="resource.model_resource_resource"/>
<field name="state">code</field>
<field name="code">action = model.action_resource_resource()</field>
</record>
</odoo>
@@ -32,8 +32,8 @@
<group string="个人信息" col="2">
<group>
<field name="resource_id"/>
<field name="departments_id" invisible="1"/>
<field name="template_id"/>
<field name="employee_ids" widget="many2many_tags"/>
<field name="start_list_ids" widget="many2many_tags"/>
<field name="users_id" invisible="1"/>
<field name="is_issues" invisible="1"/>
<field name="related_issues_id" invisible="not is_issues"/>
@@ -41,7 +41,7 @@
</group>
<group>
<field name="department_id"/>
<field name="start_date"/>
<field name="slot_id"/>
</group>
</group>
</sheet>