Compare commits

...

66 Commits

Author SHA1 Message Date
胡尧
4099756d15 Accept Merge Request #2255: (feature/6711 -> develop)
Merge Request: 日计划量对工单id去重

Created By: @胡尧
Accepted By: @胡尧
URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/2255?initial=true
2025-06-25 08:44:32 +08:00
胡尧
133eac4a5c 日计划量对工单id去重 2025-06-25 08:43:59 +08:00
禹翔辉
91bad533c3 Accept Merge Request #2254: (feature/调拨验证优化 -> develop)
Merge Request: 调拨单需验证质检单数量方法优化

Created By: @禹翔辉
Reviewed By: @胡尧
Approved By: @胡尧 
Accepted By: @禹翔辉
URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/2254
2025-06-24 17:10:41 +08:00
yuxianghui
f5ed94866b 调拨单需验证质检单数量方法优化 2025-06-24 16:59:38 +08:00
胡尧
b70f280c6e Accept Merge Request #2253: (feature/6711 -> develop)
Merge Request: 修复明细接口bug

Created By: @胡尧
Accepted By: @胡尧
URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/2253?initial=true
2025-06-24 15:56:52 +08:00
胡尧
9922402b3b 修复明细接口bug 2025-06-24 15:56:33 +08:00
胡尧
152657e41b Accept Merge Request #2252: (feature/6711 -> develop)
Merge Request: 修改未完成订单明细的判断逻辑

Created By: @胡尧
Accepted By: @胡尧
URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/2252?initial=true
2025-06-24 15:51:17 +08:00
胡尧
0a79a4e336 修改未完成订单明细的判断逻辑 2025-06-24 15:50:45 +08:00
胡尧
174af13a58 Accept Merge Request #2251: (feature/6711 -> develop)
Merge Request: 修改工单状态对应名字

Created By: @胡尧
Accepted By: @胡尧
URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/2251?initial=true
2025-06-24 15:35:42 +08:00
胡尧
00922e3674 修改工单状态对应名字 2025-06-24 15:35:19 +08:00
胡尧
3b60db56de Accept Merge Request #2250: (feature/6711 -> develop)
Merge Request: 修改大屏获取订单详情接口

Created By: @胡尧
Accepted By: @胡尧
URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/2250
2025-06-24 14:52:47 +08:00
胡尧
2a330a4bd8 修改大屏获取订单详情接口 2025-06-24 14:52:03 +08:00
yuxianghui
579b7138e7 需求 调拨单关联校验是否完成质量检查时,可先排除欠单量后再校验 开发 2025-06-24 14:41:49 +08:00
yuxianghui
98f8430c45 Revert "需求 调拨单关联校验是否完成质量检查时,可先排除欠单量后再校验 开发"
This reverts commit 912847ae33.
2025-06-24 14:32:40 +08:00
yuxianghui
912847ae33 需求 调拨单关联校验是否完成质量检查时,可先排除欠单量后再校验 开发 2025-06-24 14:32:21 +08:00
胡尧
33647fa3e0 修改明细接口 2025-06-24 14:18:27 +08:00
管欢
d1f9f8cf8c Accept Merge Request #2249: (feature/齐套检查与下达生产 -> develop)
Merge Request: 坯料尺寸显示修改

Created By: @管欢
Reviewed By: @胡尧
Approved By: @胡尧 
Accepted By: @管欢
URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/2249
2025-06-24 11:44:41 +08:00
guanhuan
7d1f7b11eb 坯料尺寸显示修改 2025-06-24 11:39:47 +08:00
胡尧
72f737c370 Accept Merge Request #2248: (feature/6711 -> develop)
Merge Request: 解决大屏bug

Created By: @胡尧
Accepted By: @胡尧
URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/2248?initial=true
2025-06-23 17:54:56 +08:00
胡尧
a2a652eea4 解决大屏bug 2025-06-23 17:54:38 +08:00
管欢
98c5b3b013 Accept Merge Request #2247: (feature/齐套检查与下达生产 -> develop)
Merge Request: 需求计划修改

Created By: @管欢
Reviewed By: @胡尧
Approved By: @胡尧 
Accepted By: @管欢
URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/2247
2025-06-23 14:26:02 +08:00
guanhuan
0d76d1a7d3 需求计划修改 2025-06-23 13:59:37 +08:00
胡尧
a5bb686708 Accept Merge Request #2245: (feature/根据项目组区分sf代码 -> develop)
Merge Request: 将sf_manufacturing模块中stock.py的_run_manufacture方法进行拆分

Created By: @胡尧
Accepted By: @胡尧
URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/2245?initial=true
2025-06-23 10:54:27 +08:00
胡尧
46125dc44b Accept Merge Request #2244: (feature/6711 -> develop)
Merge Request: 修复时间显示问题

Created By: @胡尧
Accepted By: @胡尧
URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/2244?initial=true
2025-06-23 09:22:55 +08:00
胡尧
05c5c0ef81 修复时间显示问题 2025-06-23 09:22:37 +08:00
胡尧
d0d3215bf3 Accept Merge Request #2243: (feature/6711 -> develop)
Merge Request: 修改日产量时间

Created By: @胡尧
Accepted By: @胡尧
URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/2243
2025-06-23 09:11:51 +08:00
胡尧
35e80266d7 修改日产量时间 2025-06-23 08:59:02 +08:00
禹翔辉
92a0c15708 Accept Merge Request #2242: (feature/委外加工bug修复 -> develop)
Merge Request: Merge branch 'feature/委外加工采购订单原生BUG修复' into feature/委外加工bug修复

Created By: @禹翔辉
Reviewed By: @胡尧
Approved By: @胡尧 
Accepted By: @禹翔辉
URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/2242
2025-06-23 08:50:21 +08:00
yuxianghui
0013f9f8c9 Merge branch 'feature/委外加工采购订单原生BUG修复' into feature/委外加工bug修复 2025-06-23 08:34:14 +08:00
禹翔辉
149d8e287b Accept Merge Request #2241: (feature/出厂检验报告模版 -> develop)
Merge Request: 撤销出厂检验报告模版-页脚优化

Created By: @禹翔辉
Reviewed By: @胡尧
Approved By: @胡尧 
Accepted By: @禹翔辉
URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/2241
2025-06-20 17:44:00 +08:00
yuxianghui
3f65742add 撤销出厂检验报告模版-页脚优化 2025-06-20 17:42:39 +08:00
管欢
b56e3545a1 Accept Merge Request #2239: (feature/齐套检查与下达生产 -> develop)
Merge Request: 需求计划

Created By: @管欢
Reviewed By: @胡尧
Approved By: @胡尧 
Accepted By: @管欢
URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/2239
2025-06-20 17:37:21 +08:00
禹翔辉
fd7080a332 Accept Merge Request #2240: (feature/出厂检验报告模版 -> develop)
Merge Request: 页脚条件判断条件优化

Created By: @禹翔辉
Reviewed By: @胡尧
Approved By: @胡尧 
Accepted By: @禹翔辉
URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/2240
2025-06-20 17:37:12 +08:00
yuxianghui
85fb64ed55 页脚条件判断条件优化 2025-06-20 17:36:12 +08:00
guanhuan
9ad06b4361 需求计划 2025-06-20 17:34:17 +08:00
guanhuan
f9c13341e6 Merge branch 'refs/heads/develop' into feature/齐套检查与下达生产 2025-06-20 17:33:26 +08:00
guanhuan
d2a61c79d0 需求计划 2025-06-20 17:29:41 +08:00
禹翔辉
5f80b377e5 Accept Merge Request #2238: (feature/出厂检验报告模版 -> develop)
Merge Request: 添加页脚页码数据测试

Created By: @禹翔辉
Reviewed By: @胡尧 @秦圣
Approved By: @胡尧 
Accepted By: @禹翔辉
URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/2238
2025-06-20 17:28:20 +08:00
yuxianghui
ab2e685004 添加页脚页码数据测试 2025-06-20 17:24:48 +08:00
guanhuan
dcc5eef006 需求计划 2025-06-20 17:21:06 +08:00
guanhuan
7e8b2adb3d 需求计划 2025-06-20 17:19:33 +08:00
禹翔辉
9aa870065b Accept Merge Request #2237: (feature/出厂检验报告模版 -> develop)
Merge Request: 页脚优化

