Commit 82b26169 by 夏超

[fix] 子母任务修正

parent 7a97a33e
......@@ -11,7 +11,7 @@ from odoo.exceptions import ValidationError
class InheritProductionTask(models.Model):
_inherit = "roke.production.task"
_order = "main_task_code desc, id"
_order = "main_task_code desc, code asc"
file_ids = fields.Many2many("ir.attachment", "roke_production_task_ir_attachment", "pro_id", "att_id")
......@@ -19,41 +19,29 @@ class InheritProductionTask(models.Model):
task_type = fields.Selection([
('main', '主任务'),
('sub', '子任务'),
('repair', '返修任务'),
('replenish', '补件任务')
], string='任务类型', compute='_compute_task_type', store=True)
('sub', '子任务')
], string='任务类型', compute='_compute_task_type')
main_task_code = fields.Char(string='主任务编号', compute='_compute_main_task_code', store=True, index=True)
main_task_code = fields.Char(string='主任务编号', compute='_compute_main_task_code', index=True)
@api.depends('work_order_ids')
def _compute_work_order_hours(self):
for record in self:
record.work_order_hours = sum(record.work_order_ids.mapped("work_hours"))
@api.depends('parent_id', 'type')
@api.depends('code')
def _compute_task_type(self):
for record in self:
if record.type == '返修':
record.task_type = 'repair'
elif record.type == '补件':
record.task_type = 'replenish'
elif record.parent_id:
if '-' in (record.code or ""):
task_str = record.code.split('-')
if task_str[-1] == "1":
record.task_type = 'main'
record.main_task_code = task_str[0]
else:
record.task_type = 'sub'
record.main_task_code = task_str[0]
else:
record.task_type = 'main'
@api.depends('task_type', 'code', 'parent_id')
def _compute_main_task_code(self):
for record in self:
# 对于子任务、返修任务和补件任务,获取主任务的编号
if record.type == "返修":
record.main_task_code = record.repair_order_id.wr_id.work_order_id.task_id.code
elif record.type == '补件':
record.main_task_code = record.scrap_order_id.wr_id.work_order_id.task_id.code
elif record.parent_id:
record.main_task_code = record.parent_id.code
else:
record.main_task_code = record.code
def write(self, vals):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment