基础排程基本完成

This commit is contained in:
mgw
2023-08-30 17:50:43 +08:00
parent e3f58ccee8
commit 41566a4d74
7 changed files with 276 additions and 92 deletions

View File

@@ -2,3 +2,4 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details. # Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import models from . import models
from . import controllers

View File

@@ -24,7 +24,8 @@
'web.assets_qweb': [ 'web.assets_qweb': [
], ],
'web.assets_backend': [ 'web.assets_backend': [
'sf_plan/static/src/scss/gannt_change.scss' 'sf_plan/static/src/scss/gannt_change.scss',
'sf_plan/static/src/css/button_color.css'
], ],
}, },

View File

@@ -0,0 +1,2 @@
from .import controllers

View File

@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
import json
import logging
from odoo import http
from odoo.http import request
class ProductionPlan(http.Controller):
@http.route('/api/production/plan', type='http', auth='none', methods=['GET', 'POST'], csrf=False,
cors="*")
def schedule_orders(self, **kw):
"""
排程订单
"""
logging.info('schedule_orders', kw)

View File

@@ -1,19 +1,35 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import base64
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):
_name = 'sf.production.plan' _name = 'sf.production.plan'
# _inherit = 'mrp.production'
_description = 'sf_production_plan' _description = 'sf_production_plan'
name = fields.Char(string='名称', size=64) name = fields.Char(string='名称')
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,
default=fields.Datetime.now)
date_planned_finished = fields.Datetime(string='计划结束时间')
state = fields.Selection([
('draft', '未排程'), ('done', '已排程')], string='状态', copy=False, index=True, readonly=True,
store=True, tracking=True)
product_id = fields.Many2one('product.product', '关联产品')
origin = fields.Char(string='来源')
# 序号、坯料编号、坯料名称、材质、数量、长度、宽度、厚度、直径、计划开始时间、计划结束时间、状态(已产出与待产出)、操作、创建人、创建时间、客户名称、订单号、行号、长度、宽度、厚度、直径、交货数量、交货日期 # 序号、坯料编号、坯料名称、材质、数量、长度、宽度、厚度、直径、计划开始时间、计划结束时间、状态(已产出与待产出)、操作、创建人、创建时间、客户名称、订单号、行号、长度、宽度、厚度、直径、交货数量、交货日期
# sequence = fields.Integer(string='序号', required=True, copy=False, readonly=True, index=True, # sequence = fields.Integer(string='序号', required=True, copy=False, readonly=True, index=True,
# default=lambda self: self.env['ir.sequence'].sudo().next_by_code('sf.pl.plan')) # default=lambda self: self.env['ir.sequence'].sudo().next_by_code('sf.pl.plan'))
sequence = fields.Integer(string='序号', required=True, copy=False, readonly=True, index=True) sequence = fields.Integer(string='序号', copy=False, readonly=True, index=True)
current_operation_name = fields.Char(string='当前工序名称', size=64, default='生产计划') current_operation_name = fields.Char(string='当前工序名称', size=64, default='生产计划')
production_line_id = fields.Many2one('sf.production.line', string='生产线') production_line_id = fields.Many2one('sf.production.line', string='生产线')
@@ -21,6 +37,24 @@ class sf_production_plan(models.Model):
# ('未排程', '未排程'), ('已排程', '已排程')], string='State', copy=False, index=True, readonly=True, # ('未排程', '未排程'), ('已排程', '已排程')], string='State', copy=False, index=True, readonly=True,
# store=True, tracking=True) # store=True, tracking=True)
# orderpoint_id = fields.Many2one('stock.warehouse.orderpoint', compute='_compute_orderpoint_id')
# location_src_id = fields.Many2one('stock.location', 'Components Location', compute='_compute_orderpoint_id', active=False)
# location_dest_id = fields.Many2one('stock.location', 'Finished Products Location', compute='_compute_orderpoint_id')
# picking_type_id = fields.Many2one('stock.picking.type', 'Operation Type', compute='_compute_orderpoint_id')
# move_dest_ids = fields.One2many('stock.move', 'created_production_id', compute='_compute_orderpoint_id')
@api.model
def _compute_orderpoint_id(self):
pass
def test_sale_order(self):
company_id = self.env.ref('base.main_company').sudo()
date = datetime.today()
aaa = self.env['sale.order'].with_user(self.env.ref("base.user_admin")).sale_order_create(
company_id, 'delivery_name', 'delivery_telephone', 'delivery_address',
date)
print('aaa', aaa)
# 当不设置计划结束时间时,增加计算计划结束时间的方法,根据采购周期加缓冲期两个值来算就可以了 # 当不设置计划结束时间时,增加计算计划结束时间的方法,根据采购周期加缓冲期两个值来算就可以了
def action_view_production_schedule(self): def action_view_production_schedule(self):
self.ensure_one() self.ensure_one()
@@ -40,17 +74,16 @@ class sf_production_plan(models.Model):
else: else:
return None return None
def cancel_plan(self): def cancel_plan(self):
self.ensure_one() self.ensure_one()
self.date_planned_finished = None self.date_planned_finished = None
self.state = 'confirmed' self.state = 'draft'
@api.model # @api.model
def create(self, vals): # def create(self, vals):
if 'sequence' not in vals: # if 'sequence' not in vals:
vals['sequence'] = self.env['sf.production.plan'].search_count([]) + 1 # vals['sequence'] = self.env['sf.production.plan'].search_count([]) + 1
return super().create(vals) # return super().create(vals)
def unlink(self): def unlink(self):
sequence_to_reorder = self.mapped('sequence') sequence_to_reorder = self.mapped('sequence')
@@ -89,18 +122,18 @@ class sf_production_plan(models.Model):
# pl_no = fields.Char(string='坯料编号', required=True, default=_get_pl_no, readonly=True) # pl_no = fields.Char(string='坯料编号', required=True, default=_get_pl_no, readonly=True)
# pl_name = fields.Char(string='坯料名称', size=64, required=True) # pl_name = fields.Char(string='坯料名称', size=64, required=True)
# material = fields.Many2one('sf.production.materials', string='材质', required=True) # material = fields.Many2one('sf.production.materials', string='材质', required=True)
quantity = fields.Float(string='数量', required=True) # quantity = fields.Float(string='数量', required=True)
# length = fields.Float(string='长度', required=True) # length = fields.Float(string='长度', required=True)
# width = fields.Float(string='宽度', required=True) # width = fields.Float(string='宽度', required=True)
# thickness = fields.Float(string='厚度', required=True) # thickness = fields.Float(string='厚度', required=True)
# diameter = fields.Float(string='直径', required=True) # diameter = fields.Float(string='直径', required=True)
plan_start_time = fields.Datetime(string='计划开始时间') # plan_start_time = fields.Datetime(string='计划开始时间')
plan_end_time = fields.Datetime(string='计划结束时间') # plan_end_time = fields.Datetime(string='计划结束时间')
state = fields.Selection([ # state = fields.Selection([
('draft', '待排程'), # ('draft', '待排程'),
('produce', '已排程'), # ('produce', '已排程'),
('done', '已产出'), # ('done', '已产出'),
], string='状态', copy=False, index=True, default='draft') # ], string='状态', copy=False, index=True, default='draft')
# customer_name = fields.Char(string='客户名称', size=64) # customer_name = fields.Char(string='客户名称', size=64)
# order_no = fields.Char(string='订单号', size=64) # order_no = fields.Char(string='订单号', size=64)
# line_no = fields.Char(string='行号', size=64) # line_no = fields.Char(string='行号', size=64)
@@ -113,40 +146,99 @@ class sf_production_plan(models.Model):
# 当不设置计划结束时间时,增加计算计划结束时间的方法,根据采购周期加缓冲期两个值来算就可以了 # 当不设置计划结束时间时,增加计算计划结束时间的方法,根据采购周期加缓冲期两个值来算就可以了
def do_production_schedule(self): def do_production_schedule(self):
if self.production_line_id: aa = self.env['mrp.production'].sudo().search([('name', '=', self.name)])
if self.plan_start_time and self.plan_end_time: workorder_time = 0
return None print(aa.workorder_ids)
elif self.plan_start_time and not self.plan_end_time: print(type(aa.workorder_ids))
# 如果没有给出计划结束时间,则计划结束时间为计划开始时间+采购周期+缓冲期 if aa.workorder_ids:
# 采购周期 for item in aa.workorder_ids:
purchase_cycle = 3 current_workorder = self.env['mrp.workorder'].sudo().search([('id', '=', item.id)])
# 缓冲期 workorder_time += current_workorder.duration_expected
buffer_period = 1 print(workorder_time)
# 计划结束时间 = 计划开始时间 + 采购周期 + 缓冲期 self.date_planned_finished = self.date_planned_start + timedelta(minutes=workorder_time)
self.plan_end_time = self.plan_start_time + timedelta(days=purchase_cycle) + timedelta(days=buffer_period) self.state = 'done'
self.state = 'produce'
return self.plan_end_time
else: else:
return None self.date_planned_finished = self.date_planned_start + timedelta(days=3)
# 后面要补充计划开始时间的计算方法 self.state = 'done'
# # 坯料预制时间 return {
# # pl_time = 0.5 '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 # purchase_cycle = 3
# # 缓冲期 # # 缓冲期
# buffer_period = 1 # buffer_period = 1
# # 计划结束时间 = 计划开始时间 + 坯料预制时间 + 采购周期 + 缓冲期 # # 计划结束时间 = 计划开始时间 + 采购周期 + 缓冲期
# # plan_end_time = plan_start_time + pl_time + purchase_cycle + buffer_period # self.plan_end_time = self.plan_start_time + timedelta(days=purchase_cycle) + timedelta(
# # 计划结束时间 = 计划开始时间(是一个datatime) + 采购周期(Float) + 缓冲期(Float) # days=buffer_period)
# self.plan_end_time = self.plan_start_time + timedelta(days=purchase_cycle) + timedelta(days=buffer_period) # self.state = 'produce'
# return self.plan_end_time # return self.plan_end_time
else: # else:
raise ValidationError('生产线为空!') # 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): def cancel_production_schedule(self):
self.plan_end_time = False self.date_planned_finished = False
self.state = 'draft' self.state = 'draft'
return self.plan_end_time return self.date_planned_finished
def liucheng_cs(self):
res = {'order_number': '123', 'delivery_end_date': str(datetime.now()),
'delivery_name': '机企猫', 'delivery_telephone': '18943919239',
'delivery_address': '新时空大厦',
'bfm_process_order_list': []}
aa = self.env['ir.attachment'].search([('id', '=', 631)])
temp = self.env['product.template'].search([('id', '=', 47)])
item = aa.datas.decode('utf-8')
val = {
'model_long': 3,
'model_width': 1,
'model_height': 1,
'model_volume': 3,
'model_machining_precision': '0.10',
'model_name': aa.name,
'model_data': base64.b64encode(aa.datas).decode('utf-8'),
'model_file': base64.b64encode(temp.model_file).decode('utf-8'),
'texture_code': '001',
'texture_type_code': '001001',
# 'surface_process_code': self.env['jikimo.surface.process']._json_surface_process_code(item),
'process_parameters_code': 'R',
'price': 20,
'number': 2,
'total_amount': 100,
'remark': '这只是测试',
'barcode': 123456789,
}
res['bfm_process_order_list'].append(val)
url = '/api/bfm_process_order/list'
res['bfm_process_order_list'] = json.dumps(res['bfm_process_order_list'])
try:
ret = requests.post(('http://localhost:1069' + url), json={}, data=res)
# aa = json.loads(ret.text)
print(ret)
except Exception as e:
raise UserError(e)
# # sf生产排程 # # sf生产排程
# class sf_produce_plan(models.Model): # class sf_produce_plan(models.Model):

