Compare commits

..

11 Commits

Author SHA1 Message Date
guanhuan
fe8df494f9 需求计划列表字段位置变动 2025-06-30 17:13:46 +08:00
guanhuan
32cd68e15f 调拨动作中屏蔽验证 2025-06-30 13:36:04 +08:00
guanhuan
f0e47371ed 新增坯料类型 2025-06-27 15:29:02 +08:00
yuxianghui
6dde814acc 产品-form页面加工参数 添加坯料类型字段 2025-06-27 15:17:15 +08:00
yuxianghui
71ab241e94 产品添加坯料类型字段,值来着bfm下单 2025-06-27 15:10:15 +08:00
yuxianghui
0a13acbb68 修改 销售订单确认时,生成产品BOM时校验单位用量值的提示信息 2025-06-26 17:04:50 +08:00
hyyy
4b026535f8 修改固定列tree的传参方式 2025-06-25 14:01:34 +08:00
hyyy
99ac89f995 需求-字段命名调整 2025-06-25 09:54:37 +08:00
yuxianghui
35b1d648c3 产品新增单件用量 unit_number 字段,值由bfm下单同步获得;产品生成的BOM中组件数量的值由unit_number 字段提供。 2025-06-24 15:36:23 +08:00
guanhuan
fe3492ceb5 坯料尺寸显示修改 2025-06-24 11:32:41 +08:00
yuxianghui
4274b9fe99 出厂检验报告-页脚修改回退 2025-06-20 17:53:04 +08:00
22 changed files with 297 additions and 516 deletions

View File

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

View File

@@ -1,18 +0,0 @@
# -*- 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

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

View File

