From 7e071151a8a73b6295bd5ecc80b0795c220348ee Mon Sep 17 00:00:00 2001
From: mgw <1392924357@qq.com>
Date: Fri, 25 Aug 2023 10:43:22 +0800
Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=88=B6=E9=80=A0=E8=AE=A2?=
=?UTF-8?q?=E5=8D=95=E5=A4=84=E6=8E=92=E7=A8=8B=E7=9B=B8=E5=85=B3=E7=9A=84?=
=?UTF-8?q?=E9=83=A8=E5=88=86=EF=BC=8C=E6=8E=92=E7=A8=8B=E6=A8=A1=E5=9D=97?=
=?UTF-8?q?=E6=9E=B6=E6=9E=84=E6=94=B9=E9=80=A0=E5=AE=8C=E6=88=90?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
sf_manufacturing/models/mrp_production.py | 63 +----
.../views/mrp_production_addional_change.xml | 52 ++--
sf_plan/models/custom_plan.py | 130 ++++++----
sf_plan/security/ir.model.access.csv | 2 +-
sf_plan/views/view.xml | 240 +++++++++---------
5 files changed, 236 insertions(+), 251 deletions(-)
diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py
index 196baebf..b6d774a3 100644
--- a/sf_manufacturing/models/mrp_production.py
+++ b/sf_manufacturing/models/mrp_production.py
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
import re
-from datetime import datetime, timedelta
from odoo import api, fields, models, _
@@ -15,66 +14,6 @@ class MrpProduction(models.Model):
model_file = fields.Binary('模型文件', related='product_id.model_file')
schedule_state = fields.Selection([('未排', '未排'), ('已排', '已排')],
string='排程状态', default='未排')
- # state = fields.Selection(selection_add=[('未排程', '未排程'), ('已排程', '已排程')])
- # 生产线
- production_line_id = fields.Many2one('sf.production.line', string='生产线')
- state = fields.Selection([
- ('draft', 'Draft'),
- ('confirmed', 'Confirmed'),
- ('未排程', '未排程'), ('已排程', '已排程'),
- ('progress', 'In Progress'),
- ('to_close', 'To Close'),
- ('done', 'Done'),
- ('cancel', 'Cancelled')], string='State',
- compute='_compute_state', copy=False, index=True, readonly=True,
- store=True, tracking=True,
- help=" * Draft: The MO is not confirmed yet.\n"
- " * Confirmed: The MO is confirmed, the stock rules and the reordering of the components are trigerred.\n"
- " * In Progress: The production has started (on the MO or on the WO).\n"
- " * To Close: The production is done, the MO has to be closed.\n"
- " * Done: The MO is closed, the stock moves are posted. \n"
- " * Cancelled: The MO has been cancelled, can't be confirmed anymore.")
-
- @api.depends('company_id', 'date_planned_start', 'is_planned', 'product_id')
- def _compute_date_planned_finished(self):
- pass
-
- # 当不设置计划结束时间时,增加计算计划结束时间的方法,根据采购周期加缓冲期两个值来算就可以了
- def action_view_production_schedule(self):
- self.ensure_one()
- if self.date_planned_start and self.date_planned_finished:
- return None
- elif self.date_planned_start and not self.date_planned_finished:
- # 如果没有给出计划结束时间,则计划结束时间为计划开始时间+采购周期+缓冲期
- # 采购周期
- purchase_cycle = 3
- # 缓冲期
- buffer_period = 1
- # 计划结束时间 = 计划开始时间 + 采购周期 + 缓冲期
- self.date_planned_finished = self.date_planned_start + timedelta(days=purchase_cycle) + timedelta(
- days=buffer_period)
- self.state = '已排程'
- return self.date_planned_finished
- else:
- return None
- # 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)
- # return self.plan_end_time
- # else:
- # return None
-
- def cancel_plan(self):
- self.ensure_one()
- self.date_planned_finished = None
- self.state = 'confirmed'
@api.depends('request_ids')
def _compute_maintenance_count(self):
@@ -400,7 +339,7 @@ class MrpProduction(models.Model):
current_sequence += 1
if work.name == '获取CNC加工程序':
work.button_start()
- #work.fetchCNC()
+ # work.fetchCNC()
# 创建工单并进行排序
def _create_workorder(self):
diff --git a/sf_manufacturing/views/mrp_production_addional_change.xml b/sf_manufacturing/views/mrp_production_addional_change.xml
index 9200c980..b326f288 100644
--- a/sf_manufacturing/views/mrp_production_addional_change.xml
+++ b/sf_manufacturing/views/mrp_production_addional_change.xml
@@ -16,7 +16,6 @@
-
@@ -43,36 +42,35 @@
decoration-warning="reservation_state != 'assigned' and components_availability_state in ('expected', 'available')"
decoration-danger="reservation_state != 'assigned' and components_availability_state == 'late'"/>
-
-
-
-
-
-
-
-
- custom.mrp.production.form
- mrp.production
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
custom.mrp.production.select
mrp.production
diff --git a/sf_plan/models/custom_plan.py b/sf_plan/models/custom_plan.py
index 6ac1b08e..2a2be736 100644
--- a/sf_plan/models/custom_plan.py
+++ b/sf_plan/models/custom_plan.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from odoo import models, fields, api, _
from datetime import datetime, timedelta
+from odoo.exceptions import UserError, ValidationError
# sf排程
@@ -16,10 +17,39 @@ class sf_production_plan(models.Model):
current_operation_name = fields.Char(string='当前工序名称', size=64, default='生产计划')
production_line_id = fields.Many2one('sf.production.line', string='生产线')
+ # state = fields.Selection([
+ # ('未排程', '未排程'), ('已排程', '已排程')], string='State', copy=False, index=True, readonly=True,
+ # store=True, tracking=True)
+
+ # 当不设置计划结束时间时,增加计算计划结束时间的方法,根据采购周期加缓冲期两个值来算就可以了
+ def action_view_production_schedule(self):
+ self.ensure_one()
+ if self.date_planned_start and self.date_planned_finished:
+ return None
+ elif self.date_planned_start and not self.date_planned_finished:
+ # 如果没有给出计划结束时间,则计划结束时间为计划开始时间+采购周期+缓冲期
+ # 采购周期
+ purchase_cycle = 3
+ # 缓冲期
+ buffer_period = 1
+ # 计划结束时间 = 计划开始时间 + 采购周期 + 缓冲期
+ self.date_planned_finished = self.date_planned_start + timedelta(days=purchase_cycle) + timedelta(
+ days=buffer_period)
+ self.state = '已排程'
+ return self.date_planned_finished
+ else:
+ return None
+
+
+ def cancel_plan(self):
+ self.ensure_one()
+ self.date_planned_finished = None
+ self.state = 'confirmed'
+
@api.model
def create(self, vals):
if 'sequence' not in vals:
- vals['sequence'] = self.env['sf.pl.plan'].search_count([]) + 1
+ vals['sequence'] = self.env['sf.production.plan'].search_count([]) + 1
return super().create(vals)
def unlink(self):
@@ -32,7 +62,7 @@ class sf_production_plan(models.Model):
# 生成编码
def _get_pl_no(self):
- sf_pl_no = self.env['sf.pl.plan'].sudo().search(
+ sf_pl_no = self.env['sf.production.plan'].sudo().search(
[('pl_no', '!=', '')],
limit=1,
order="id desc")
@@ -56,57 +86,67 @@ class sf_production_plan(models.Model):
return num
- pl_no = fields.Char(string='坯料编号', required=True, default=_get_pl_no, readonly=True)
- pl_name = fields.Char(string='坯料名称', size=64, required=True)
- material = fields.Many2one('sf.production.materials', string='材质', required=True)
+ # pl_no = fields.Char(string='坯料编号', required=True, default=_get_pl_no, readonly=True)
+ # pl_name = fields.Char(string='坯料名称', size=64, required=True)
+ # material = fields.Many2one('sf.production.materials', string='材质', required=True)
quantity = fields.Float(string='数量', required=True)
- length = fields.Float(string='长度', required=True)
- width = fields.Float(string='宽度', required=True)
- thickness = fields.Float(string='厚度', required=True)
- diameter = fields.Float(string='直径', required=True)
+ # length = fields.Float(string='长度', required=True)
+ # width = fields.Float(string='宽度', required=True)
+ # thickness = fields.Float(string='厚度', required=True)
+ # diameter = fields.Float(string='直径', required=True)
plan_start_time = fields.Datetime(string='计划开始时间')
plan_end_time = fields.Datetime(string='计划结束时间')
state = fields.Selection([
- ('draft', '待产出'),
- ('produce', '已产出'),
+ ('draft', '待排程'),
+ ('produce', '已排程'),
+ ('done', '已产出'),
], string='状态', copy=False, index=True, default='draft')
- customer_name = fields.Char(string='客户名称', size=64)
- order_no = fields.Char(string='订单号', size=64)
- line_no = fields.Char(string='行号', size=64)
- delivery_length = fields.Float(string='交货长度')
- delivery_width = fields.Float(string='交货宽度')
- delivery_thickness = fields.Float(string='交货厚度')
- delivery_diameter = fields.Float(string='交货直径')
- delivery_quantity = fields.Float(string='交货数量')
- delivery_date = fields.Datetime(string='交货日期', related='plan_end_time', readonly=False, store=True)
+ # customer_name = fields.Char(string='客户名称', size=64)
+ # order_no = fields.Char(string='订单号', size=64)
+ # line_no = fields.Char(string='行号', size=64)
+ # delivery_length = fields.Float(string='交货长度')
+ # delivery_width = fields.Float(string='交货宽度')
+ # delivery_thickness = fields.Float(string='交货厚度')
+ # delivery_diameter = fields.Float(string='交货直径')
+ # delivery_quantity = fields.Float(string='交货数量')
+ # delivery_date = fields.Datetime(string='交货日期', related='plan_end_time', readonly=False, store=True)
# 当不设置计划结束时间时,增加计算计划结束时间的方法,根据采购周期加缓冲期两个值来算就可以了
- def get_plan_end_time(self):
- 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)
- return self.plan_end_time
+ def do_production_schedule(self):
+ 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:
- 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
+ raise ValidationError('生产线为空!')
+
+ def cancel_production_schedule(self):
+ self.plan_end_time = False
+ self.state = 'draft'
+ return self.plan_end_time
# # sf生产排程
# class sf_produce_plan(models.Model):
diff --git a/sf_plan/security/ir.model.access.csv b/sf_plan/security/ir.model.access.csv
index 7effd7c3..b1578586 100644
--- a/sf_plan/security/ir.model.access.csv
+++ b/sf_plan/security/ir.model.access.csv
@@ -1,5 +1,5 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
-access_sf_pl_plan,sf.pl.plan,model_sf_pl_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
diff --git a/sf_plan/views/view.xml b/sf_plan/views/view.xml
index 8753e460..22e72c30 100644
--- a/sf_plan/views/view.xml
+++ b/sf_plan/views/view.xml
@@ -1,101 +1,117 @@
-
- sf.pl.plan.tree
- sf.pl.plan
+
+ sf.production.plan.tree
+ sf.production.plan
-
+
-
-
+
-
-
+
+
-
- sf.pl.plan.form
- sf.pl.plan
+
+ sf.production.plan.form
+ sf.production.plan
-
-
- sf.pl.plan.gantt
- sf.pl.plan
+
+
+ sf.production.plan.search
+ sf.production.plan
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ sf.production.plan.gantt
+ sf.production.plan
+ color="production_line_id"
+ decoration-success="state == 'done'"
+ progress_bar="name"
+ form_view_id="sf_production_plan_form">
-
-
+
@@ -114,21 +130,13 @@
- 坯料编号:
-
-
-
- 坯料名称:
-
+ 名称:
+
数量:
-
- 材质:
-
-
状态:
@@ -149,70 +157,70 @@
-
- sf.production.plan.gantt
- mrp.production
-
-
-
-
-
-
-
-
-
-
-
-
- -
- 开始时间:
-
-
- -
- 结束时间:
-
-
- -
- 数量:
-
-
- -
- 状态:
- 已取消
- 已完成
- 已排程
- 其他状态
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
制造订单生产计划
ir.actions.act_window
- mrp.production
+ sf.production.plan
gantt,tree,form