tree视图中的"批量排程"按钮优化为向导的实现方式
This commit is contained in:
@@ -2,3 +2,4 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import models
|
||||
from . import wizard
|
||||
|
||||
@@ -17,8 +17,10 @@
|
||||
'data': [
|
||||
'security/ir.model.access.csv',
|
||||
# 'security/rules.xml',
|
||||
'wizard/action_plan_some.xml',
|
||||
'views/view.xml',
|
||||
'views/change_manufactuing.xml'
|
||||
'views/change_manufactuing.xml',
|
||||
|
||||
],
|
||||
|
||||
'assets': {
|
||||
|
||||
@@ -12,7 +12,7 @@ class sf_production_plan(models.Model):
|
||||
_name = 'sf.production.plan'
|
||||
_description = 'sf_production_plan'
|
||||
_inherit = ['mail.thread']
|
||||
_order = 'create_date desc'
|
||||
_order = 'state desc, write_date desc'
|
||||
|
||||
state = fields.Selection([
|
||||
('draft', '待排程'),
|
||||
@@ -252,6 +252,7 @@ class sf_production_plan(models.Model):
|
||||
def cancel_production_schedule(self):
|
||||
self.date_planned_finished = False
|
||||
self.state = 'draft'
|
||||
self.production_line_id = False
|
||||
aa = self.env['mrp.production'].sudo().search([('name', '=', self.name)])
|
||||
aa.schedule_state = '未排'
|
||||
return self.date_planned_finished
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||
access_sf_production_plan,sf.production.plan,model_sf_production_plan,base.group_user,1,0,0,0
|
||||
access_sf_production_plan_for_dispatch,sf.production.plan for dispatch,model_sf_production_plan,sf_base.group_plan_dispatch,1,1,1,0
|
||||
|
||||
access_sf_action_plan_all_wizard,sf.action.plan.all.wizard,model_sf_action_plan_all_wizard,base.group_user,1,1,1,1
|
||||
|
@@ -5,9 +5,11 @@
|
||||
<field name="name">sf.production.plan.tree</field>
|
||||
<field name="model">sf.production.plan</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="订单计划" editable="bottom">
|
||||
<!-- <tree string="订单计划" editable="bottom"> -->
|
||||
<tree string="订单计划">
|
||||
<header>
|
||||
<button name="do_production_schedule" type="object" string="批量排程"/>
|
||||
<!-- <button name="do_production_schedule" type="object" string="批量排程"/> -->
|
||||
<button string="批量排程" name="%(sf_plan.action_plan_some)d" type="action" class="btn-primary"/>
|
||||
</header>
|
||||
<field name="state" widget="badge" decoration-warning="state == 'draft'" decoration-success="state == 'done'"/>
|
||||
<field name="name"/>
|
||||
|
||||
1
sf_plan/wizard/__init__.py
Normal file
1
sf_plan/wizard/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import action_plan_some
|
||||
65
sf_plan/wizard/action_plan_some.py
Normal file
65
sf_plan/wizard/action_plan_some.py
Normal file
@@ -0,0 +1,65 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import base64
|
||||
import logging
|
||||
import os
|
||||
from datetime import datetime
|
||||
from odoo import fields, models
|
||||
# from odoo.exceptions import ValidationError
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Action_Plan_All_Wizard(models.TransientModel):
|
||||
_name = 'sf.action.plan.all.wizard'
|
||||
_description = u'排程向导'
|
||||
|
||||
# 选择生产线
|
||||
production_line_id = fields.Many2one('sf.production.line', string=u'生产线', required=True)
|
||||
|
||||
# 接收传递过来的计划ID
|
||||
plan_ids = fields.Many2many('sf.production.plan', string=u'计划ID')
|
||||
|
||||
# 确认排程按钮
|
||||
def action_plan_all(self):
|
||||
# 使用传递过来的计划ID
|
||||
temp_plan_ids = self.plan_ids
|
||||
# 在这里添加您的逻辑来处理这些ID
|
||||
for plan in temp_plan_ids:
|
||||
# 处理每个计划
|
||||
# 比如更新计划状态、分配资源等
|
||||
# 示例:plan.state = 'scheduled'
|
||||
print('处理计划:', plan.id)
|
||||
# 拿到计划对象
|
||||
plan_obj = self.env['sf.production.plan'].browse(plan.id)
|
||||
plan_obj.production_line_id = self.production_line_id.id
|
||||
plan_obj.do_production_schedule()
|
||||
plan_obj.state = 'done'
|
||||
print('处理计划:', plan.id, '完成')
|
||||
|
||||
# # 获取当前生产线
|
||||
# production_line_id = self.production_line_id
|
||||
# # 获取当前生产线的所有生产订单
|
||||
# production_order_ids = self.env['mrp.production'].search([('production_line_id', '=', production_line_id.id)])
|
||||
# # 获取当前生产线的所有生产订单的id
|
||||
# production_order_id_list = []
|
||||
# for production_order_id in production_order_ids:
|
||||
# production_order_id_list.append(production_order_id.id)
|
||||
# # 获取当前生产线的所有生产订单的排程状态
|
||||
# production_order_plan_state_list = []
|
||||
# for production_order_id in production_order_ids:
|
||||
# production_order_plan_state_list.append(production_order_id.plan_state)
|
||||
# # 如果当前生产线的所有生产订单的排程状态都是已排程,则报错
|
||||
# if all(production_order_plan_state == '已排程' for production_order_plan_state in production_order_plan_state_list):
|
||||
# raise UserError('当前生产线的所有生产订单都已排程,请勿重复排程!')
|
||||
# # 如果当前生产线的所有生产订单的排程状态都是未排程,则报错
|
||||
# if all(production_order_plan_state == '未排程' for production_order_plan_state in production_order_plan_state_list):
|
||||
# raise UserError('当前生产线的所有生产订单都未排程,请先排程!')
|
||||
# # 如果当前生产线的所有生产订单的排程状态都是已完成,则报错
|
||||
# if all(production_order_plan_state == '已完成' for production_order_plan_state in production_order_plan_state_list):
|
||||
# raise UserError('当前生产线的所有生产订单都已完成,请勿重复排程!')
|
||||
# # 如果当前生产线的所有生产订单的排程状态都是已取消,则报错
|
||||
# if all(production_order_plan_state == '已取消' for production_order_plan_state in production_order_plan_state_list):
|
||||
# raise UserError('当前生产线的所有生产订单都已取消,请勿重复排程!')
|
||||
# # 如果当前生产线的所有生产订单的排程状态都是已暂停,则报错
|
||||
# if all(production_order_plan_state == '已暂停' for production_order_plan_state in production
|
||||
31
sf_plan/wizard/action_plan_some.xml
Normal file
31
sf_plan/wizard/action_plan_some.xml
Normal file
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<odoo>
|
||||
<record id="action_plan_some_form" model="ir.ui.view">
|
||||
<field name="name">选择生产线</field>
|
||||
<field name="model">sf.action.plan.all.wizard</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<group>
|
||||
<field name="production_line_id"/>
|
||||
</group>
|
||||
<footer>
|
||||
<button string="确认排程" name="action_plan_all" type="object" class="btn-primary"/>
|
||||
<!-- <button string="取消" class="btn-secondary" special="cancel"/> -->
|
||||
<button string="取消" class="btn-primary" special="cancel"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
<record id="action_plan_some" model="ir.actions.act_window">
|
||||
<field name="name">请选择要排程的生产线</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<!-- <field name="res_model">up.select.wizard</field>-->
|
||||
<field name="res_model">sf.action.plan.all.wizard</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="view_id" ref="action_plan_some_form"/>
|
||||
<field name="target">new</field>
|
||||
<field name="context">{'default_plan_ids': active_ids}</field>
|
||||
</record>
|
||||
|
||||
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user