@@ -1,20 +0,0 @@
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', 'category': 'sf',
'website': 'https://www.sf.jikimo.com', 'website': 'https://www.sf.jikimo.com',
'depends': ['sf_plan','jikimo_printing'], 'depends': ['sf_plan', 'jikimo_printing'],
'data': [ 'data': [
'security/ir.model.access.csv', 'security/ir.model.access.csv',
'views/demand_plan.xml', 'views/demand_plan.xml',

View File

@@ -72,6 +72,7 @@ class SfProductionDemandPlan(models.Model):
model_long = fields.Char('尺寸(mm)', compute='_compute_model_long') model_long = fields.Char('尺寸(mm)', compute='_compute_model_long')
blank_type = fields.Selection([('圆料', '圆料'), ('方料', '方料')], string='坯料分类', blank_type = fields.Selection([('圆料', '圆料'), ('方料', '方料')], string='坯料分类',
related='product_id.blank_type') related='product_id.blank_type')
blank_precision = fields.Selection([('精坯', '精坯'), ('粗坯', '粗坯')], string='坯料类型', related='product_id.blank_precision')
embryo_long = fields.Char('坯料尺寸(mm)', compute='_compute_embryo_long') embryo_long = fields.Char('坯料尺寸(mm)', compute='_compute_embryo_long')
materials_id = fields.Char('材料', compute='_compute_materials_id', store=True) materials_id = fields.Char('材料', compute='_compute_materials_id', store=True)
model_machining_precision = fields.Selection(selection=_get_machining_precision, string='精度', model_machining_precision = fields.Selection(selection=_get_machining_precision, string='精度',
@@ -196,11 +197,14 @@ class SfProductionDemandPlan(models.Model):
else: else:
line.model_long = None 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): def _compute_embryo_long(self):
for line in self: for line in self:
if line.product_id: 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: else:
line.embryo_long = None line.embryo_long = None
@@ -323,12 +327,8 @@ class SfProductionDemandPlan(models.Model):
date_planned_start = datetime.combine(date_part, time_part) date_planned_start = datetime.combine(date_part, time_part)
pro_plan_list.production_line_id = sf_production_line.id pro_plan_list.production_line_id = sf_production_line.id
pro_plan_list.date_planned_start = date_planned_start pro_plan_list.date_planned_start = date_planned_start
self._do_production_schedule(pro_plan_list) for pro_plan in pro_plan_list:
pro_plan.do_production_schedule()
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): def button_action_print(self):
return { return {

View File

@@ -81,4 +81,9 @@
input,label { input,label {
cursor: pointer; cursor: pointer;
} }
} }
th[data-name=processing_time] + th::before{
content: '待执行单据';
line-height: 38px;
}

View File

@@ -4,14 +4,13 @@
<field name="model">sf.production.demand.plan</field> <field name="model">sf.production.demand.plan</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<tree string="需求计划" default_order="sequence desc,id desc" editable="bottom" <tree string="需求计划" default_order="sequence desc,id desc" editable="bottom"
class="demand_plan_tree"> class="demand_plan_tree freeze-columns-before-part_number">
<header> <header>
<button string="打印" name="button_action_print" type="object" <button string="打印" name="button_action_print" type="object"
class="btn-primary"/> class="btn-primary"/>
</header> </header>
<field name="sequence" widget="handle"/> <field name="sequence" widget="handle"/>
<field name="id" optional="hide"/> <field name="id" optional="hide"/>
<field name="priority"/>
<field name="status"/> <field name="status"/>
<field name="customer_name"/> <field name="customer_name"/>
<field name="order_remark"/> <field name="order_remark"/>
@@ -28,7 +27,8 @@
<field name="qty_delivered"/> <field name="qty_delivered"/>
<field name="qty_to_deliver"/> <field name="qty_to_deliver"/>
<field name="model_long"/> <field name="model_long"/>
<field name="blank_type"/> <field name="blank_type" optional="hide"/>
<field name="blank_precision"/>
<field name="embryo_long"/> <field name="embryo_long"/>
<field name="materials_id"/> <field name="materials_id"/>
<field name="model_machining_precision"/> <field name="model_machining_precision"/>
@@ -43,7 +43,10 @@
<field name="date_order"/> <field name="date_order"/>
<field name="contract_code"/> <field name="contract_code"/>
<field name="plan_remark"/> <field name="plan_remark"/>
<field name="processing_time"/> <field name="priority" decoration-danger="priority == '1'"
decoration-warning="priority == '2'"
decoration-info="priority == '3'"
decoration-success="priority == '4'"/>
<field name="material_check" optional="hide"/> <field name="material_check" optional="hide"/>
<field name="hide_action_open_mrp_production" invisible="1"/> <field name="hide_action_open_mrp_production" invisible="1"/>
<field name="hide_action_purchase_orders" invisible="1"/> <field name="hide_action_purchase_orders" invisible="1"/>
@@ -62,6 +65,7 @@
<field name="planned_start_date"/> <field name="planned_start_date"/>
<field name="actual_start_date"/> <field name="actual_start_date"/>
<field name="actual_end_date"/> <field name="actual_end_date"/>
<field name="processing_time"/>
<field name="create_date" optional="hide" string="创建时间"/> <field name="create_date" optional="hide" string="创建时间"/>
<field name="create_uid" optional="hide" string="创建人"/> <field name="create_uid" optional="hide" string="创建人"/>
<field name="write_date" string="更新时间"/> <field name="write_date" string="更新时间"/>
@@ -91,7 +95,8 @@
<group expand="0" string="Group By"> <group expand="0" string="Group By">
<filter name="group_by_priority" string="优先级" domain="[]" context="{'group_by': 'priority'}"/> <filter name="group_by_priority" string="优先级" domain="[]" context="{'group_by': 'priority'}"/>
<filter name="group_by_status" string="状态" domain="[]" context="{'group_by': 'status'}"/> <filter name="group_by_status" string="状态" domain="[]" context="{'group_by': 'status'}"/>
<filter name="group_by_customer_name" string="客户" domain="[]" context="{'group_by': 'customer_name'}"/> <filter name="group_by_customer_name" string="客户" domain="[]"
context="{'group_by': 'customer_name'}"/>
<filter name="group_by_is_incoming_material" string="客供料" domain="[]" <filter name="group_by_is_incoming_material" string="客供料" domain="[]"
context="{'group_by': 'is_incoming_material'}"/> context="{'group_by': 'is_incoming_material'}"/>
<filter name="group_by_supply_method" string="供货方式" domain="[]" <filter name="group_by_supply_method" string="供货方式" domain="[]"
@@ -122,4 +127,9 @@
action="sf_production_demand_plan_action" action="sf_production_demand_plan_action"
parent="sf_plan.sf_production_plan_menu" parent="sf_plan.sf_production_plan_menu"
/> />
<!-- 调拨动作中屏蔽验证-->
<record id="stock.action_validate_picking" model="ir.actions.server">
<field name="binding_model_id" eval="False"/>
</record>
</odoo> </odoo>

View File

@@ -4,12 +4,12 @@
<field name="name">sf.demand.plan.print.wizard.tree</field> <field name="name">sf.demand.plan.print.wizard.tree</field>
<field name="model">sf.demand.plan.print.wizard</field> <field name="model">sf.demand.plan.print.wizard</field>
<field name="arch" type="xml"> <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="model_id"/>
<field name="filename_url"/> <field name="filename_url"/>
<field name="type"/> <field name="type"/>
<field name="machining_drawings" attrs="{'column_invisible': True }"/> <field name="machining_drawings" attrs="{'column_invisible': True }"/>
<field name="cnc_worksheet" attrs="{'column_invisible': True }"/> <field name="cnc_worksheet" attrs="{'column_invisible': True }" />
<field name="status"/> <field name="status"/>
</tree> </tree>
</field> </field>

View File

@@ -3,6 +3,7 @@ import logging
import re import re
from odoo import models, fields, api from odoo import models, fields, api
from odoo.exceptions import ValidationError
class ResProductCategory(models.Model): class ResProductCategory(models.Model):
@@ -47,11 +48,14 @@ class ResMrpBomMo(models.Model):
item.subcontractor_name = '' item.subcontractor_name = ''
def bom_create_line_has(self, embryo): def bom_create_line_has(self, embryo):
product = self.product_tmpl_id
if product.unit_number in (0, None, False):
raise ValidationError(f'产品{product.name}单件用量的值不能为{product.unit_number}')
vals = { vals = {
'bom_id': self.id, 'bom_id': self.id,
'product_id': embryo.id, 'product_id': embryo.id,
'product_tmpl_id': embryo.product_tmpl_id.id, 'product_tmpl_id': embryo.product_tmpl_id.id,
'product_qty': 1, 'product_qty': product.unit_number,
'product_uom_id': 1 'product_uom_id': 1
} }
return self.env['mrp.bom.line'].sudo().create(vals) return self.env['mrp.bom.line'].sudo().create(vals)
@@ -122,7 +126,7 @@ class ResMrpBomMo(models.Model):
# 查bom的原材料 # 查bom的原材料
def get_raw_bom(self, product): def get_raw_bom(self, product):
raw_bom = self.env['product.product'].search( raw_bom = self.env['product.product'].search(
[('categ_id.type', '=', '原材料'), ('materials_type_id', '=', product.materials_type_id.id)],limit=1) [('categ_id.type', '=', '原材料'), ('materials_type_id', '=', product.materials_type_id.id)], limit=1)
return raw_bom return raw_bom

View File

@@ -95,6 +95,8 @@
<page string="加工参数"> <page string="加工参数">
<group> <group>
<group string="模型"> <group string="模型">
<field name="blank_type" readonly="1"/>
<field name="blank_precision" readonly="1"/>
<label for="model_long" string="坯料尺寸[mm]"/> <label for="model_long" string="坯料尺寸[mm]"/>
<div class="o_address_format"> <div class="o_address_format">
<label for="model_long" string="长"/> <label for="model_long" string="长"/>
@@ -104,7 +106,7 @@
<label for="model_height" string="高"/> <label for="model_height" string="高"/>
<field name="model_height" class="o_address_zip"/> <field name="model_height" class="o_address_zip"/>
</div> </div>
<field name="blank_type" readonly="1"/> <field name="unit_number" readonly="1"/>
<field name="model_volume" string="体积[mm³]"/> <field name="model_volume" string="体积[mm³]"/>
<field name="product_model_type_id" string="模型类型"/> <field name="product_model_type_id" string="模型类型"/>
<field name="model_processing_panel" placeholder="例如R,U" string="加工面板" <field name="model_processing_panel" placeholder="例如R,U" string="加工面板"

View File

@@ -437,7 +437,7 @@ class Sf_Dashboard_Connect(http.Controller):
('state', 'in', ['ready', 'progress', 'done']) ('state', 'in', ['ready', 'progress', 'done'])
]) ])
plan_data_total_counts = sum(plan_data_total.mapped('qty_production')) plan_data_total_counts = sum(plan_data_total.mapped('qty_produced'))
# # 工单完成量 # # 工单完成量
# plan_data_finish_counts = plan_obj.search_count( # plan_data_finish_counts = plan_obj.search_count(
@@ -601,11 +601,8 @@ class Sf_Dashboard_Connect(http.Controller):
line_list = ast.literal_eval(kw['line_list']) line_list = ast.literal_eval(kw['line_list'])
begin_time_str = kw['begin_time'].strip('"') begin_time_str = kw['begin_time'].strip('"')
end_time_str = kw['end_time'].strip('"') end_time_str = kw['end_time'].strip('"')
# 将时间减去8小时UTC+8转UTC begin_time = datetime.strptime(begin_time_str, '%Y-%m-%d %H:%M:%S')
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')
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('line_list: %s' % line_list)
print('kw', kw) print('kw', kw)
time_unit = kw.get('time_unit', 'day').strip('"') # 默认单位为天 time_unit = kw.get('time_unit', 'day').strip('"') # 默认单位为天
@@ -639,15 +636,6 @@ class Sf_Dashboard_Connect(http.Controller):
if time_unit == 'hour': 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: for line in line_list:
date_field_name = 'date_finished' # 替换为你模型中的实际字段名 date_field_name = 'date_finished' # 替换为你模型中的实际字段名
@@ -690,10 +678,19 @@ class Sf_Dashboard_Connect(http.Controller):
) )
# 使用小时和分钟作为键,确保每个小时的数据有独立的键 # 使用小时和分钟作为键,确保每个小时的数据有独立的键
key = (start_time + timedelta(hours=8)).strftime('%H:%M:%S') # 只取小时:分钟:秒作为键 key = start_time.strftime('%H:%M:%S') # 只取小时:分钟:秒作为键
# time_count_dict[key] = len(orders) # time_count_dict[key] = len(orders)
time_count_dict[key] = sum(interval_orders.mapped('qty_produced')) 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: for time_interval in time_intervals:
start_time, end_time = time_interval start_time, end_time = time_interval
@@ -718,9 +715,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) interval_orders = interval_orders.filtered(lambda o: o.routing_type == 'CNC加工' and o.production_line_id.name == line)
# 使用小时和分钟作为键,确保每个小时的数据有独立的键 # 使用小时和分钟作为键,确保每个小时的数据有独立的键
key = (start_time + timedelta(hours=8)).strftime('%H:%M:%S') # 只取小时:分钟:秒作为键 key = start_time.strftime('%H:%M:%S') # 只取小时:分钟:秒作为键
# time_count_dict[key] = len(orders) # time_count_dict[key] = len(orders)
plan_count_dict[key] = sum(interval_orders.mapped('qty_production')) plan_count_dict[key] = sum(interval_orders.mapped('qty_produced'))
# order_counts.append() # order_counts.append()
res['data'][line] = { res['data'][line] = {
@@ -876,18 +873,6 @@ class Sf_Dashboard_Connect(http.Controller):
not_done_index = 1 not_done_index = 1
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: for line in line_list:
if line == '业绩总览': if line == '业绩总览':
@@ -904,27 +889,19 @@ class Sf_Dashboard_Connect(http.Controller):
# [('production_line_id.name', '=', line), ('state', 'not in', ['finished']), # [('production_line_id.name', '=', line), ('state', 'not in', ['finished']),
# ('production_id.state', 'not in', ['cancel', 'done']), ('active', '=', True) # ('production_id.state', 'not in', ['cancel', 'done']), ('active', '=', True)
# ]) # ])
# not_done_orders = work_order_obj.search(work_order_domain + not_done_orders = work_order_obj.search(work_order_domain +
# [('state', 'in', ['ready', 'progress'])], order='id asc' [('state', 'in', ['ready', 'progress'])], 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小时前的时间 # 获取当前时间并计算24小时前的时间
# current_time = datetime.now() current_time = datetime.now()
# time_24_hours_ago = current_time - timedelta(hours=24) time_24_hours_ago = current_time - timedelta(hours=24)
finish_orders = work_order_obj.search(work_order_domain + [ finish_orders = work_order_obj.search(work_order_domain + [
('state', 'in', ['finished']), ('state', 'in', ['finished']),
('production_id.state', 'not in', ['cancel']), ('production_id.state', 'not in', ['cancel']),
('date_finished', '>=', time_48_hours_ago) ('date_finished', '>=', time_24_hours_ago)
], order='id asc') ], order='id asc')
# print(finish_orders) # print(finish_orders)

View File

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

View File

@@ -1,16 +0,0 @@
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,77 +1709,7 @@ class MrpProduction(models.Model):
vals['procurement_group_id'] = product_group_id[product_id.id] vals['procurement_group_id'] = product_group_id[product_id.id]
else: else:
vals['procurement_group_id'] = is_custemer_group_id[key] 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', @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') 'procurement_group_id.stock_move_ids.move_orig_ids.purchase_line_id.order_id')

