Accept Merge Request #365: (feature/生产排程 -> develop)

Merge Request: 生产计划优化

Created By: @马广威
Accepted By: @马广威
URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/365?initial=true
This commit is contained in:
马广威
2023-09-06 09:23:50 +08:00
committed by Coding
3 changed files with 104 additions and 56 deletions

View File

@@ -1,12 +1,10 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import base64 import base64
import json, requests
from odoo import models, fields, api, _ from odoo import models, fields, api, _
from datetime import datetime, timedelta from datetime import datetime, timedelta
from odoo.exceptions import UserError, ValidationError from odoo.exceptions import UserError, ValidationError
import json, requests, logging
# sf排程 # sf排程
class sf_production_plan(models.Model): class sf_production_plan(models.Model):
@@ -15,6 +13,7 @@ class sf_production_plan(models.Model):
_description = 'sf_production_plan' _description = 'sf_production_plan'
name = fields.Char(string='名称') name = fields.Char(string='名称')
# selected = fields.Boolean(default=False)
production_id = fields.Many2one('mrp.production', '关联制造订单') production_id = fields.Many2one('mrp.production', '关联制造订单')
product_qty = fields.Float(string='数量', digits='Product Unit of Measure', required=True, default=0.0) product_qty = fields.Float(string='数量', digits='Product Unit of Measure', required=True, default=0.0)
date_planned_start = fields.Datetime(string='计划开始时间', required=True, index=True, copy=False, date_planned_start = fields.Datetime(string='计划开始时间', required=True, index=True, copy=False,
@@ -146,57 +145,60 @@ class sf_production_plan(models.Model):
# 当不设置计划结束时间时,增加计算计划结束时间的方法,根据采购周期加缓冲期两个值来算就可以了 # 当不设置计划结束时间时,增加计算计划结束时间的方法,根据采购周期加缓冲期两个值来算就可以了
def do_production_schedule(self): def do_production_schedule(self):
aa = self.env['mrp.production'].sudo().search([('name', '=', self.name)]) if not self.production_line_id:
workorder_time = 0 raise ValidationError("未选择生产线")
print(aa.workorder_ids)
print(type(aa.workorder_ids))
if aa.workorder_ids:
for item in aa.workorder_ids:
current_workorder = self.env['mrp.workorder'].sudo().search([('id', '=', item.id)])
workorder_time += current_workorder.duration_expected
print(workorder_time)
self.date_planned_finished = self.date_planned_start + timedelta(minutes=workorder_time)
self.state = 'done'
else: else:
self.date_planned_finished = self.date_planned_start + timedelta(days=3) aa = self.env['mrp.production'].sudo().search([('name', '=', self.name)])
self.state = 'done' workorder_time = 0
return { print(aa.workorder_ids)
'name': '排程甘特图', print(type(aa.workorder_ids))
'type': 'ir.actions.act_window', if aa.workorder_ids:
'res_model': 'sf.production.plan', # 要跳转的模型名称 for item in aa.workorder_ids:
'view_mode': 'gantt,tree,form', # 要显示的视图类型,可以是'form', 'tree', 'kanban', 'graph', 'calendar', 'pivot'等 current_workorder = self.env['mrp.workorder'].sudo().search([('id', '=', item.id)])
'target': 'current', # 跳转的目标窗口,可以是'current'或'new' workorder_time += current_workorder.duration_expected
} print(workorder_time)
# if self.production_line_id: self.date_planned_finished = self.date_planned_start + timedelta(minutes=workorder_time)
# if self.plan_start_time and self.plan_end_time: self.state = 'done'
# return None else:
# elif self.plan_start_time and not self.plan_end_time: self.date_planned_finished = self.date_planned_start + timedelta(days=3)
# # 如果没有给出计划结束时间,则计划结束时间为计划开始时间+采购周期+缓冲期 self.state = 'done'
# # 采购周期 return {
# purchase_cycle = 3 'name': '排程甘特图',
# # 缓冲期 'type': 'ir.actions.act_window',
# buffer_period = 1 'res_model': 'sf.production.plan', # 要跳转的模型名称
# # 计划结束时间 = 计划开始时间 + 采购周期 + 缓冲期 'view_mode': 'gantt,tree,form', # 要显示的视图类型,可以是'form', 'tree', 'kanban', 'graph', 'calendar', 'pivot'等
# self.plan_end_time = self.plan_start_time + timedelta(days=purchase_cycle) + timedelta( 'target': 'current', # 跳转的目标窗口,可以是'current'或'new'
# days=buffer_period) }
# self.state = 'produce' # if self.production_line_id:
# return self.plan_end_time # if self.plan_start_time and self.plan_end_time:
# else: # return None
# return None # elif self.plan_start_time and not self.plan_end_time:
# # 后面要补充计划开始时间的计算方法 # # 如果没有给出计划结束时间,则计划结束时间为计划开始时间+采购周期+缓冲期
# # # 坯料预制时间 # # 采购周期
# # # pl_time = 0.5 # purchase_cycle = 3
# # # 采购周 # # 缓冲
# # purchase_cycle = 3 # buffer_period = 1
# # # 缓冲期 # # 计划结束时间 = 计划开始时间 + 采购周期 + 缓冲期
# # buffer_period = 1 # self.plan_end_time = self.plan_start_time + timedelta(days=purchase_cycle) + timedelta(
# # # 计划结束时间 = 计划开始时间 + 坯料预制时间 + 采购周期 + 缓冲期 # days=buffer_period)
# # # plan_end_time = plan_start_time + pl_time + purchase_cycle + buffer_period # self.state = 'produce'
# # # 计划结束时间 = 计划开始时间(是一个datatime) + 采购周期(Float) + 缓冲期(Float) # return self.plan_end_time
# # self.plan_end_time = self.plan_start_time + timedelta(days=purchase_cycle) + timedelta(days=buffer_period) # else:
# # return self.plan_end_time # return None
# else: # # 后面要补充计划开始时间的计算方法
# raise ValidationError('生产线为空!') # # # 坯料预制时间
# # # pl_time = 0.5
# # # 采购周期
# # purchase_cycle = 3
# # # 缓冲期
# # buffer_period = 1
# # # 计划结束时间 = 计划开始时间 + 坯料预制时间 + 采购周期 + 缓冲期
# # # plan_end_time = plan_start_time + pl_time + purchase_cycle + buffer_period
# # # 计划结束时间 = 计划开始时间(是一个datatime) + 采购周期(Float) + 缓冲期(Float)
# # self.plan_end_time = self.plan_start_time + timedelta(days=purchase_cycle) + timedelta(days=buffer_period)
# # return self.plan_end_time
# else:
# raise ValidationError('生产线为空!')
def cancel_production_schedule(self): def cancel_production_schedule(self):
self.date_planned_finished = False self.date_planned_finished = False
@@ -240,6 +242,7 @@ class sf_production_plan(models.Model):
except Exception as e: except Exception as e:
raise UserError(e) raise UserError(e)
# # sf生产排程 # # sf生产排程
# class sf_produce_plan(models.Model): # class sf_produce_plan(models.Model):
# _name = 'sf.produce.plan' # _name = 'sf.produce.plan'
@@ -266,3 +269,10 @@ class sf_production_plan(models.Model):
# plan_end_time = plan_start_time + pl_time # plan_end_time = plan_start_time + pl_time
# return plan_end_time # return plan_end_time
# #
# 机台作业计划
class machine_work_schedule(models.Model):
_name = 'sf.machine.schedule'
_description = '机台作业计划'
name = fields.Char(string='机台名')

View File

@@ -1,5 +1,6 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink 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,1,1,1 access_sf_production_plan,sf.production.plan,model_sf_production_plan,base.group_user,1,1,1,1
access_sf_machine_schedule,sf.machine.schedule,model_sf_machine_schedule,base.group_user,1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_sf_production_plan sf.production.plan model_sf_production_plan base.group_user 1 1 1 1
3 access_sf_machine_schedule sf.machine.schedule model_sf_machine_schedule base.group_user 1 1 1 1
4
5
6

View File

@@ -6,6 +6,7 @@
<field name="model">sf.production.plan</field> <field name="model">sf.production.plan</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<tree string="订单计划"> <tree string="订单计划">
<!-- <field name="selected" widget="boolean_toggle"/> -->
<!-- sequence、pl_no、pl_name、quantity、plan_start_time、plan_end_time、actual_start_time、actual_end_time、state、create_uid、create_date --> <!-- sequence、pl_no、pl_name、quantity、plan_start_time、plan_end_time、actual_start_time、actual_end_time、state、create_uid、create_date -->
<!-- <field name="sequence"/> --> <!-- <field name="sequence"/> -->
<field name="name"/> <field name="name"/>
@@ -25,9 +26,10 @@
<field name="arch" type="xml"> <field name="arch" type="xml">
<form string="订单计划"> <form string="订单计划">
<header> <header>
<button string="执行排程" name="do_production_schedule" type="object" class="oe_highlight" icon="fa-step-forward"/> <!-- <button string="执行排程" name="do_production_schedule" type="object" class="oe_highlight" icon="fa-step-forward"/> -->
<button string="销售单" name="test_sale_order" type="object" class="oe_highlight"/> <button string="执行排程" name="do_production_schedule" type="object" class="oe_highlight"/>
<button string="测试流程" name="liucheng_cs" type="object" class="oe_highlight"/> <!-- <button string="销售单" name="test_sale_order" type="object" class="oe_highlight"/> -->
<!-- <button string="测试流程" name="liucheng_cs" type="object" class="oe_highlight"/> -->
<!-- <field name="state" widget="statusbar" statusbar_visible="draft,produce"/> --> <!-- <field name="state" widget="statusbar" statusbar_visible="draft,produce"/> -->
</header> </header>
<sheet> <sheet>
@@ -212,6 +214,18 @@
<!-- </gantt> --> <!-- </gantt> -->
<!-- </field> --> <!-- </field> -->
<!-- </record> --> <!-- </record> -->
<record id="sf_machine_schedule_tree" model="ir.ui.view">
<field name="name">sf.machine.schedule.tree</field>
<field name="model">sf.machine.schedule</field>
<field name="arch" type="xml">
<tree string="机台作业计划">
<field name="name"/>
</tree>
</field>
</record>
<record id="sf_production_plan_action" model="ir.actions.act_window"> <record id="sf_production_plan_action" model="ir.actions.act_window">
<field name="name">制造订单生产计划</field> <field name="name">制造订单生产计划</field>
<field name="type">ir.actions.act_window</field> <field name="type">ir.actions.act_window</field>
@@ -254,6 +268,22 @@
<field name="view_mode">tree,form</field> <field name="view_mode">tree,form</field>
</record> </record>
<record model="ir.actions.act_window" id="action_machine_work_schedule">
<!-- 自定义额外的动作 -->
<field name="name">机台作业计划</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">sf.machine.schedule</field>
<field name="view_mode">tree</field>
<field name="help" type="html">
<p class="o_view_nocontent_smiling_face">
暂无机台作业计划
</p>
<p>
跟进请求的处理,并且和合作者沟通。
</p>
</field>
</record>
<menuitem <menuitem
id="mrp_custom_menu" id="mrp_custom_menu"
name="制造订单" name="制造订单"
@@ -275,6 +305,13 @@
action="sf_production_plan_action1" action="sf_production_plan_action1"
parent="sf_production_plan_menu" parent="sf_production_plan_menu"
/> />
<menuitem
id="machine_work_schedule"
name="机台作业计划"
sequence="200"
action="action_machine_work_schedule"
parent="sf_production_plan_menu"
/>
<!-- --><!-- 在现有菜单结构后面加入自定义的动作 --> <!-- --><!-- 在现有菜单结构后面加入自定义的动作 -->