Created By: @禹翔辉
Reviewed By: @胡尧
Approved By: @胡尧 
Accepted By: @禹翔辉
URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/2237
2025-06-20 17:03:52 +08:00
yuxianghui
60c39929b2 页脚优化 2025-06-20 17:02:31 +08:00
禹翔辉
9a5b8a2627 Accept Merge Request #2236: (feature/出厂检验报告模版 -> develop)
Merge Request: 出厂检验报告-页脚优化

Created By: @禹翔辉
Reviewed By: @秦圣
Approved By: @秦圣 
Accepted By: @禹翔辉
URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/2236
2025-06-20 16:56:08 +08:00
yuxianghui
73696eb72c 出厂检验报告-页脚优化 2025-06-20 16:50:59 +08:00
禹翔辉
55babb8a35 Accept Merge Request #2235: (feature/出厂检验报告模版 -> develop)
Merge Request: 出厂检验报告模版-页脚优化

Created By: @禹翔辉
Reviewed By: @胡尧
Approved By: @胡尧 
Accepted By: @禹翔辉
URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/2235
2025-06-20 16:42:02 +08:00
yuxianghui
6682dbfb7d 出厂检验报告模版-页脚优化 2025-06-20 16:40:38 +08:00
禹翔辉
e0b8e5fe07 Accept Merge Request #2234: (feature/出厂检验报告模版 -> develop)
Merge Request: 出厂检验报告-页脚优化

Created By: @禹翔辉
Reviewed By: @胡尧
Approved By: @胡尧 
Accepted By: @禹翔辉
URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/2234
2025-06-20 16:19:18 +08:00
yuxianghui
800f2eb6a7 出厂检验报告-页脚优化 2025-06-20 16:03:13 +08:00
禹翔辉
3cc633131e Accept Merge Request #2233: (feature/出厂检验报告模版 -> develop)
Merge Request: 出厂检验报告-页脚修改

Created By: @禹翔辉
Reviewed By: @胡尧
Approved By: @胡尧 
Accepted By: @禹翔辉
URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/2233
2025-06-20 15:57:55 +08:00
yuxianghui
e3fb266890 出厂检验报告-页脚修改 2025-06-20 15:55:58 +08:00
胡尧
844f7de1ab Accept Merge Request #2232: (feature/6711 -> develop)
Merge Request: 修改计划量字段为–qty_production

Created By: @胡尧
Accepted By: @胡尧
URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/2232?initial=true
2025-06-20 15:39:28 +08:00
胡尧
13d33488dc 修改计划量字段为–qty_production 2025-06-20 15:39:11 +08:00
禹翔辉
266601cf84 Accept Merge Request #2231: (feature/出厂检验报告模版 -> develop)
Merge Request: 出厂检验报告模版-页脚优化

Created By: @禹翔辉
Reviewed By: @胡尧
Approved By: @胡尧 
Accepted By: @禹翔辉
URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/2231
2025-06-20 15:36:51 +08:00
yuxianghui
2e168a4ba7 出厂检验报告模版-页脚优化 2025-06-20 15:35:07 +08:00
胡尧
68ba47ed70 Accept Merge Request #2230: (feature/7151 -> develop)
Merge Request: 修改依赖

Created By: @胡尧
Accepted By: @胡尧
URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/2230?initial=true
2025-06-20 15:03:57 +08:00
胡尧
5bb6fcd4f7 修改依赖 2025-06-20 15:03:42 +08:00
胡尧
9a05bbd82c Accept Merge Request #2229: (feature/7151 -> develop)
Merge Request: 修改需求计划,下达生成的方法

Created By: @胡尧
Accepted By: @胡尧
URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/2229?initial=true
2025-06-20 14:52:34 +08:00
胡尧
b33c992b25 修改需求计划,下达生成的方法 2025-06-20 14:51:58 +08:00
yuxianghui
5947b3dfe9 回退出厂检验报告模版 2025-06-20 14:26:29 +08:00
禹翔辉
95e43b0fba Accept Merge Request #2228: (feature/出厂检验报告模版 -> develop)
Merge Request: 出厂检验报告模版优化

Created By: @禹翔辉
Reviewed By: @胡尧
Approved By: @胡尧 
Accepted By: @禹翔辉
URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/2228
2025-06-20 14:07:56 +08:00
yuxianghui
e7afc76753 出厂检验报告模版优化 2025-06-20 14:01:56 +08:00
胡尧
788183e239 修改批量大小 2025-06-20 13:52:37 +08:00
胡尧
f38f60a6a8 计划增加队列 2025-06-20 11:24:39 +08:00
yuxianghui
71a0f39ec9 新增如果采购订单类型为委外加工,则不进行供应商校验直接生成补给单 2025-06-18 10:50:13 +08:00
胡尧
92f591c3e7 将sf_manufacturing模块中stock.py的_run_manufacture方法进行拆分 2025-06-18 09:25:44 +08:00
19 changed files with 707 additions and 347 deletions

View File

@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from . import models

View File

@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
{
'name': '机企猫 需求计划排程队列',
'version': '1.0',
'summary': """ 使用队列进行排程 """,
'author': 'fox',
'website': '',
'category': '',
'depends': ['queue_job_batch', 'sf_demand_plan'],
'data': [
],
'application': True,
'installable': True,
'auto_install': False,
'license': 'LGPL-3',
}

View File

@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from . import production_demand_plan

View File

@@ -0,0 +1,20 @@
from odoo import models, fields
class ProductionDemandPlan(models.Model):
_inherit = 'sf.production.demand.plan'
def _do_production_schedule(self, pro_plan_list):
"""使用队列进行排程"""
batch_size = 10
current_time = fields.Datetime.now().strftime('%Y%m%d%H%M%S')
index = 1
for i in range(0, len(pro_plan_list), batch_size):
batch = self.env['queue.job.batch'].get_new_batch('plan-%s-%s' % (current_time, index))
pro_plans = pro_plan_list[i:i+batch_size]
pro_plans.with_context(
job_batch=batch
).with_delay().do_production_schedule()
index += 1
batch.enqueue()

View File

