跟新
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from odoo import fields, models, api, _
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
class CreateTechnologyDesignTaskWizard(models.TransientModel):
|
||||
_name = 'sf.create.technology.design.task.wizard'
|
||||
_description = '创建工艺设计任务向导'
|
||||
|
||||
demand_plan_ids = fields.Many2many('sf.production.demand.plan', string='需求计划', required=True)
|
||||
assigned_to = fields.Many2one('res.users', string='负责人', default=lambda self: self.env.user)
|
||||
deadline = fields.Datetime('截止时间', required=True)
|
||||
notes = fields.Text('备注')
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields_list):
|
||||
res = super(CreateTechnologyDesignTaskWizard, self).default_get(fields_list)
|
||||
if self.env.context.get('active_model') == 'sf.production.demand.plan':
|
||||
demand_plan_ids = self.env.context.get('active_ids', [])
|
||||
res['demand_plan_ids'] = [(6, 0, demand_plan_ids)]
|
||||
return res
|
||||
|
||||
def action_create_tasks(self):
|
||||
"""创建工艺设计任务"""
|
||||
if not self.demand_plan_ids:
|
||||
raise UserError(_('请选择需求计划'))
|
||||
|
||||
# 检查是否已存在工艺设计任务
|
||||
existing_tasks = self.env['sf.technology.design.task'].search([
|
||||
('demand_plan_id', 'in', self.demand_plan_ids.ids),
|
||||
('state', 'not in', ['cancelled'])
|
||||
])
|
||||
|
||||
if existing_tasks:
|
||||
raise UserError(_('以下需求计划已存在工艺设计任务:\n%s') %
|
||||
'\n'.join([task.demand_plan_id.name for task in existing_tasks]))
|
||||
|
||||
# 创建工艺设计任务
|
||||
tasks = self.env['sf.technology.design.task']
|
||||
for demand_plan in self.demand_plan_ids:
|
||||
task_vals = {
|
||||
'demand_plan_id': demand_plan.id,
|
||||
'assigned_to': self.assigned_to.id,
|
||||
'deadline': self.deadline,
|
||||
'notes': self.notes,
|
||||
}
|
||||
task = self.env['sf.technology.design.task'].create(task_vals)
|
||||
tasks |= task
|
||||
|
||||
# 返回工艺设计任务列表视图
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'name': _('工艺设计任务'),
|
||||
'res_model': 'sf.technology.design.task',
|
||||
'view_mode': 'tree,form',
|
||||
'domain': [('id', 'in', tasks.ids)],
|
||||
'context': {'search_default_filter_pending': 1},
|
||||
}
|
||||
Reference in New Issue
Block a user