生产计划优化

This commit is contained in:
mgw
2023-09-06 09:22:58 +08:00
parent e5213d06ae
commit 48e30865af
3 changed files with 104 additions and 56 deletions

View File

@@ -1,12 +1,10 @@
# -*- coding: utf-8 -*-
import base64
import json, requests
from odoo import models, fields, api, _
from datetime import datetime, timedelta
from odoo.exceptions import UserError, ValidationError
import json, requests, logging
# sf排程
class sf_production_plan(models.Model):
@@ -15,6 +13,7 @@ class sf_production_plan(models.Model):
_description = 'sf_production_plan'
name = fields.Char(string='名称')
# selected = fields.Boolean(default=False)
production_id = fields.Many2one('mrp.production', '关联制造订单')
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,
@@ -146,57 +145,60 @@ class sf_production_plan(models.Model):
# 当不设置计划结束时间时,增加计算计划结束时间的方法,根据采购周期加缓冲期两个值来算就可以了
def do_production_schedule(self):
aa = self.env['mrp.production'].sudo().search([('name', '=', self.name)])
workorder_time = 0
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'
if not self.production_line_id:
raise ValidationError("未选择生产线")
else:
self.date_planned_finished = self.date_planned_start + timedelta(days=3)
self.state = 'done'
return {
'name': '排程甘特图',
'type': 'ir.actions.act_window',
'res_model': 'sf.production.plan', # 要跳转的模型名称
'view_mode': 'gantt,tree,form', # 要显示的视图类型,可以是'form', 'tree', 'kanban', 'graph', 'calendar', 'pivot'等
'target': 'current', # 跳转的目标窗口,可以是'current'或'new'
}
# if self.production_line_id:
# if self.plan_start_time and self.plan_end_time:
# return None
# elif self.plan_start_time and not self.plan_end_time:
# # 如果没有给出计划结束时间,则计划结束时间为计划开始时间+采购周期+缓冲期
# # 采购周期
# purchase_cycle = 3
# # 缓冲期
# buffer_period = 1
# # 计划结束时间 = 计划开始时间 + 采购周期 + 缓冲期
# self.plan_end_time = self.plan_start_time + timedelta(days=purchase_cycle) + timedelta(
# days=buffer_period)
# self.state = 'produce'
# return self.plan_end_time
# else:
# return None
# # 后面要补充计划开始时间的计算方法
# # # 坯料预制时间
# # # 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('生产线为空!')
aa = self.env['mrp.production'].sudo().search([('name', '=', self.name)])
workorder_time = 0
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:
self.date_planned_finished = self.date_planned_start + timedelta(days=3)
self.state = 'done'
return {
'name': '排程甘特图',
'type': 'ir.actions.act_window',
'res_model': 'sf.production.plan', # 要跳转的模型名称
'view_mode': 'gantt,tree,form', # 要显示的视图类型,可以是'form', 'tree', 'kanban', 'graph', 'calendar', 'pivot'等
'target': 'current', # 跳转的目标窗口,可以是'current'或'new'
}
# if self.production_line_id:
# if self.plan_start_time and self.plan_end_time:
# return None
# elif self.plan_start_time and not self.plan_end_time:
# # 如果没有给出计划结束时间,则计划结束时间为计划开始时间+采购周期+缓冲期
# # 采购周期
# purchase_cycle = 3
# # 缓冲
# buffer_period = 1
# # 计划结束时间 = 计划开始时间 + 采购周期 + 缓冲期
# self.plan_end_time = self.plan_start_time + timedelta(days=purchase_cycle) + timedelta(
# days=buffer_period)
# self.state = 'produce'
# return self.plan_end_time
# else:
# return None
# # 后面要补充计划开始时间的计算方法
# # # 坯料预制时间
# # # 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):
self.date_planned_finished = False
@@ -240,6 +242,7 @@ class sf_production_plan(models.Model):
except Exception as e:
raise UserError(e)
# # sf生产排程
# class sf_produce_plan(models.Model):
# _name = 'sf.produce.plan'
@@ -266,3 +269,10 @@ class sf_production_plan(models.Model):
# plan_end_time = plan_start_time + pl_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
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="arch" type="xml">
<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 -->
<!-- <field name="sequence"/> -->
<field name="name"/>
@@ -25,9 +26,10 @@
<field name="arch" type="xml">
<form string="订单计划">
<header>
<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="liucheng_cs" type="object" class="oe_highlight"/>
<!-- <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"/>
<!-- <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"/> -->
</header>
<sheet>
@@ -212,6 +214,18 @@
<!-- </gantt> -->
<!-- </field> -->
<!-- </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">
<field name="name">制造订单生产计划</field>
<field name="type">ir.actions.act_window</field>
@@ -254,6 +268,22 @@
<field name="view_mode">tree,form</field>
</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
id="mrp_custom_menu"
name="制造订单"
@@ -275,6 +305,13 @@
action="sf_production_plan_action1"
parent="sf_production_plan_menu"
/>
<menuitem
id="machine_work_schedule"
name="机台作业计划"
sequence="200"
action="action_machine_work_schedule"
parent="sf_production_plan_menu"
/>
<!-- --><!-- 在现有菜单结构后面加入自定义的动作 -->