@@ -10,7 +10,7 @@
""",
'category': 'sf',
'website': 'https://www.sf.jikimo.com',
'depends': ['sf_plan', 'jikimo_printing'],
'depends': ['sf_plan','jikimo_printing'],
'data': [
'security/ir.model.access.csv',
'views/demand_plan.xml',

View File

@@ -196,11 +196,14 @@ class SfProductionDemandPlan(models.Model):
else:
line.model_long = None
@api.depends('product_id.model_long', 'product_id.model_width', 'product_id.model_height')
@api.depends('product_id.model_long', 'product_id.model_width', 'product_id.model_height', 'product_id.blank_type')
def _compute_embryo_long(self):
for line in self:
if line.product_id:
line.embryo_long = f"{round(line.product_id.model_long, 3)}*{round(line.product_id.model_width, 3)}*{round(line.product_id.model_height, 3)}"
if line.product_id.blank_type == '圆料':
line.embryo_long = f"Ø{round(line.product_id.model_width, 3)}*{round(line.product_id.model_long, 3)}"
else:
line.embryo_long = f"{round(line.product_id.model_long, 3)}*{round(line.product_id.model_width, 3)}*{round(line.product_id.model_height, 3)}"
else:
line.embryo_long = None
@@ -323,8 +326,12 @@ class SfProductionDemandPlan(models.Model):
date_planned_start = datetime.combine(date_part, time_part)
pro_plan_list.production_line_id = sf_production_line.id
pro_plan_list.date_planned_start = date_planned_start
for pro_plan in pro_plan_list:
pro_plan.do_production_schedule()
self._do_production_schedule(pro_plan_list)
def _do_production_schedule(self, pro_plan_list):
for pro_plan in pro_plan_list:
pro_plan.do_production_schedule()
def button_action_print(self):
return {
@@ -399,29 +406,30 @@ class SfProductionDemandPlan(models.Model):
outsourcing_purchase_request.extend(pr_ids.ids)
if record.supply_method == 'outsourcing' and not record.sale_order_line_id.is_incoming_material:
bom_line_ids = record.product_id.bom_ids.bom_line_ids
# BOM_数量
total_product_qty = sum(line.product_qty for line in bom_line_ids)
bom_product_ids = bom_line_ids.mapped('product_id')
product_purchase_orders = self.env['purchase.order'].sudo().search([
('state', 'in', ('purchase', 'done')),
('order_line.product_id', 'in', bom_product_ids.ids)
])
# 购订单_数量
total_outsourcing_purchase_quantity = sum(
sum(
order.order_line.filtered(
lambda line: line.product_id in bom_product_ids
).mapped('product_qty')
if bom_line_ids:
# BOM_数量
total_product_qty = sum(line.product_qty for line in bom_line_ids)
bom_product_ids = bom_line_ids.mapped('product_id')
product_purchase_orders = self.env['purchase.order'].sudo().search([
('state', 'in', ('purchase', 'done')),
('order_line.product_id', 'in', bom_product_ids.ids)
])
# 购订单_数量
total_outsourcing_purchase_quantity = sum(
sum(
order.order_line.filtered(
lambda line: line.product_id in bom_product_ids
).mapped('product_qty')
)
for order in product_purchase_orders
)
for order in product_purchase_orders
)
quantity = total_outsourcing_purchase_quantity / total_product_qty
if float_compare(quantity, record.product_uom_qty,
precision_rounding=record.product_id.uom_id.rounding) == -1:
purchase_request = self.env['purchase.request'].sudo().search(
[('line_ids.product_id', 'in', bom_product_ids.ids),
('line_ids.purchase_state', 'not in', ('purchase', 'done')), ('state', '!=', 'done')])
outsourcing_purchase_request.extend(purchase_request.ids)
quantity = total_outsourcing_purchase_quantity / total_product_qty
if float_compare(quantity, record.product_uom_qty,
precision_rounding=record.product_id.uom_id.rounding) == -1:
purchase_request = self.env['purchase.request'].sudo().search(
[('line_ids.product_id', 'in', bom_product_ids.ids),
('line_ids.purchase_state', 'not in', ('purchase', 'done')), ('state', '!=', 'done')])
outsourcing_purchase_request.extend(purchase_request.ids)
record.outsourcing_purchase_request = json.dumps(outsourcing_purchase_request)
if outsourcing_purchase_request:
record.hide_action_purchase_orders = True

View File

@@ -28,7 +28,7 @@
<field name="qty_delivered"/>
<field name="qty_to_deliver"/>
<field name="model_long"/>
<field name="blank_type"/>
<field name="blank_type" optional="hide"/>
<field name="embryo_long"/>
<field name="materials_id"/>
<field name="model_machining_precision"/>

View File

@@ -4,12 +4,12 @@
<field name="name">sf.demand.plan.print.wizard.tree</field>
<field name="model">sf.demand.plan.print.wizard</field>
<field name="arch" type="xml">
<tree string="打印" class="print_demand" js_class="print_demand" >
<tree string="打印" class="print_demand" js_class="print_demand">
<field name="model_id"/>
<field name="filename_url"/>
<field name="type"/>
<field name="machining_drawings" attrs="{'column_invisible': True }"/>
<field name="cnc_worksheet" attrs="{'column_invisible': True }" />
<field name="machining_drawings" attrs="{'column_invisible': True }"/>
<field name="cnc_worksheet" attrs="{'column_invisible': True }"/>
<field name="status"/>
</tree>
</field>

View File

@@ -437,7 +437,7 @@ class Sf_Dashboard_Connect(http.Controller):
('state', 'in', ['ready', 'progress', 'done'])
])
plan_data_total_counts = sum(plan_data_total.mapped('qty_produced'))
plan_data_total_counts = sum(plan_data_total.mapped('qty_production'))
# # 工单完成量
# plan_data_finish_counts = plan_obj.search_count(
@@ -601,8 +601,11 @@ class Sf_Dashboard_Connect(http.Controller):
line_list = ast.literal_eval(kw['line_list'])
begin_time_str = kw['begin_time'].strip('"')
end_time_str = kw['end_time'].strip('"')
begin_time = datetime.strptime(begin_time_str, '%Y-%m-%d %H:%M:%S')
end_time = datetime.strptime(end_time_str, '%Y-%m-%d %H:%M:%S')
# 将时间减去8小时UTC+8转UTC
begin_time = (datetime.strptime(begin_time_str, '%Y-%m-%d %H:%M:%S') - timedelta(hours=8))
end_time = (datetime.strptime(end_time_str, '%Y-%m-%d %H:%M:%S') - timedelta(hours=8))
# begin_time = datetime.strptime(begin_time_str, '%Y-%m-%d %H:%M:%S')
# end_time = datetime.strptime(end_time_str, '%Y-%m-%d %H:%M:%S')
# print('line_list: %s' % line_list)
print('kw', kw)
time_unit = kw.get('time_unit', 'day').strip('"') # 默认单位为天
@@ -636,6 +639,15 @@ class Sf_Dashboard_Connect(http.Controller):
if time_unit == 'hour':
# 计划量目前只能从mail.message中筛选出
plan_order_messages = request.env['mail.message'].sudo().search([
('model', '=', 'mrp.workorder'),
('create_date', '>=', begin_time.strftime('%Y-%m-%d %H:%M:%S')),
('create_date', '<=', end_time.strftime('%Y-%m-%d %H:%M:%S')),
('tracking_value_ids.field_desc', '=', '状态'),
('tracking_value_ids.new_value_char', '=', '就绪')
])
for line in line_list:
date_field_name = 'date_finished' # 替换为你模型中的实际字段名
@@ -678,19 +690,10 @@ class Sf_Dashboard_Connect(http.Controller):
)
# 使用小时和分钟作为键,确保每个小时的数据有独立的键
key = start_time.strftime('%H:%M:%S') # 只取小时:分钟:秒作为键
key = (start_time + timedelta(hours=8)).strftime('%H:%M:%S') # 只取小时:分钟:秒作为键
# time_count_dict[key] = len(orders)
time_count_dict[key] = sum(interval_orders.mapped('qty_produced'))
# 计划量目前只能从mail.message中筛选出
plan_order_messages = request.env['mail.message'].sudo().search([
('model', '=', 'mrp.workorder'),
('create_date', '>=', begin_time.strftime('%Y-%m-%d %H:%M:%S')),
('create_date', '<=', end_time.strftime('%Y-%m-%d %H:%M:%S')),
('tracking_value_ids.field_desc', '=', '状态'),
('tracking_value_ids.new_value_char', '=', '就绪')
])
for time_interval in time_intervals:
start_time, end_time = time_interval
@@ -704,9 +707,11 @@ class Sf_Dashboard_Connect(http.Controller):
interval_plan_orders = plan_order_messages.filtered(
lambda o: o.create_date >= start_time
and o.create_date <= end_time
)
)
interval_orders = request.env['mrp.workorder'].sudo().browse(interval_plan_orders.mapped('res_id'))
interval_order_ids = set(interval_plan_orders.mapped('res_id'))
interval_orders = request.env['mrp.workorder'].sudo().browse(interval_order_ids)
if line == '业绩总览':
interval_orders = interval_orders.filtered(lambda o: o.routing_type in ['人工线下加工', 'CNC加工'])
elif line == '人工线下加工中心':
@@ -715,9 +720,9 @@ class Sf_Dashboard_Connect(http.Controller):
interval_orders = interval_orders.filtered(lambda o: o.routing_type == 'CNC加工' and o.production_line_id.name == line)
# 使用小时和分钟作为键,确保每个小时的数据有独立的键
key = start_time.strftime('%H:%M:%S') # 只取小时:分钟:秒作为键
key = (start_time + timedelta(hours=8)).strftime('%H:%M:%S') # 只取小时:分钟:秒作为键
# time_count_dict[key] = len(orders)
plan_count_dict[key] = sum(interval_orders.mapped('qty_produced'))
plan_count_dict[key] = sum(interval_orders.mapped('qty_production'))
# order_counts.append()
res['data'][line] = {
@@ -859,21 +864,37 @@ class Sf_Dashboard_Connect(http.Controller):
"""
# res = {'status': 1, 'message': '成功', 'not_done_data': [], 'done_data': []}
res = {'status': 1, 'message': '成功', 'data': {}}
# 解决产品名称取到英文的问题
request.update_context(lang='zh_CN')
plan_obj = request.env['sf.production.plan'].sudo()
work_order_obj = request.env['mrp.workorder'].sudo()
# 获取mrp.workorder的state字段的selection内容
state_dict = dict(request.env['mrp.workorder'].sudo()._fields['state'].selection)
line_list = ast.literal_eval(kw['line_list'])
begin_time_str = kw['begin_time'].strip('"')
end_time_str = kw['end_time'].strip('"')
begin_time = datetime.strptime(begin_time_str, '%Y-%m-%d %H:%M:%S')
end_time = datetime.strptime(end_time_str, '%Y-%m-%d %H:%M:%S')
# print('line_list: %s' % line_list)
not_done_data = []
done_data = []
final_data = {}
not_done_index = 1
done_index = 1
# 获取当前时间并计算24小时前的时间
current_time = datetime.now()
time_48_hours_ago = current_time - timedelta(hours=48)
# # 计划量目前只能从mail.message中筛选出
# plan_order_messages = request.env['mail.message'].sudo().search([
# ('model', '=', 'mrp.workorder'),
# ('create_date', '>=', time_48_hours_ago.strftime('%Y-%m-%d %H:%M:%S')),
# ('tracking_value_ids.field_desc', '=', '状态'),
# ('tracking_value_ids.new_value_char', 'in', ['就绪', '生产中'])
# ])
for line in line_list:
not_done_data = []
done_data = []
not_done_index = 1
done_index = 1
if line == '业绩总览':
work_order_domain = [('routing_type', 'in', ['人工线下加工', 'CNC加工'])]
@@ -889,21 +910,31 @@ class Sf_Dashboard_Connect(http.Controller):
# [('production_line_id.name', '=', line), ('state', 'not in', ['finished']),
# ('production_id.state', 'not in', ['cancel', 'done']), ('active', '=', True)
# ])
not_done_orders = work_order_obj.search(work_order_domain +
[('state', 'in', ['ready', 'progress'])], order='id asc'
not_done_orders = work_order_obj.search(work_order_domain + [
('state', 'in', ['ready', 'progress']),
('date_planned_start', '>=', time_48_hours_ago)
], order='id asc'
)
# not_done_orders = request.env['mrp.workorder'].sudo().browse(plan_order_messages.mapped('res_id'))
# if line == '业绩总览':
# not_done_orders = not_done_orders.filtered(lambda o: o.routing_type in ['人工线下加工', 'CNC加工'])
# elif line == '人工线下加工中心':
# not_done_orders = not_done_orders.filtered(lambda o: o.routing_type == '人工线下加工')
# else:
# not_done_orders = not_done_orders.filtered(lambda o: o.routing_type == 'CNC加工' and o.production_line_id.name == line)
# 完成订单
# 获取当前时间并计算24小时前的时间
current_time = datetime.now()
time_24_hours_ago = current_time - timedelta(hours=24)
# current_time = datetime.now()
# time_24_hours_ago = current_time - timedelta(hours=24)
finish_orders = work_order_obj.search(work_order_domain + [
('state', 'in', ['finished']),
('state', 'in', ['done']),
('production_id.state', 'not in', ['cancel']),
('date_finished', '>=', time_24_hours_ago)
('date_finished', '>=', time_48_hours_ago)
], order='id asc')
# print(finish_orders)
# logging.info('完成订单: %s' % finish_orders)
# 获取所有未完成订单的ID列表
order_ids = [order.id for order in not_done_orders]
@@ -939,14 +970,6 @@ class Sf_Dashboard_Connect(http.Controller):
material_match = re.search(material_pattern, blank_name)
material = material_match.group(1) if material_match else 'No match found'
state_dict = {
'draft': '待排程',
'done': '已排程',
'processing': '生产中',
'finished': '已完成',
'ready': '待加工',
'progress': '生产中',
}
line_dict = {
'sequence': not_done_index,
@@ -962,8 +985,6 @@ class Sf_Dashboard_Connect(http.Controller):
not_done_index += 1
for finish_order in finish_orders:
if not finish_order.actual_end_time:
continue
blank_name = ''
try:
blank_name = finish_order.production_id.move_raw_ids[0].product_id.name
@@ -979,13 +1000,13 @@ class Sf_Dashboard_Connect(http.Controller):
line_dict = {
'sequence': done_index,
'workorder_name': finish_order.name,
'workorder_name': finish_order.production_id.name,
'blank_name': blank_name,
'material': material,
'dimensions': dimensions,
'order_qty': order.qty_produced,
'finish_time': finish_order.actual_end_time.strftime(
'%Y-%m-%d %H:%M:%S') if finish_order.actual_end_time else ' '
'order_qty': finish_order.qty_produced,
'finish_time': finish_order.date_finished.strftime(
'%Y-%m-%d %H:%M:%S') if finish_order.date_finished else ' '
}
done_data.append(line_dict)

View File

@@ -18,4 +18,5 @@ from . import quick_easy_order
from . import purchase_order
from . import quality_check
from . import purchase_request_line
from . import bom
# from . import stock_warehouse_orderpoint

View File

@@ -0,0 +1,16 @@
from odoo import models
from odoo.osv.expression import AND
class MrpBom(models.Model):
_inherit = 'mrp.bom'
def _bom_subcontract_find(self, product, picking_type=None, company_id=False, bom_type='subcontract', subcontractor=False):
domain = self._bom_find_domain(product, picking_type=picking_type, company_id=company_id, bom_type=bom_type)
if self.env.context.get('stock_picking') == 'outsourcing':
return self.search(domain, order='sequence, product_id, id', limit=1)
if subcontractor:
domain = AND([domain, [('subcontractor_ids', 'parent_of', subcontractor.ids)]])
return self.search(domain, order='sequence, product_id, id', limit=1)
else:
return self.env['mrp.bom']

View File

@@ -1709,7 +1709,77 @@ class MrpProduction(models.Model):
vals['procurement_group_id'] = product_group_id[product_id.id]
else:
vals['procurement_group_id'] = is_custemer_group_id[key]
return super(MrpProduction, self).create(vals_list)
productions = super(MrpProduction, self).create(vals_list)
# 查询成品工序排序(自动化产线加工),供后续使用
product_model_type_routing_sorts = self.env['sf.product.model.type.routing.sort'].search([], order='sequence asc')
# 查询成品工序排序(人工线下加工),供后续使用
manual_product_model_type_routing_sorts = self.env['sf.manual.product.model.type.routing.sort'].search([], order='sequence asc')
# 查询坯料工序排序,供后续使用
embryo_model_type_routing_sorts = self.env['sf.embryo.model.type.routing.sort'].search([], order='sequence asc')
for production in productions:
# 生成序列号
production.action_generate_serial()
# 创建工序模板
technology_design_values = []
i = 0
if production.product_id.categ_id.type == '成品':
# 根据加工面板的面数及成品工序模板生成工序设计
if production.production_type == '自动化产线加工':
product_routing_workcenter = product_model_type_routing_sorts.filtered(
lambda s: s.product_model_type_id.id == production.product_id.product_model_type_id.id
)
else:
product_routing_workcenter = manual_product_model_type_routing_sorts.filtered(
lambda s: s.manual_product_model_type_id.id == production.product_id.product_model_type_id.id
)
if production.production_type == '自动化产线加工':
for k in (production.product_id.model_processing_panel.split(',')):
for route in product_routing_workcenter:
i += 1
technology_design_values.append(
self.env['sf.technology.design'].json_technology_design_str(k, route, i, False)
)
elif production.production_type == '人工线下加工':
for route in product_routing_workcenter:
i += 1
technology_design_values.append(
self.env['sf.technology.design'].json_technology_design_str('ZM', route, i, False)
)
else:
for route in product_routing_workcenter:
i += 1
technology_design_values.append(
self.env['sf.technology.design'].json_technology_design_str(False, route, i, False)
)
elif production.product_id.categ_id.type == '坯料':
embryo_routing_workcenter = embryo_model_type_routing_sorts.filtered(
lambda s: s.embryo_model_type_id.id == production.product_id.embryo_model_type_id.id
)
for route_embryo in embryo_routing_workcenter:
i += 1
technology_design_values.append(
self.env['sf.technology.design'].json_technology_design_str(False, route_embryo, i, False)
)
# 处理表面工艺
for item in production.product_id.product_model_type_id.surface_technics_routing_tmpl_ids:
if item.route_workcenter_id.surface_technics_id.id:
for process_param in production.product_id.model_process_parameters_ids:
if item.route_workcenter_id.surface_technics_id == process_param.process_id:
technology_design_values.append(
self.env['sf.technology.design'].json_technology_design_str(
False,
item.route_workcenter_id,
i,
process_param
)
)
production.technology_design_ids = technology_design_values
# 设置制造订单状态为待工艺确认
productions.write({'state': 'technology_to_confirmed'})
return productions
@api.depends('procurement_group_id.stock_move_ids.created_purchase_line_id.order_id',
'procurement_group_id.stock_move_ids.move_orig_ids.purchase_line_id.order_id')

View File

@@ -95,35 +95,36 @@ class StockRule(models.Model):
precision_rounding=proc[
0].product_uom.rounding) > 0)
list2 = []
for item in procurements:
num = int(item[0].product_qty)
for procurement, rule in procurements:
num = int(procurement.product_qty)
product = self.env['product.product'].search(
[("id", '=', item[0].product_id.id)])
product_tmpl = self.env['product.template'].search(
["&", ("id", '=', product.product_tmpl_id.id), ('single_manufacturing', "!=", False)])
if product_tmpl:
warehouse_id = rule.warehouse_id
if not warehouse_id:
warehouse_id = rule.location_dest_id.warehouse_id
manu_rule = rule.route_id.rule_ids.filtered(lambda r: r.action == 'manufacture' and r.warehouse_id == warehouse_id)
if procurement.product_id.product_tmpl_id.single_manufacturing and manu_rule:
if num > 1:
for no in range(1, num + 1):
Procurement = namedtuple('Procurement', ['product_id', 'product_qty',
'product_uom', 'location_id', 'name', 'origin',
'company_id',
'values'])
s = Procurement(product_id=item[0].product_id, product_qty=1.0, product_uom=item[0].product_uom,
location_id=item[0].location_id,
name=item[0].name,
origin=item[0].origin,
company_id=item[0].company_id,
values=item[0].values,
s = Procurement(product_id=procurement.product_id, product_qty=1.0, product_uom=procurement.product_uom,
location_id=procurement.location_id,
name=procurement.name,
origin=procurement.origin,
company_id=procurement.company_id,
values=procurement.values,
)
item1 = list(item)
item1[0] = s
# item1 = list(item)
# item1[0] = s
list2.append(tuple(item1))
list2.append((s, rule))
else:
list2.append(item)
list2.append((procurement, rule))
else:
list2.append(item)
list2.append((procurement, rule))
for procurement, rule in list2:
procure_method = rule.procure_method
@@ -162,215 +163,203 @@ class StockRule(models.Model):
[('res_id', '=', res_id), ('res_field', '=', res_field)], limit=1)
attachment_info.write({'name': name})
@api.model
def _run_manufacture(self, procurements):
productions_values_by_company = defaultdict(list)
errors = []
for procurement, rule in procurements:
if float_compare(procurement.product_qty, 0, precision_rounding=procurement.product_uom.rounding) <= 0:
# If procurement contains negative quantity, don't create a MO that would be for a negative value.
continue
bom = rule._get_matching_bom(procurement.product_id, procurement.company_id, procurement.values)
# @api.model
# def _run_manufacture(self, procurements):
# productions_values_by_company = defaultdict(list)
# errors = []
# for procurement, rule in procurements:
# if float_compare(procurement.product_qty, 0, precision_rounding=procurement.product_uom.rounding) <= 0:
# # If procurement contains negative quantity, don't create a MO that would be for a negative value.
# continue
# bom = rule._get_matching_bom(procurement.product_id, procurement.company_id, procurement.values)
productions_values_by_company[procurement.company_id.id].append(rule._prepare_mo_vals(*procurement, bom))
# productions_values_by_company[procurement.company_id.id].append(rule._prepare_mo_vals(*procurement, bom))
if errors:
raise ProcurementException(errors)
# if errors:
# raise ProcurementException(errors)
for company_id, productions_values in productions_values_by_company.items():
# create the MO as SUPERUSER because the current user may not have the rights to do it
# (mto product launched by a sale for example)
'''创建制造订单'''
productions = self.env['mrp.production'].with_user(SUPERUSER_ID).sudo().with_company(company_id).create(
productions_values)
# 将这一批制造订单的采购组根据成品设置为不同的采购组
# product_group_id = {}
# for index, production in enumerate(productions):
# if production.product_id.id not in product_group_id.keys():
# product_group_id[production.product_id.id] = production.procurement_group_id.id
# else:
# productions_values[index].update({'name': production.name})
# procurement_group_vals = production._prepare_procurement_group_vals(productions_values[index])
# production.procurement_group_id = self.env["procurement.group"].create(procurement_group_vals).id
# for company_id, productions_values in productions_values_by_company.items():
# # create the MO as SUPERUSER because the current user may not have the rights to do it
# # (mto product launched by a sale for example)
# '''创建制造订单'''
# productions = self.env['mrp.production'].with_user(SUPERUSER_ID).sudo().with_company(company_id).create(
# productions_values)
# self.env['stock.move'].sudo().create(productions._get_moves_raw_values())
# self.env['stock.move'].sudo().create(productions._get_moves_finished_values())
# '''
# 创建工单
# '''
# # productions._create_workorder()
# #
# # self.env['stock.move'].sudo().create(productions._get_moves_finished_values())
# productions.filtered(lambda p: (not p.orderpoint_id and p.move_raw_ids) or \
# (
# p.move_dest_ids.procure_method != 'make_to_order' and not
# p.move_raw_ids and not p.workorder_ids)).action_confirm()
# # 处理 根据制造订单生成的采购单坯料入库时到原材料库,手动将原材料位置该为坯料存货区
# for production in productions:
# if production.picking_ids:
# product_type_id = production.picking_ids[0].move_ids[0].product_id.categ_id
# if product_type_id.name == '坯料':
# location_id = self.env['stock.location'].search([('name', '=', '坯料存货区')])
# if not location_id:
# logging.info(f'没有搜索到【坯料存货区】: {location_id}')
# break
# for picking_id in production.picking_ids:
# if picking_id.picking_type_id.name == '内部调拨':
# if picking_id.location_dest_id.product_type != product_type_id:
# picking_id.location_dest_id = location_id.id
# elif picking_id.picking_type_id.name == '生产发料':
# if picking_id.location_id.product_type != product_type_id:
# picking_id.location_id = location_id.id
'''
创建工单
'''
# productions._create_workorder()
#
# self.env['stock.move'].sudo().create(productions._get_moves_finished_values())
productions.filtered(lambda p: (not p.orderpoint_id and p.move_raw_ids) or \
(
p.move_dest_ids.procure_method != 'make_to_order' and not
p.move_raw_ids and not p.workorder_ids)).action_confirm()
# 处理 根据制造订单生成的采购单坯料入库时到原材料库,手动将原材料位置该为坯料存货区
for production in productions:
if production.picking_ids:
product_type_id = production.picking_ids[0].move_ids[0].product_id.categ_id
if product_type_id.name == '坯料':
location_id = self.env['stock.location'].search([('name', '=', '坯料存货区')])
if not location_id:
logging.info(f'没有搜索到【坯料存货区】: {location_id}')
break
for picking_id in production.picking_ids:
if picking_id.picking_type_id.name == '内部调拨':
if picking_id.location_dest_id.product_type != product_type_id:
picking_id.location_dest_id = location_id.id
elif picking_id.picking_type_id.name == '生产发料':
if picking_id.location_id.product_type != product_type_id:
picking_id.location_id = location_id.id
# for production in productions:
# '''
# 创建制造订单时生成序列号
# '''
# # production.action_generate_serial()
# origin_production = production.move_dest_ids and production.move_dest_ids[
# 0].raw_material_production_id or False
# orderpoint = production.orderpoint_id
# if orderpoint and orderpoint.create_uid.id == SUPERUSER_ID and orderpoint.trigger == 'manual':
# production.message_post(
# body=_('This production order has been created from Replenishment Report.'),
# message_type='comment',
# subtype_xmlid='mail.mt_note')
# elif orderpoint:
# production.message_post_with_view(
# 'mail.message_origin_link',
# values={'self': production, 'origin': orderpoint},
# subtype_id=self.env.ref('mail.mt_note').id)
# elif origin_production:
# production.message_post_with_view(
# 'mail.message_origin_link',
# values={'self': production, 'origin': origin_production},
# subtype_id=self.env.ref('mail.mt_note').id)
for production in productions:
'''
创建制造订单时生成序列号
'''
production.action_generate_serial()
origin_production = production.move_dest_ids and production.move_dest_ids[
0].raw_material_production_id or False
orderpoint = production.orderpoint_id
if orderpoint and orderpoint.create_uid.id == SUPERUSER_ID and orderpoint.trigger == 'manual':
production.message_post(
body=_('This production order has been created from Replenishment Report.'),
message_type='comment',
subtype_xmlid='mail.mt_note')
elif orderpoint:
production.message_post_with_view(
'mail.message_origin_link',
values={'self': production, 'origin': orderpoint},
subtype_id=self.env.ref('mail.mt_note').id)
elif origin_production:
production.message_post_with_view(
'mail.message_origin_link',
values={'self': production, 'origin': origin_production},
subtype_id=self.env.ref('mail.mt_note').id)
# '''
# 创建生产计划
# '''
# # 工单耗时
# # workorder_duration = 0
# # for workorder in production.workorder_ids:
# # workorder_duration += workorder.duration_expected
'''
创建生产计划
'''
# 工单耗时
workorder_duration = 0
for workorder in production.workorder_ids:
workorder_duration += workorder.duration_expected
sale_order = self.env['sale.order'].sudo().search([('name', '=', production.origin)])
# 如果订单为空,则获取来源制造订单的销售单
if not sale_order:
mrp_production = self.env['mrp.production'].sudo().search([('name', '=', production.origin)],
limit=1)
if mrp_production:
sale_order = self.env['sale.order'].sudo().search([('name', '=', mrp_production.origin)])
else:
mrp_production = production
# if sale_order:
# sale_order.write({'schedule_status': 'to schedule'})
self.env['sf.production.plan'].sudo().with_company(company_id).create({
'name': production.name,
'order_deadline': sale_order.deadline_of_delivery,
'production_id': production.id,
'date_planned_start': production.date_planned_start,
'origin': mrp_production.origin,
'product_qty': production.product_qty,
'product_id': production.product_id.id,
'state': 'draft',
})
all_production = productions
grouped_product_ids = {k: list(g) for k, g in groupby(all_production, key=lambda x: x.product_id.id)}
# 初始化一个字典来存储每个product_id对应的生产订单名称列表
product_id_to_production_names = {}
# 对于每个product_id获取其所有生产订单的名称
for product_id, all_production in grouped_product_ids.items():
# 为同一个product_id创建一个生产订单名称列表
product_id_to_production_names[product_id] = [production.name for production in all_production]
for production_item in productions:
technology_design_values = []
production_programming = self.env['mrp.production'].search(
[('product_id.id', '=', production_item.product_id.id),
('origin', '=', production_item.origin)],
limit=1, order='id asc')
if production_item.product_id.id in product_id_to_production_names:
# 同一个产品多个制造订单对应一个编程单和模型库
# 只调用一次fetchCNC并将所有生产订单的名称作为字符串传递
if not production_item.programming_no and production_item.production_type in ['自动化产线加工',
'人工线下加工']:
if not production_programming.programming_no:
production_item.fetchCNC(
', '.join(product_id_to_production_names[production_item.product_id.id]))
else:
production_item.write({'programming_no': production_programming.programming_no,
'programming_state': '编程中'})
i = 0
if production_item.product_id.categ_id.type == '成品':
# 根据加工面板的面数及成品工序模板生成工序设计
if production_item.production_type == '自动化产线加工':
model = 'sf.product.model.type.routing.sort'
domain = [
('product_model_type_id', '=', production_item.product_id.product_model_type_id.id)]
else:
model = 'sf.manual.product.model.type.routing.sort'
domain = [('manual_product_model_type_id', '=',
production_item.product_id.product_model_type_id.id)]
product_routing_workcenter = self.env[model].search(domain, order='sequence asc')
if production_item.production_type == '自动化产线加工':
for k in (production_item.product_id.model_processing_panel.split(',')):
for route in product_routing_workcenter:
i += 1
technology_design_values.append(
self.env['sf.technology.design'].json_technology_design_str(k, route, i, False))
elif production_item.production_type == '人工线下加工':
for route in product_routing_workcenter:
i += 1
technology_design_values.append(
self.env['sf.technology.design'].json_technology_design_str('ZM', route, i, False))
else:
for route in product_routing_workcenter:
i += 1
technology_design_values.append(
self.env['sf.technology.design'].json_technology_design_str(False, route, i, False))
elif production_item.product_id.categ_id.type == '坯料':
embryo_routing_workcenter = self.env['sf.embryo.model.type.routing.sort'].search(
[('embryo_model_type_id', '=', production_item.product_id.embryo_model_type_id.id)],
order='sequence asc'
)
for route_embryo in embryo_routing_workcenter:
i += 1
technology_design_values.append(
self.env['sf.technology.design'].json_technology_design_str(False, route_embryo, i,
False))
surface_technics_arr = []
route_workcenter_arr = []
for item in production_item.product_id.product_model_type_id.surface_technics_routing_tmpl_ids:
if item.route_workcenter_id.surface_technics_id.id:
for process_param in production_item.product_id.model_process_parameters_ids:
if item.route_workcenter_id.surface_technics_id == process_param.process_id:
surface_technics_arr.append(
item.route_workcenter_id.surface_technics_id.id)
route_workcenter_arr.append(item.route_workcenter_id.id)
if surface_technics_arr:
production_process = self.env['sf.production.process'].search(
[('id', 'in', surface_technics_arr)],
order='sequence asc'
)
for p in production_process:
logging.info('production_process:%s' % p.name)
process_parameters = production_item.product_id.model_process_parameters_ids.filtered(
lambda pm: pm.process_id.id == p.id)
for process_parameter in process_parameters:
i += 1
route_production_process = self.env[
'mrp.routing.workcenter'].search(
[('surface_technics_id', '=', p.id),
('id', 'in', route_workcenter_arr)])
technology_design_values.append(
self.env['sf.technology.design'].json_technology_design_str(False,
route_production_process,
i,
process_parameter))
production_item.technology_design_ids = technology_design_values
productions.write({'state': 'technology_to_confirmed'})
return True
# # sale_order = self.env['sale.order'].sudo().search([('name', '=', production.origin)])
# # # 如果订单为空,则获取来源制造订单的销售单
# # if not sale_order:
# # mrp_production = self.env['mrp.production'].sudo().search([('name', '=', production.origin)],
# # limit=1)
# # if mrp_production:
# # sale_order = self.env['sale.order'].sudo().search([('name', '=', mrp_production.origin)])
# # else:
# # mrp_production = production
# # # if sale_order:
# # # sale_order.write({'schedule_status': 'to schedule'})
# # self.env['sf.production.plan'].sudo().with_company(company_id).create({
# # 'name': production.name,
# # 'order_deadline': sale_order.deadline_of_delivery,
# # 'production_id': production.id,
# # 'date_planned_start': production.date_planned_start,
# # 'origin': mrp_production.origin,
# # 'product_qty': production.product_qty,
# # 'product_id': production.product_id.id,
# # 'state': 'draft',
# # })
# all_production = productions
# grouped_product_ids = {k: list(g) for k, g in groupby(all_production, key=lambda x: x.product_id.id)}
# # 初始化一个字典来存储每个product_id对应的生产订单名称列表
# product_id_to_production_names = {}
# # 对于每个product_id获取其所有生产订单的名称
# for product_id, all_production in grouped_product_ids.items():
# # 为同一个product_id创建一个生产订单名称列表
# product_id_to_production_names[product_id] = [production.name for production in all_production]
# for production_item in productions:
# technology_design_values = []
# # production_programming = self.env['mrp.production'].search(
# # [('product_id.id', '=', production_item.product_id.id),
# # ('origin', '=', production_item.origin)],
# # limit=1, order='id asc')
# # if production_item.product_id.id in product_id_to_production_names:
# # # 同一个产品多个制造订单对应一个编程单和模型库
# # # 只调用一次fetchCNC并将所有生产订单的名称作为字符串传递
# # if not production_item.programming_no and production_item.production_type in ['自动化产线加工',
# # '人工线下加工']:
# # if not production_programming.programming_no:
# # production_item.fetchCNC(
# # ', '.join(product_id_to_production_names[production_item.product_id.id]))
# # else:
# # production_item.write({'programming_no': production_programming.programming_no,
# # 'programming_state': '编程中'})
# i = 0
# if production_item.product_id.categ_id.type == '成品':
# # 根据加工面板的面数及成品工序模板生成工序设计
# if production_item.production_type == '自动化产线加工':
# model = 'sf.product.model.type.routing.sort'
# domain = [
# ('product_model_type_id', '=', production_item.product_id.product_model_type_id.id)]
# else:
# model = 'sf.manual.product.model.type.routing.sort'
# domain = [('manual_product_model_type_id', '=',
# production_item.product_id.product_model_type_id.id)]
# product_routing_workcenter = self.env[model].search(domain, order='sequence asc')
# if production_item.production_type == '自动化产线加工':
# for k in (production_item.product_id.model_processing_panel.split(',')):
# for route in product_routing_workcenter:
# i += 1
# technology_design_values.append(
# self.env['sf.technology.design'].json_technology_design_str(k, route, i, False))
# elif production_item.production_type == '人工线下加工':
# for route in product_routing_workcenter:
# i += 1
# technology_design_values.append(
# self.env['sf.technology.design'].json_technology_design_str('ZM', route, i, False))
# else:
# for route in product_routing_workcenter:
# i += 1
# technology_design_values.append(
# self.env['sf.technology.design'].json_technology_design_str(False, route, i, False))
# elif production_item.product_id.categ_id.type == '坯料':
# embryo_routing_workcenter = self.env['sf.embryo.model.type.routing.sort'].search(
# [('embryo_model_type_id', '=', production_item.product_id.embryo_model_type_id.id)],
# order='sequence asc'
# )
# for route_embryo in embryo_routing_workcenter:
# i += 1
# technology_design_values.append(
# self.env['sf.technology.design'].json_technology_design_str(False, route_embryo, i,
# False))
# surface_technics_arr = []
# route_workcenter_arr = []
# for item in production_item.product_id.product_model_type_id.surface_technics_routing_tmpl_ids:
# if item.route_workcenter_id.surface_technics_id.id:
# for process_param in production_item.product_id.model_process_parameters_ids:
# if item.route_workcenter_id.surface_technics_id == process_param.process_id:
# surface_technics_arr.append(
# item.route_workcenter_id.surface_technics_id.id)
# route_workcenter_arr.append(item.route_workcenter_id.id)
# if surface_technics_arr:
# production_process = self.env['sf.production.process'].search(
# [('id', 'in', surface_technics_arr)],
# order='sequence asc'
# )
# for p in production_process:
# logging.info('production_process:%s' % p.name)
# process_parameters = production_item.product_id.model_process_parameters_ids.filtered(
# lambda pm: pm.process_id.id == p.id)
# for process_parameter in process_parameters:
# i += 1
# route_production_process = self.env[
# 'mrp.routing.workcenter'].search(
# [('surface_technics_id', '=', p.id),
# ('id', 'in', route_workcenter_arr)])
# technology_design_values.append(
# self.env['sf.technology.design'].json_technology_design_str(False,
# route_production_process,
# i,
# process_parameter))
# production_item.technology_design_ids = technology_design_values
# productions.write({'state': 'technology_to_confirmed'})
# return True
class ProductionLot(models.Model):
@@ -1216,6 +1205,20 @@ class ReStockMove(models.Model):
res['lot_id'] = self.subcontract_workorder_id.production_id.move_raw_ids.move_line_ids[0].lot_id.id
return res
def _get_subcontract_bom(self):
self.ensure_one()
purchase_type = getattr(self.picking_id.purchase_id, 'purchase_type', False)
if purchase_type:
self = self.with_context(stock_picking=purchase_type)
bom = self.env['mrp.bom'].sudo()._bom_subcontract_find(
self.product_id,
picking_type=self.picking_type_id,
company_id=self.company_id.id,
bom_type='subcontract',
subcontractor=self.picking_id.partner_id
)
return bom
class ReStockQuant(models.Model):
_inherit = 'stock.quant'