View File

@@ -27,9 +27,11 @@ class ResProductMo(models.Model):
categ_type = fields.Selection(string='产品的类别', related='categ_id.type', store=True) categ_type = fields.Selection(string='产品的类别', related='categ_id.type', store=True)
model_name = fields.Char('模型名称') model_name = fields.Char('模型名称')
blank_type = fields.Selection([('圆料', '圆料'), ('方料', '方料')], string='坯料分类') blank_type = fields.Selection([('圆料', '圆料'), ('方料', '方料')], string='坯料分类')
blank_precision = fields.Selection([('精坯', '精坯'), ('粗坯', '粗坯')], string='坯料类型')
model_long = fields.Float('模型长(mm)', digits=(16, 3)) model_long = fields.Float('模型长(mm)', digits=(16, 3))
model_width = fields.Float('模型宽(mm)', digits=(16, 3)) model_width = fields.Float('模型宽(mm)', digits=(16, 3))
model_height = fields.Float('模型高(mm)', digits=(16, 3)) model_height = fields.Float('模型高(mm)', digits=(16, 3))
unit_number = fields.Float('单件用量', digits=(16, 3), default=1)
model_volume = fields.Float('模型体积(m³)') model_volume = fields.Float('模型体积(m³)')
model_area = fields.Float('模型表面积(m²)') model_area = fields.Float('模型表面积(m²)')
model_machining_precision = fields.Selection(selection=_get_machining_precision, string='加工精度') model_machining_precision = fields.Selection(selection=_get_machining_precision, string='加工精度')
@@ -901,9 +903,11 @@ class ResProductMo(models.Model):
vals = { vals = {
'name': product_name, 'name': product_name,
'blank_type': item.get('blank_type'), 'blank_type': item.get('blank_type'),
'blank_precision': item.get('blank_precision'),
'model_long': item.get('blank_length') if blank_bool else self.format_float(item['model_long'] + embryo_redundancy_id.long), 'model_long': item.get('blank_length') if blank_bool else self.format_float(item['model_long'] + embryo_redundancy_id.long),
'model_width': item.get('blank_width') if blank_bool else self.format_float(item['model_width'] + embryo_redundancy_id.width), 'model_width': item.get('blank_width') if blank_bool else self.format_float(item['model_width'] + embryo_redundancy_id.width),
'model_height': item.get('blank_height') if blank_bool else self.format_float(item['model_height'] + embryo_redundancy_id.height), 'model_height': item.get('blank_height') if blank_bool else self.format_float(item['model_height'] + embryo_redundancy_id.height),
'unit_number': item.get('unit_number'),
'model_volume': self.format_float(((item['model_long'] + embryo_redundancy_id.long) * 'model_volume': self.format_float(((item['model_long'] + embryo_redundancy_id.long) *
(item['model_width'] + embryo_redundancy_id.width) * (item['model_width'] + embryo_redundancy_id.width) *
(item['model_height'] + embryo_redundancy_id.height))) if not blank_bool else ( (item['model_height'] + embryo_redundancy_id.height))) if not blank_bool else (
@@ -957,7 +961,7 @@ class ResProductMo(models.Model):
self.attachment_update(item['quality_standard_name'], copy_product_id.product_tmpl_id.id, self.attachment_update(item['quality_standard_name'], copy_product_id.product_tmpl_id.id,
'quality_standard', item['quality_standard_mimetype']) 'quality_standard', item['quality_standard_mimetype'])
return copy_product_id return copy_product_id
def format_float(self, value): def format_float(self, value):
# 将浮点数转换为字符串 # 将浮点数转换为字符串
value_str = str(value) value_str = str(value)

View File

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

View File

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

View File

@@ -1,44 +0,0 @@
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,4 +3,3 @@
from . import custom_plan from . import custom_plan
from . import change_manufactuing from . import change_manufactuing
from . import mrp_production

View File

@@ -1,41 +0,0 @@
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,11 +200,11 @@
<p></p> <p></p>
</div> </div>
</div> --> </div> -->
<!-- 页脚固定在底部 -->
<!-- <div style="position: absolute; bottom: 0; left: 0; right: 0;"> --> <!-- 页脚固定在底部 -->
<t t-call="sf_quality.report_quality_footer"/> <!-- <div style="position: absolute; bottom: 0; left: 0; right: 0;"> -->
<!-- </div> --> <t t-call="sf_quality.report_quality_footer"/>
<!-- </div> -->
</div> </div>
</t> </t>
</t> </t>
@@ -329,11 +329,9 @@
</div> --> </div> -->
<!-- 页脚固定在底部 --> <!-- 页脚固定在底部 -->
<!-- <t t-if="loop.index == len(docs) - 1">--> <!-- <div style="position: absolute; bottom: 0; left: 0; right: 0;"> -->
<!-- <div style="position: absolute; bottom: 0; left: 0; right: 0;"> --> <t t-call="sf_quality.html_report_quality_footer"/>
<t t-call="sf_quality.html_report_quality_footer"/> <!-- </div> -->
<!-- </div> -->
<!-- </t>-->
</div> </div>
</t> </t>
</t> </t>