View File

@@ -0,0 +1,8 @@
.schedule_done {
background-color: #69c17d;
color: white;
}
.schedule_cancel {
background-color: #ffc54d;
color: black;
}

View File

@@ -7,14 +7,14 @@
<field name="arch" type="xml"> <field name="arch" type="xml">
<tree string="订单计划"> <tree string="订单计划">
<!-- 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"/>
<field name="quantity"/> <field name="product_qty"/>
<field name="plan_start_time"/> <field name="date_planned_start"/>
<field name="plan_end_time"/> <field name="date_planned_finished"/>
<field name="state"/> <field name="state" widget="badge" decoration-warning="state == 'draft'" decoration-success="state == 'done'"/>
<button name="do_production_schedule" string="生产排程" type="object" attrs="{'invisible': [('state', 'not in', ['draft'])]}"/> <button name="do_production_schedule" class="btn schedule_done" string="生产排程" type="object" attrs="{'invisible': [('state', 'not in', ['draft'])]}"/>
<button name="cancel_production_schedule" string="取消排程" type="object" attrs="{'invisible': [('state', 'not in', ['produce'])]}"/> <button name="cancel_production_schedule" class="btn schedule_cancel" string="取消排程" type="object" attrs="{'invisible': [('state', 'not in', ['done'])]}"/>
</tree> </tree>
</field> </field>
</record> </record>
@@ -25,8 +25,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"/> <button string="执行排程" name="do_production_schedule" type="object" class="oe_highlight" icon="fa-step-forward"/>
<field name="state" widget="statusbar" statusbar_visible="draft,produce"/> <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> </header>
<sheet> <sheet>
<div class="oe_title"> <div class="oe_title">
@@ -36,10 +38,12 @@
</div> </div>
<group> <group>
<group string="基本信息"> <group string="基本信息">
<field name="name"/> <field name="production_id"/>
<field name="quantity"/> <field name="product_id"/>
<field name="plan_start_time"/> <field name="origin"/>
<field name="plan_end_time"/> <field name="product_qty"/>
<field name="date_planned_start"/>
<field name="date_planned_finished"/>
<field name="state"/> <field name="state"/>
<field name="production_line_id"/> <field name="production_line_id"/>
</group> </group>
@@ -87,9 +91,9 @@
<field name="arch" type="xml"> <field name="arch" type="xml">
<search string="订单计划"> <search string="订单计划">
<field name="name"/> <field name="name"/>
<field name="quantity"/> <field name="product_qty"/>
<field name="plan_start_time"/> <field name="date_planned_start"/>
<field name="plan_end_time"/> <field name="date_planned_finished"/>
<field name="state"/> <field name="state"/>
<searchpanel class="account_root"> <searchpanel class="account_root">
<field name="state" icon="fa-filter"/> <field name="state" icon="fa-filter"/>
@@ -102,7 +106,7 @@
<field name="name">sf.production.plan.gantt</field> <field name="name">sf.production.plan.gantt</field>
<field name="model">sf.production.plan</field> <field name="model">sf.production.plan</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<gantt class="o_mrp_workorder_gantt" date_stop="plan_end_time" date_start="plan_start_time" <gantt class="o_mrp_workorder_gantt" date_stop="date_planned_finished" date_start="date_planned_start"
string="制造订单生产计划" default_group_by="production_line_id" create="0" string="制造订单生产计划" default_group_by="production_line_id" create="0"
delete="0" sample="1" delete="0" sample="1"
display_unavailability="1" display_unavailability="1"
@@ -112,9 +116,9 @@
form_view_id="sf_production_plan_form"> form_view_id="sf_production_plan_form">
<field name="name"/> <field name="name"/>
<field name="quantity"/> <field name="product_qty"/>
<field name="plan_start_time"/> <field name="date_planned_start"/>
<field name="plan_end_time"/> <field name="date_planned_finished"/>
<field name="state"/> <field name="state"/>
<templates> <templates>
<div t-name="gantt-popover" class="container-fluid"> <div t-name="gantt-popover" class="container-fluid">
@@ -135,7 +139,7 @@
</li> </li>
<li> <li>
<strong>数量:</strong> <strong>数量:</strong>
<t t-out="quantity"/> <t t-out="product_qty"/>
</li> </li>
<li> <li>
<strong>状态:</strong> <strong>状态:</strong>
@@ -215,12 +219,71 @@
<field name="view_mode">gantt,tree,form</field> <field name="view_mode">gantt,tree,form</field>
</record> </record>
<!-- 这个也是制造订单生产计划只是把tree视图放在了默认位置 -->
<record id="sf_production_plan_action1" model="ir.actions.act_window">
<field name="name">制造订单生产计划</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">sf.production.plan</field>
<field name="view_mode">tree,gantt,form</field>
</record>
<menuitem <menuitem
id="sf_production_plan_menu" id="sf_production_plan_menu"
name="制造订单生产计划" name="计划"
parent="mrp_workorder.mrp_workorder_menu_planning" sequence="150"
sequence="10"
action="sf_production_plan_action" action="sf_production_plan_action"
/> />
<!-- <record model="ir.ui.menu" id="mrp_custom_menu" inherit_id="mrp.menu_mrp_manufacturing"> -->
<!-- <field name="name">Custom Manufacturing Orders</field> -->
<!-- <field name="action" ref="mrp.mrp_manufacturing_action"/> -->
<!-- --><!-- 扩展现有的动作 --><!-- -->
<!-- </record> -->
<record model="ir.actions.act_window" id="mrp_custom_action">
<!-- 自定义额外的动作 -->
<field name="name">制造订单</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">mrp.production</field>
<field name="view_mode">tree,form</field>
</record>
<record model="ir.actions.act_window" id="sale_custom_action">
<!-- 自定义额外的动作 -->
<field name="name">报价单</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">sale.order</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem
id="mrp_custom_menu"
name="制造订单"
sequence="150"
action="mrp_custom_action"
parent="sf_production_plan_menu"
/>
<menuitem
id="sale_custom_menu"
name="报价单"
sequence="50"
action="sale_custom_action"
parent="sf_production_plan_menu"
/>
<menuitem
id="schedule_custom_menu"
name="排程单"
sequence="180"
action="sf_production_plan_action1"
parent="sf_production_plan_menu"
/>
<!-- --><!-- 在现有菜单结构后面加入自定义的动作 -->
<!-- <menuitem -->
<!-- id="mrp_custom_menuitem" -->
<!-- name="My Custom Menuitem" -->
<!-- sequence="20" -->
<!-- action="mrp_custom_action"/> -->
<!-- --><!-- 自定义额外的菜单项 --><!-- -->
<!-- </field> -->
</data> </data>
</odoo> </odoo>