View File

@@ -1,4 +1,5 @@
from . import ftp_operate
from . import res_config_setting
from . import sync_common
from . import order_price
from . import order_price
from . import mrp_production

View File

@@ -0,0 +1,44 @@
from itertools import groupby
from odoo import models, api
from odoo.tools.misc import OrderedSet
class MrpProduction(models.Model):
_inherit = 'mrp.production'
@api.model_create_multi
def create(self, vals_list):
"""
生成编程单
"""
productions = super().create(vals_list)
# 定义变量存储编程单
grouped_product_programming_no = {}
# 定义产品拼接成的制造订单名称
grouped_product_production_name = {}
# 查出所有的制造订单,为了适配通过补货生成的制造订单
all_productions = self.env['mrp.production'].search([('origin', '=', productions[0].origin)])
# 将不同产品的制造订单进行分组
grouped_product_productions = {k: list(g) for k, g in groupby(all_productions, key=lambda x: x.product_id.id)}
for product_id, grouped_productions in grouped_product_productions.items():
# 产品对应的编程单号
if product_id not in grouped_product_programming_no:
# 使用列表推导式获取非空的programming_no
programming_nos = [p.programming_no for p in grouped_productions if p.programming_no if p.programming_no is not False]
if programming_nos:
grouped_product_programming_no[product_id] = programming_nos[0]
grouped_product_production_name[product_id] = ','.join(list(map(lambda p:p.name, grouped_productions)))
# 同一个产品的制造订单只请求一次CNC编程
for production in productions:
if not production.programming_no and production.production_type in ['自动化产线加工','人工线下加工']:
if production.product_id.id not in grouped_product_programming_no:
production.fetchCNC(grouped_product_production_name[production.product_id.id])
grouped_product_programming_no[production.product_id.id] = production.programming_no
else:
production.write({
'programming_no': grouped_product_programming_no[production.product_id.id],
'programming_state': '编程中'
})
return productions

