更新工艺外协流程的采购单查询逻辑
This commit is contained in:
@@ -239,7 +239,8 @@ class MrpProduction(models.Model):
|
|||||||
programming_no = fields.Char('编程单号')
|
programming_no = fields.Char('编程单号')
|
||||||
work_state = fields.Char('业务状态')
|
work_state = fields.Char('业务状态')
|
||||||
programming_state = fields.Selection(
|
programming_state = fields.Selection(
|
||||||
[('编程中', '编程中'), ('已编程', '已编程'), ('已编程未下发', '已编程未下发'), ('已下发', '已下发'), ('已取消', '已取消')],
|
[('编程中', '编程中'), ('已编程', '已编程'), ('已编程未下发', '已编程未下发'), ('已下发', '已下发'),
|
||||||
|
('已取消', '已取消')],
|
||||||
string='编程状态',
|
string='编程状态',
|
||||||
tracking=True)
|
tracking=True)
|
||||||
glb_file = fields.Binary("glb模型文件")
|
glb_file = fields.Binary("glb模型文件")
|
||||||
@@ -268,6 +269,7 @@ class MrpProduction(models.Model):
|
|||||||
quality_standard = fields.Binary('质检标准', related='product_id.quality_standard', readonly=True)
|
quality_standard = fields.Binary('质检标准', related='product_id.quality_standard', readonly=True)
|
||||||
|
|
||||||
part_name = fields.Char(string='零件名称', compute='_compute_part_info', store=True)
|
part_name = fields.Char(string='零件名称', compute='_compute_part_info', store=True)
|
||||||
|
|
||||||
@api.depends('product_id')
|
@api.depends('product_id')
|
||||||
def _compute_part_info(self):
|
def _compute_part_info(self):
|
||||||
try:
|
try:
|
||||||
@@ -401,8 +403,10 @@ class MrpProduction(models.Model):
|
|||||||
and production.schedule_state == '已排' and production.is_rework is False):
|
and production.schedule_state == '已排' and production.is_rework is False):
|
||||||
production.state = 'pending_cam'
|
production.state = 'pending_cam'
|
||||||
if any((wo.test_results == '返工' and wo.state == 'done' and
|
if any((wo.test_results == '返工' and wo.state == 'done' and
|
||||||
(production.programming_state in ['已编程'] or(wo.individuation_page_list and 'PTD' in wo.individuation_page_list)))
|
(production.programming_state in ['已编程'] or (
|
||||||
or (wo.is_rework is True and wo.state == 'done' and production.programming_state in ['编程中', '已编程'])
|
wo.individuation_page_list and 'PTD' in wo.individuation_page_list)))
|
||||||
|
or (wo.is_rework is True and wo.state == 'done' and production.programming_state in ['编程中',
|
||||||
|
'已编程'])
|
||||||
for wo in production.workorder_ids) or production.is_rework is True:
|
for wo in production.workorder_ids) or production.is_rework is True:
|
||||||
production.state = 'rework'
|
production.state = 'rework'
|
||||||
if any(wo.test_results == '报废' and wo.state == 'done' for wo in production.workorder_ids):
|
if any(wo.test_results == '报废' and wo.state == 'done' for wo in production.workorder_ids):
|
||||||
@@ -618,7 +622,7 @@ class MrpProduction(models.Model):
|
|||||||
for rp in reproduction:
|
for rp in reproduction:
|
||||||
if rp.programming_no == item['programming_no']:
|
if rp.programming_no == item['programming_no']:
|
||||||
rp.write({'programming_state': '已编程未下发' if item[
|
rp.write({'programming_state': '已编程未下发' if item[
|
||||||
'programming_state'] == '已编程' else '编程中'})
|
'programming_state'] == '已编程' else '编程中'})
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return item
|
return item
|
||||||
@@ -890,12 +894,13 @@ class MrpProduction(models.Model):
|
|||||||
workorders_values.append(
|
workorders_values.append(
|
||||||
self.env[
|
self.env[
|
||||||
'mrp.workorder']._json_workorder_surface_process_str(
|
'mrp.workorder']._json_workorder_surface_process_str(
|
||||||
production, route, product_production_process.seller_ids[0].partner_id.id if product_production_process.seller_ids else False))
|
production, route, product_production_process.seller_ids[
|
||||||
|
0].partner_id.id if product_production_process.seller_ids else False))
|
||||||
production.workorder_ids = workorders_values
|
production.workorder_ids = workorders_values
|
||||||
for workorder in production.workorder_ids:
|
for workorder in production.workorder_ids:
|
||||||
workorder.duration_expected = workorder._get_duration_expected()
|
workorder.duration_expected = workorder._get_duration_expected()
|
||||||
|
|
||||||
def _create_subcontract_purchase_request(self,purchase_request_line):
|
def _create_subcontract_purchase_request(self, purchase_request_line):
|
||||||
sorted_list = sorted(purchase_request_line, key=itemgetter('name'))
|
sorted_list = sorted(purchase_request_line, key=itemgetter('name'))
|
||||||
grouped_purchase_request_line = {
|
grouped_purchase_request_line = {
|
||||||
k: list(g)
|
k: list(g)
|
||||||
@@ -908,22 +913,25 @@ class MrpProduction(models.Model):
|
|||||||
for k, g in groupby(request_line_sorted_list, key=itemgetter('product_id'))
|
for k, g in groupby(request_line_sorted_list, key=itemgetter('product_id'))
|
||||||
}
|
}
|
||||||
purchase_request_model = self.env["purchase.request"]
|
purchase_request_model = self.env["purchase.request"]
|
||||||
|
origin = ", ".join({item['production_name'] for item in request_line_sorted_list if item.get('production_name')})
|
||||||
pr = purchase_request_model.create({
|
pr = purchase_request_model.create({
|
||||||
"origin": name,
|
"origin": origin,
|
||||||
"company_id": self.company_id.id,
|
"company_id": self.company_id.id,
|
||||||
"picking_type_id": self.env.ref('stock.picking_type_in').id,
|
"picking_type_id": self.env.ref('stock.picking_type_in').id,
|
||||||
"group_id": request_line[0].get('group_id'),
|
"group_id": request_line[0].get('group_id'),
|
||||||
"requested_by": self.env.context.get("uid", self.env.uid),
|
"requested_by": self.env.context.get("uid", self.env.uid),
|
||||||
"assigned_to": False,
|
"assigned_to": False,
|
||||||
"bom_id":self[0].bom_id.id,
|
"bom_id": self[0].bom_id.id,
|
||||||
})
|
})
|
||||||
for product_id, request_line_list in grouped_purchase_request_line_sorted_list.items():
|
for product_id, request_line_list in grouped_purchase_request_line_sorted_list.items():
|
||||||
cur_request_line = request_line_list[0]
|
cur_request_line = request_line_list[0]
|
||||||
cur_request_line['product_qty'] = len(request_line_list)
|
cur_request_line['product_qty'] = len(request_line_list)
|
||||||
cur_request_line['request_id'] = pr.id
|
cur_request_line['request_id'] = pr.id
|
||||||
cur_request_line['origin'] = name
|
cur_request_line['origin'] = ", ".join({item['production_name'] for item in request_line_list if item.get('production_name')})
|
||||||
cur_request_line.pop('group_id', None)
|
cur_request_line.pop('group_id', None)
|
||||||
|
cur_request_line.pop('production_name', None)
|
||||||
self.env["purchase.request.line"].create(cur_request_line)
|
self.env["purchase.request.line"].create(cur_request_line)
|
||||||
|
|
||||||
# 外协出入库单处理
|
# 外协出入库单处理
|
||||||
def get_subcontract_pick_purchase(self):
|
def get_subcontract_pick_purchase(self):
|
||||||
production_all = self.sorted(lambda x: x.id)
|
production_all = self.sorted(lambda x: x.id)
|
||||||
@@ -951,7 +959,8 @@ class MrpProduction(models.Model):
|
|||||||
for workorders in reversed(sorted_workorders):
|
for workorders in reversed(sorted_workorders):
|
||||||
self.env['stock.picking'].create_outcontract_picking(workorders, production, sorted_workorders)
|
self.env['stock.picking'].create_outcontract_picking(workorders, production, sorted_workorders)
|
||||||
# self.env['purchase.order'].get_purchase_order(workorders, production, product_id_to_production_names)
|
# self.env['purchase.order'].get_purchase_order(workorders, production, product_id_to_production_names)
|
||||||
purchase_request_line = purchase_request_line + self.env['purchase.order'].get_purchase_request(workorders, production)
|
purchase_request_line = purchase_request_line + self.env['purchase.order'].get_purchase_request(
|
||||||
|
workorders, production)
|
||||||
self._create_subcontract_purchase_request(purchase_request_line)
|
self._create_subcontract_purchase_request(purchase_request_line)
|
||||||
|
|
||||||
# 工单排序
|
# 工单排序
|
||||||
@@ -1374,7 +1383,7 @@ class MrpProduction(models.Model):
|
|||||||
'default_reprogramming_num': cloud_programming.get('reprogramming_num') if cloud_programming else '',
|
'default_reprogramming_num': cloud_programming.get('reprogramming_num') if cloud_programming else '',
|
||||||
'default_programming_state': cloud_programming.get('programming_state') if cloud_programming else '',
|
'default_programming_state': cloud_programming.get('programming_state') if cloud_programming else '',
|
||||||
'default_is_reprogramming': True if cloud_programming and (
|
'default_is_reprogramming': True if cloud_programming and (
|
||||||
cloud_programming.get('programming_state') in ['已下发']) else False
|
cloud_programming.get('programming_state') in ['已下发']) else False
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1761,7 +1770,8 @@ class MrpProduction(models.Model):
|
|||||||
raise UserError('仅支持选择单个制造订单进行编程申请,请重新选择')
|
raise UserError('仅支持选择单个制造订单进行编程申请,请重新选择')
|
||||||
for production in self:
|
for production in self:
|
||||||
if production.state not in ['confirmed', 'pending_cam'] or production.programming_state != '已编程':
|
if production.state not in ['confirmed', 'pending_cam'] or production.programming_state != '已编程':
|
||||||
raise UserError('不可操作。所选制造订单必须同时满足如下条件:\n1、制造订单状态:待排程 或 待加工;\n2、制造订单编程状态:已编程。\n请检查!')
|
raise UserError(
|
||||||
|
'不可操作。所选制造订单必须同时满足如下条件:\n1、制造订单状态:待排程 或 待加工;\n2、制造订单编程状态:已编程。\n请检查!')
|
||||||
cloud_programming = production._cron_get_programming_state()
|
cloud_programming = production._cron_get_programming_state()
|
||||||
if cloud_programming['programming_state'] in ['待编程', '已编程', '编程中']:
|
if cloud_programming['programming_state'] in ['待编程', '已编程', '编程中']:
|
||||||
raise UserError("当前编程单正在重新编程,请注意查看当前制造订单的“编程记录”确认进度!")
|
raise UserError("当前编程单正在重新编程,请注意查看当前制造订单的“编程记录”确认进度!")
|
||||||
|
|||||||
@@ -429,11 +429,11 @@ class ResMrpWorkOrder(models.Model):
|
|||||||
def _compute_surface_technics_purchase_ids(self):
|
def _compute_surface_technics_purchase_ids(self):
|
||||||
for order in self:
|
for order in self:
|
||||||
if order.routing_type == '表面工艺' and order.state not in ['cancel']:
|
if order.routing_type == '表面工艺' and order.state not in ['cancel']:
|
||||||
domain = [('group_id', '=', self.production_id.procurement_group_id.id),
|
# domain = [('group_id', '=', self.production_id.procurement_group_id.id),
|
||||||
('purchase_type', '=', 'consignment'), ('state', '!=', 'cancel')]
|
# ('purchase_type', '=', 'consignment'), ('state', '!=', 'cancel')]
|
||||||
# domain = [('purchase_type', '=', 'consignment'),
|
domain = [('purchase_type', '=', 'consignment'),
|
||||||
# ('origin', 'like', '%' + self.production_id.name + '%'),
|
('origin', 'like', '%' + self.production_id.name + '%'),
|
||||||
# ('state', '!=', 'cancel')]
|
('state', '!=', 'cancel')]
|
||||||
purchase = self.env['purchase.order'].search(domain)
|
purchase = self.env['purchase.order'].search(domain)
|
||||||
order.surface_technics_purchase_count = 0
|
order.surface_technics_purchase_count = 0
|
||||||
if not purchase:
|
if not purchase:
|
||||||
@@ -474,8 +474,8 @@ class ResMrpWorkOrder(models.Model):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
def _get_surface_technics_purchase_ids(self):
|
def _get_surface_technics_purchase_ids(self):
|
||||||
# domain = [('origin', 'like', '%' + self.production_id.name + '%'), ('purchase_type', '=', 'consignment')]
|
domain = [('origin', 'like', '%' + self.production_id.name + '%'), ('purchase_type', '=', 'consignment')]
|
||||||
domain = [('group_id', '=', self.production_id.procurement_group_id.id), ('purchase_type', '=', 'consignment')]
|
# domain = [('group_id', '=', self.production_id.procurement_group_id.id), ('purchase_type', '=', 'consignment')]
|
||||||
purchase_orders = self.env['purchase.order'].search(domain, order='id desc', # 按创建时间降序(最新的在前)
|
purchase_orders = self.env['purchase.order'].search(domain, order='id desc', # 按创建时间降序(最新的在前)
|
||||||
limit=1)
|
limit=1)
|
||||||
purchase_orders_id = self.env['purchase.order']
|
purchase_orders_id = self.env['purchase.order']
|
||||||
|
|||||||
@@ -398,6 +398,7 @@ class RePurchaseOrder(models.Model):
|
|||||||
"orderpoint_id": False,
|
"orderpoint_id": False,
|
||||||
'is_subcontract':True,
|
'is_subcontract':True,
|
||||||
'group_id':production.procurement_group_id.id,
|
'group_id':production.procurement_group_id.id,
|
||||||
|
'production_name':pp.production_id.name,
|
||||||
})
|
})
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user