diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py
index 27b75ff9..d2b63cb9 100644
--- a/sf_manufacturing/models/mrp_production.py
+++ b/sf_manufacturing/models/mrp_production.py
@@ -1101,67 +1101,19 @@ class MrpProduction(models.Model):
('is_subcontract', '=', True)])
if scarp_process_parameter_workorder:
production_programming = self.env['mrp.production'].search(
- [('programming_no', '=', self.programming_no)], order='name asc')
+ [('programming_no', '=', self.programming_no), ('id', '!=', productions.id)], order='name asc')
production_list = [production.name for production in production_programming]
- purchase_orders = self.env['purchase.order'].search([('origin', '=', ','.join(production_list))])
+ purchase_orders = self.env['purchase.order'].search([('origin', 'ilike', ','.join(production_list))])
for purchase_item in purchase_orders.order_line:
for process_item in scarp_process_parameter_workorder:
if purchase_item.product_id.categ_type == '表面工艺':
if purchase_item.product_id.server_product_process_parameters_id == process_item.surface_technics_parameters_id:
- print(purchase_orders.find(productions.name))
- if purchase_orders.find(productions.name) == -1:
- purchase_orders.origin += productions.name
+ print(purchase_orders.origin.find(productions.name))
+ if purchase_orders.origin.find(productions.name) == -1:
+ purchase_orders.origin += ',' + productions.name
if item['is_reprogramming'] is False:
productions._create_workorder(item)
productions.programming_state = '已编程'
- for production_item in productions:
- process_parameter_workorder = self.env['mrp.workorder'].search(
- [('surface_technics_parameters_id', '!=', False), ('production_id', '=', production_item.id),
- ('is_subcontract', '=', True)])
- if process_parameter_workorder:
- is_pick = False
- consecutive_workorders = []
- m = 0
- sorted_workorders = sorted(process_parameter_workorder, key=lambda w: w.id)
- for i in range(len(sorted_workorders) - 1):
- if m == 0:
- is_pick = False
- if sorted_workorders[i].supplier_id.id == sorted_workorders[i + 1].supplier_id.id and \
- sorted_workorders[i].is_subcontract == sorted_workorders[i + 1].is_subcontract and \
- sorted_workorders[i].id == sorted_workorders[i + 1].id - 1:
- if sorted_workorders[i] not in consecutive_workorders:
- consecutive_workorders.append(sorted_workorders[i])
- consecutive_workorders.append(sorted_workorders[i + 1])
- m += 1
- continue
- else:
- if m == len(consecutive_workorders) - 1 and m != 0:
- self.env['stock.picking'].create_outcontract_picking(consecutive_workorders,
- production_item)
- if sorted_workorders[i] in consecutive_workorders:
- is_pick = True
- consecutive_workorders = []
- m = 0
- # 当前面的连续工序生成对应的外协出入库单再生成当前工序的外协出入库单
- if is_pick is False:
- self.env['stock.picking'].create_outcontract_picking(sorted_workorders[i],
- production_item)
- if m == len(consecutive_workorders) - 1 and m != 0:
- self.env['stock.picking'].create_outcontract_picking(consecutive_workorders,
- production_item)
- if sorted_workorders[i] in consecutive_workorders:
- is_pick = True
- consecutive_workorders = []
- m = 0
- if m == len(consecutive_workorders) - 1 and m != 0:
- self.env['stock.picking'].create_outcontract_picking(consecutive_workorders,
- production_item)
- if is_pick is False and m == 0:
- if len(sorted_workorders) == 1:
- self.env['stock.picking'].create_outcontract_picking(sorted_workorders, production_item)
- else:
- self.env['stock.picking'].create_outcontract_picking(sorted_workorders[i],
- production_item)
else:
productions.programming_state = '编程中'
return productions
diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py
index 63ff1551..485eb290 100644
--- a/sf_manufacturing/models/mrp_workorder.py
+++ b/sf_manufacturing/models/mrp_workorder.py
@@ -58,6 +58,7 @@ class ResMrpWorkOrder(models.Model):
('cancel', '取消')], string='Status',
compute='_compute_state', store=True,
default='pending', copy=False, readonly=True, recursive=True, index=True, tracking=True)
+
# state = fields.Selection(selection_add=[('to be detected', "待检测"), ('rework', '返工')], tracking=True)
@api.depends('production_id.manual_quotation')
@@ -183,17 +184,12 @@ class ResMrpWorkOrder(models.Model):
if order.routing_type == '表面工艺':
production_programming = self.env['mrp.production'].search(
[('programming_no', '=', order.production_id.programming_no)], order='name asc')
+ production_no_remanufacture = production_programming.filtered(lambda a: a.is_remanufacture is False)
production_list = [production.name for production in production_programming]
purchase = self.env['purchase.order'].search([('origin', '=', ','.join(production_list))])
for line in purchase.order_line:
if line.product_id.server_product_process_parameters_id == order.surface_technics_parameters_id and line.product_qty == len(
- production_programming):
- # server_product = self.env['product.template'].search(
- # [('server_product_process_parameters_id', '=', pp.id),
- # ('detailed_type', '=', 'service')])
- # purchase_order_line = self.env['purchase.order.line'].search(
- # [('product_id', '=', server_product.id), ('product_qty', '=', len(production_programming))])
- # if purchase_order_line:
+ production_no_remanufacture):
order.surface_technics_purchase_count = len(purchase)
else:
order.surface_technics_purchase_count = 0
@@ -243,6 +239,7 @@ class ResMrpWorkOrder(models.Model):
store=True, compute='_compute_tool_state')
tool_state_remark = fields.Text(string='功能刀具状态备注(缺刀)', compute='_compute_tool_state_remark', store=True)
reserved_duration = fields.Float('预留时长', default=30, tracking=True)
+
@api.depends('cnc_ids.tool_state')
def _compute_tool_state_remark(self):
for item in self:
@@ -651,7 +648,7 @@ class ResMrpWorkOrder(models.Model):
# 拼接工单对象属性值
def json_workorder_str(self, k, production, route, item):
# 计算预计时长duration_expected
- routing_types = ['切割', '装夹预调', 'CNC加工','解除装夹']
+ routing_types = ['切割', '装夹预调', 'CNC加工', '解除装夹']
if route.routing_type in routing_types:
routing_workcenter = self.env['mrp.routing.workcenter'].sudo().search(
[('name', '=', route.routing_type)])
@@ -704,7 +701,7 @@ class ResMrpWorkOrder(models.Model):
item),
# 'workpiece_delivery_ids': False if not route.routing_type == '装夹预调' else self._json_workpiece_delivery_list(
# production)
- 'reserved_duration': reserved_duration,
+ 'reserved_duration': reserved_duration,
}]
return workorders_values_str
@@ -1169,8 +1166,9 @@ class ResMrpWorkOrder(models.Model):
if record.routing_type == '装夹预调':
if not record.rfid_code and record.is_rework is False:
raise UserError("请扫RFID码进行绑定")
- if not record.material_center_point and record.X_deviation_angle > 0:
- raise UserError("坯料中心点为空或X偏差角度小于等于0")
+ if record.is_rework is False:
+ if not record.material_center_point or record.X_deviation_angle <= 0:
+ raise UserError("请对前置三元检测定位参数进行计算定位")
record.process_state = '待加工'
# record.write({'process_state': '待加工'})
record.production_id.process_state = '待加工'
diff --git a/sf_manufacturing/models/stock.py b/sf_manufacturing/models/stock.py
index 76c51cff..b9483a17 100644
--- a/sf_manufacturing/models/stock.py
+++ b/sf_manufacturing/models/stock.py
@@ -288,28 +288,46 @@ class StockRule(models.Model):
# 为同一个product_id创建一个生产订单名称列表
product_id_to_production_names[product_id] = [production.name for production in all_production]
for production_item in productions:
+ 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:
- if production_item.product_id.model_process_parameters_ids:
- is_purchase = False
- sorted_process_parameters = sorted(production_item.product_id.model_process_parameters_ids,
- key=lambda w: w.id)
+ if not production_programming.programming_no:
+ if production_item.product_id.model_process_parameters_ids:
+ is_purchase = False
+ sorted_process_parameters = sorted(production_item.product_id.model_process_parameters_ids,
+ key=lambda w: w.id)
- consecutive_process_parameters = []
- m = 0
- for i in range(len(sorted_process_parameters) - 1):
- if m == 0:
- is_purchase = False
- if self.env['product.template']._get_process_parameters_product(
- sorted_process_parameters[i]).partner_id == self.env[
- 'product.template']._get_process_parameters_product(sorted_process_parameters[
- i + 1]).partner_id and \
- sorted_process_parameters[i].gain_way == '外协':
- if sorted_process_parameters[i] not in consecutive_process_parameters:
- consecutive_process_parameters.append(sorted_process_parameters[i])
- consecutive_process_parameters.append(sorted_process_parameters[i + 1])
- m += 1
- continue
- else:
+ consecutive_process_parameters = []
+ m = 0
+ for i in range(len(sorted_process_parameters) - 1):
+ if m == 0:
+ is_purchase = False
+ if self.env['product.template']._get_process_parameters_product(
+ sorted_process_parameters[i]).partner_id == self.env[
+ 'product.template']._get_process_parameters_product(sorted_process_parameters[
+ i + 1]).partner_id and \
+ sorted_process_parameters[i].gain_way == '外协':
+ if sorted_process_parameters[i] not in consecutive_process_parameters:
+ consecutive_process_parameters.append(sorted_process_parameters[i])
+ consecutive_process_parameters.append(sorted_process_parameters[i + 1])
+ m += 1
+ continue
+ else:
+ if m == len(consecutive_process_parameters) - 1 and m != 0:
+ self.env['purchase.order'].get_purchase_order(consecutive_process_parameters,
+ production_item,
+ product_id_to_production_names)
+ if sorted_process_parameters[i] in consecutive_process_parameters:
+ is_purchase = True
+ consecutive_process_parameters = []
+ m = 0
+ # 当前面的连续外协采购单生成再生成当前外协采购单
+ if is_purchase is False:
+ self.env['purchase.order'].get_purchase_order(consecutive_process_parameters,
+ production_item,
+ product_id_to_production_names)
if m == len(consecutive_process_parameters) - 1 and m != 0:
self.env['purchase.order'].get_purchase_order(consecutive_process_parameters,
production_item,
@@ -318,39 +336,22 @@ class StockRule(models.Model):
is_purchase = True
consecutive_process_parameters = []
m = 0
- # 当前面的连续外协采购单生成再生成当前外协采购单
- if is_purchase is False:
- self.env['purchase.order'].get_purchase_order(consecutive_process_parameters,
- production_item,
- product_id_to_production_names)
- if m == len(consecutive_process_parameters) - 1 and m != 0:
- self.env['purchase.order'].get_purchase_order(consecutive_process_parameters,
- production_item,
- product_id_to_production_names)
- if sorted_process_parameters[i] in consecutive_process_parameters:
- is_purchase = True
- consecutive_process_parameters = []
- m = 0
- if m == len(consecutive_process_parameters) - 1 and m != 0:
- self.env['purchase.order'].get_purchase_order(consecutive_process_parameters,
- production_item,
- product_id_to_production_names)
- if is_purchase is False and m == 0:
- if len(sorted_process_parameters) == 1:
- self.env['purchase.order'].get_purchase_order(sorted_process_parameters,
- production_item,
- product_id_to_production_names)
- else:
- self.env['purchase.order'].get_purchase_order(sorted_process_parameters[i],
+ if m == len(consecutive_process_parameters) - 1 and m != 0:
+ self.env['purchase.order'].get_purchase_order(consecutive_process_parameters,
production_item,
product_id_to_production_names)
+ if is_purchase is False and m == 0:
+ if len(sorted_process_parameters) == 1:
+ self.env['purchase.order'].get_purchase_order(sorted_process_parameters,
+ production_item,
+ product_id_to_production_names)
+ else:
+ self.env['purchase.order'].get_purchase_order(sorted_process_parameters[i],
+ production_item,
+ product_id_to_production_names)
# # 同一个产品多个制造订单对应一个编程单和模型库
# # 只调用一次fetchCNC,并将所有生产订单的名称作为字符串传递
if not production_item.programming_no:
- 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 not production_programming.programming_no:
production_item.fetchCNC(
', '.join(product_id_to_production_names[production_item.product_id.id]))
@@ -544,7 +545,7 @@ class StockPicking(models.Model):
# 设置外协出入单的名称
def _get_name_Res(self, rescode):
- last_picking = self.sudo().search([('name', 'like', rescode)], order='create_date desc,id desc', limit=1)
+ last_picking = self.sudo().search([('name', 'ilike', rescode)], order='create_date desc,id desc', limit=1)
if not last_picking:
num = "%04d" % 1
else:
diff --git a/sf_manufacturing/views/mrp_production_addional_change.xml b/sf_manufacturing/views/mrp_production_addional_change.xml
index 6fa14a6f..58dc1513 100644
--- a/sf_manufacturing/views/mrp_production_addional_change.xml
+++ b/sf_manufacturing/views/mrp_production_addional_change.xml
@@ -437,6 +437,12 @@
+
+
+
diff --git a/sf_manufacturing/views/mrp_workorder_view.xml b/sf_manufacturing/views/mrp_workorder_view.xml
index 457ac122..a802266f 100644
--- a/sf_manufacturing/views/mrp_workorder_view.xml
+++ b/sf_manufacturing/views/mrp_workorder_view.xml
@@ -10,7 +10,7 @@
-
+
diff --git a/sf_mrs_connect/controllers/controllers.py b/sf_mrs_connect/controllers/controllers.py
index 6729ecc1..c5d1cd10 100644
--- a/sf_mrs_connect/controllers/controllers.py
+++ b/sf_mrs_connect/controllers/controllers.py
@@ -26,7 +26,7 @@ class Sf_Mrs_Connect(http.Controller):
logging.info('下发编程单:%s' % ret)
domain = [('programming_no', '=', ret['programming_no'])]
if ret['manufacturing_type'] == 'scrap':
- domain += [('state', 'not in', ['done', 'scrap'])]
+ domain += [('state', 'not in', ['done', 'scrap', 'cancel'])]
productions = request.env['mrp.production'].with_user(
request.env.ref("base.user_admin")).search(domain)
if productions:
diff --git a/sf_sale/models/sale_order.py b/sf_sale/models/sale_order.py
index 8e92040b..d19a3b02 100644
--- a/sf_sale/models/sale_order.py
+++ b/sf_sale/models/sale_order.py
@@ -225,45 +225,42 @@ class RePurchaseOrder(models.Model):
raise UserError('请对【产品】中的【税】进行选择')
def get_purchase_order(self, consecutive_process_parameters, production, product_id_to_production_names):
- is_exist = True
server_product_process = []
production_process = product_id_to_production_names.get(
production.product_id.id)
for pp in consecutive_process_parameters:
if pp.gain_way == '外协':
- server_product = self.env['product.template'].search(
+ server_template = self.env['product.template'].search(
[('server_product_process_parameters_id', '=', pp.id),
('detailed_type', '=', 'service')])
purchase_order_line = self.env['purchase.order.line'].search(
- [('product_id', '=', server_product.id), ('product_qty', '=', len(production_process))])
+ [('product_id', '=', server_template.product_variant_id.id),
+ ('product_qty', '=', len(production_process))], limit=1, order='id desc')
if not purchase_order_line:
- is_exist = False
server_product_process.append((0, 0, {
- 'product_id': server_product.product_variant_id.id,
+ 'product_id': server_template.product_variant_id.id,
'product_qty': len(production_process),
- 'product_uom': server_product.uom_id.id
+ 'product_uom': server_template.uom_id.id
}))
else:
for item in purchase_order_line:
- purchase_order = self.env['purchase.order'].search(
- [('state', '=', 'draft'), ('origin', 'ilike', production.name),
- ('id', '=', item.order_id.id)])
- if not purchase_order:
- is_exist = False
- server_product_process.append((0, 0, {
- 'product_id': server_product.product_variant_id.id,
- 'product_qty': len(production_process),
- 'product_uom': server_product.uom_id.id
- }))
- if is_exist is False:
- purchase_order = self.env['purchase.order'].search(
- [('state', '=', 'draft'), ('origin', '=', ','.join(production_process))])
- if not purchase_order or len(purchase_order) >= 1:
- self.env['purchase.order'].sudo().create({
- 'partner_id': server_product.seller_ids.partner_id.id,
- 'origin': ','.join(production_process),
- 'state': 'draft',
- 'order_line': server_product_process})
+ if production.name in production_process:
+ purchase_order = self.env['purchase.order'].search(
+ [('state', '=', 'draft'), ('origin', '=', ','.join(production_process)),
+ ('id', '=', item.order_id.id)])
+ if not purchase_order:
+ server_product_process.append((0, 0, {
+ 'product_id': server_template.product_variant_id.id,
+ 'product_qty': len(production_process),
+ 'product_uom': server_template.uom_id.id
+ }))
+ if server_product_process:
+ self.env['purchase.order'].sudo().create({
+ 'partner_id': server_template.seller_ids.partner_id.id,
+ 'origin': ','.join(production_process),
+ 'state': 'draft',
+ 'order_line': server_product_process})
+ # self.env.cr.commit()
@api.onchange('order_line')
def _onchange_order_line(self):