View File

@@ -3,3 +3,4 @@
from . import custom_plan
from . import change_manufactuing
from . import mrp_production

View File

@@ -0,0 +1,41 @@
from odoo import models, api
class MrpProduction(models.Model):
_inherit = 'mrp.production'
@api.model_create_multi
def create(self, vals_list):
"""
创建生产计划
"""
productions = super().create(vals_list)
for production in productions:
# 工单耗时
workorder_duration = 0
for workorder in production.workorder_ids:
workorder_duration += workorder.duration_expected
sale_order = self.env['sale.order'].sudo().search([('name', '=', production.origin)])
# 如果订单为空,则获取来源制造订单的销售单
if not sale_order:
mrp_production = self.env['mrp.production'].sudo().search([('name', '=', production.origin)],
limit=1)
if mrp_production:
sale_order = self.env['sale.order'].sudo().search([('name', '=', mrp_production.origin)])
else:
mrp_production = production
# if sale_order:
# sale_order.write({'schedule_status': 'to schedule'})
self.env['sf.production.plan'].sudo().with_company(production.company_id).create({
'name': production.name,
'order_deadline': sale_order.deadline_of_delivery,
'production_id': production.id,
'date_planned_start': production.date_planned_start,
'origin': mrp_production.origin,
'product_qty': production.product_qty,
'product_id': production.product_id.id,
'state': 'draft',
})
return productions

View File

@@ -200,16 +200,11 @@
<p></p>
</div>
</div> -->
<!-- 页脚固定在底部 -->
<!-- <div style="position: absolute; bottom: 0; left: 0; right: 0;"> -->
<!-- <t t-call="sf_quality.report_quality_footer"/>-->
<!-- </div> -->
<t t-if="o._index == len(docs) - 1">
<div style="position: absolute; bottom: 0; left: 0; right: 0;">
<t t-call="sf_quality.report_quality_footer"/>
</div>
</t>
<!-- <div style="position: absolute; bottom: 0; left: 0; right: 0;"> -->
<t t-call="sf_quality.report_quality_footer"/>
<!-- </div> -->
</div>
</t>
</t>
@@ -334,14 +329,11 @@
</div> -->
<!-- 页脚固定在底部 -->
<!-- <div style="position: absolute; bottom: 0; left: 0; right: 0;"> -->
<!-- <t t-call="sf_quality.html_report_quality_footer"/>-->
<!-- </div> -->
<t t-if="o._index == len(docs) - 1">
<div style="position: absolute; bottom: 0; left: 0; right: 0;">
<t t-call="sf_quality.report_quality_footer"/>
</div>
</t>
<!-- <t t-if="loop.index == len(docs) - 1">-->
<!-- <div style="position: absolute; bottom: 0; left: 0; right: 0;"> -->
<t t-call="sf_quality.html_report_quality_footer"/>
<!-- </div> -->
<!-- </t>-->
</div>
</t>
</t>

View File

@@ -1,11 +1,41 @@
import logging
from odoo import api, models
from odoo.exceptions import ValidationError, UserError
class StockPicking(models.Model):
_inherit = 'stock.picking'
def _compute_check(self):
super()._compute_check()
for picking in self:
picking_to_quality = picking.get_picking_to_quality()
if not picking_to_quality:
picking.quality_check_todo = False
break
else:
need_quality_line = picking.get_need_quality_line(picking_to_quality)
if not need_quality_line or all(not line.get('need_done_check_ids') for line in need_quality_line):
picking.quality_check_todo = False
def check_quality(self):
self.ensure_one()
# checkable_products = self.mapped('move_line_ids').mapped('product_id')
# checks = self.check_ids.filtered(lambda check: check.quality_state == 'none' and (
# check.product_id in checkable_products or check.measure_on == 'operation'))
checks = self.env['quality.check']
picking_to_quality = self._get_picking_to_quality()
need_quality_line = self.get_need_quality_line(picking_to_quality)
if need_quality_line and any(line.get('need_done_check_ids') for line in need_quality_line):
for item in need_quality_line:
checks += item.get('need_done_check_ids')
if checks:
return checks.action_open_quality_check_wizard()
return False
def button_validate(self):
"""
"""=
出厂检验报告上传
"""
@@ -17,43 +47,133 @@ class StockPicking(models.Model):
if not out_quality_check.is_factory_report_uploaded:
if out_quality_check and self.state == 'assigned':
out_quality_check.upload_factory_report()
quality_action = self.pinking_checkout_quality()
if quality_action:
return quality_action
res = super(StockPicking, self).button_validate()
return res
def pinking_checkout_quality(self):
"""
调拨单若关联了质量检查单,验证调拨单时,应校验是否有不合格品,若存在,应弹窗提示:
“警告存在不合格产品XXXX n 件、YYYYY m件继续调拨请点“确认”否则请取消
"""
context = self.env.context
if not context.get('again_validate') and self.quality_check_ids.filtered(lambda qc: qc.quality_state == 'fail'):
# 回滚事务,为二次确认/取消做准备
self.env.cr.rollback()
quality_check_ids = self.quality_check_ids.filtered(lambda qc: qc.quality_state == 'fail')
product_list = list(set([quality_check_id.product_id for quality_check_id in quality_check_ids]))
fail_check_text = ''
for product_id in product_list:
check_ids = quality_check_ids.filtered(lambda qc: qc.product_id == product_id)
if all(check_id.measure_on == 'move_line' for check_id in check_ids):
number = sum(check_ids.mapped('qty_line'))
else:
number = sum(self.move_ids_without_package.filtered(
lambda ml: ml.product_id == product_id).mapped('quantity_done'))
if number == 0:
number = sum(self.move_ids_without_package.filtered(
lambda ml: ml.product_id == product_id).mapped('reserved_availability'))
if number == 0:
number = sum(self.move_ids_without_package.filtered(
lambda ml: ml.product_id == product_id).mapped('product_uom_qty'))
fail_check_text = (f'{fail_check_text}{product_id.display_name} {number}'
if fail_check_text != '' else f'{product_id.display_name} {number}')
return {
'type': 'ir.actions.act_window',
'res_model': 'picking.validate.check.wizard',
'name': '质检不合格提示',
'view_mode': 'form',
'target': 'new',
'context': {
'default_picking_id': self.id,
'default_fail_check_text': f'警告:存在不合格产品{fail_check_text},继续调拨请点“确认”,否则请取消?',
'again_validate': True}
}
res = super(StockPicking, self).button_validate()
try:
self.ensure_one()
context = self.env.context
if not context.get('pinking_checkout_quality'):
picking_to_quality = self._get_picking_to_quality()
if not picking_to_quality: return False
need_quality_val = self.get_need_quality_line(picking_to_quality)
if any(line.get('fail_check_ids') for line in need_quality_val):
# 回滚事务,为二次确认/取消做准备
self.env.cr.rollback()
# 获取存在失败的 质检单 调拨单明细行
check_list = [item for item in need_quality_val if item.get('fail_check_ids')]
fail_check_text = ''
for item in check_list:
move_id, pre_done_qty = item.get('move_id'), item.get('pre_done_qty')
fail_check_text = (f'{fail_check_text}{move_id.product_id.display_name} {pre_done_qty}'
if fail_check_text != '' else f'{move_id.product_id.display_name} {pre_done_qty}')
return {
'type': 'ir.actions.act_window',
'res_model': 'picking.validate.check.wizard',
'name': '质检不合格提示',
'view_mode': 'form',
'target': 'new',
'context': {
'default_picking_id': self.id,
'default_fail_check_text': f'警告:存在不合格产品{fail_check_text},继续调拨请点“确认”,否则请取消?',
'pinking_checkout_quality': True}
}
else:
return False
except Exception as e:
logging.info('pinking_checkout_quality()方法报错:%s' % e)
raise ValidationError('调拨单验证质检单是否合格时报错,请联系管理员处理!!')
def get_need_quality_line(self, picking_to_quality):
"""
# 对需要进行质检,还没有质检完成的明细行进行统计
# 1、当【质量标准_控制方式】=“产品、作业”,仅校验“预完成数量”>0的产品行对应的质检单必须处理。
2、当【质量标准_控制方式】=“数量”时,仅校验“预完成数量”>0的产品行对应的质检单必须处理
1每一类的“总单数”=【调拨单_需求】时则已处理的质检单“单数”≥“预完成数量”时可执行调拨单验证
2每一类的“总单数”<【调拨单_需求】时则已处理的质检单“单数”≥0时可执行调拨单验证
"""
res = []
for item in picking_to_quality:
need_done_check_ids = self.env['quality.check']
fail_check_ids = self.env['quality.check']
move_id, pre_done_qty, check_ids = item.values()
check_ids_1 = check_ids.filtered(lambda qc: qc.measure_on in ('operation', 'product'))
if check_ids_1:
check_ids_1_done = check_ids_1.filtered(lambda qc: qc.quality_state in ('pass', 'fail'))
check_ids_1_fail = check_ids_1.filtered(lambda qc: qc.quality_state == 'fail')
check_ids_1_none = check_ids_1.filtered(lambda qc: qc.quality_state == 'none')
if check_ids_1 and not check_ids_1_done:
need_done_check_ids += check_ids_1_none
if check_ids_1_fail:
fail_check_ids += check_ids_1_fail
check_ids_2 = check_ids.filtered(lambda qc: qc.measure_on == 'move_line')
if check_ids_2:
check_ids_2_done = check_ids_2.filtered(lambda qc: qc.quality_state in ('pass', 'fail'))
check_ids_2_fail = check_ids_2.filtered(lambda qc: qc.quality_state == 'fail')
check_ids_2_none = check_ids_2.filtered(lambda qc: qc.quality_state == 'none')
# 每一类的“总单数”=【调拨单_需求】时则已处理的质检单“单数”≥“预完成数量”时可执行调拨单验证
if len(check_ids_2) >= move_id.product_uom_qty and len(check_ids_2_done) < pre_done_qty:
need_done_check_ids += check_ids_2_none
# 每一类的“总单数”<【调拨单_需求】时则已处理的质检单“单数”≥0时可执行调拨单验证
elif len(check_ids_2) < move_id.product_uom_qty and len(check_ids_2_done) == 0:
need_done_check_ids += check_ids_2_none
if check_ids_2_fail:
fail_check_ids += check_ids_2_fail
if need_done_check_ids or fail_check_ids:
res.append({'move_id': move_id,
'pre_done_qty': pre_done_qty,
'check_ids': check_ids,
'fail_check_ids': fail_check_ids,
'need_done_check_ids': need_done_check_ids})
return res
def get_picking_to_quality(self):
self.ensure_one()
return self._get_picking_to_quality()
def _get_picking_to_quality(self):
"""
对需要质检的明细行进行统计(针对“预完成数量”>0的行)
"""
quality_piking_line_list = []
pre_done_qty_lines = self._get_pinking_pre_done_qty()
for line in pre_done_qty_lines:
move_id, pre_done_qty = line.values()
if pre_done_qty == 0:
continue
product_id = move_id.product_id
check_ids = self.check_ids.filtered(lambda c: c.product_id == product_id)
quality_piking_line_list.append({'move_id': move_id, 'pre_done_qty': pre_done_qty, 'check_ids': check_ids})
return quality_piking_line_list
def _get_pinking_pre_done_qty(self):
"""
return: 明细行 及 预完成数量
1、若调拨单所有明细行的【完成】=0且任意行的【预留】<【需求】,则验证时将会话是否需创建欠单。
---->此时“预完成数量”=【预留】
2、若调拨单任意行的0<【完成】<【需求】,且则验证时将会话是否需创建欠单
---->此时“预完成数量”=【完成】
"""
# if all(move_id.quantity_done == 0 for move_id in self.move_ids_without_package):
# pre_done_qty = [{'move_id': move_id, 'pre_done_qty': move_id.reserved_availability} for move_id in
# self.move_ids_without_package]
# else:
# pre_done_qty = [{'move_id': move_id, 'pre_done_qty': move_id.quantity_done} for move_id in
# self.move_ids_without_package]
pre_done_qty = []
for move_id in self.move_ids_without_package:
if move_id.quantity_done > 0:
pre_done_qty.append({'move_id': move_id, 'pre_done_qty': move_id.quantity_done})
else:
pre_done_qty.append({'move_id': move_id, 'pre_done_qty': move_id.reserved_availability})
return pre_done_qty