增加取消订单其他功能

This commit is contained in:
mgw
2025-02-14 17:29:33 +08:00
parent 3ac096e9a7
commit e98a9a3788
2 changed files with 152 additions and 11 deletions

View File

@@ -701,14 +701,14 @@ class MrpProduction(models.Model):
config_url = configsettings['sf_url'] + url config_url = configsettings['sf_url'] + url
res['token'] = configsettings['token'] res['token'] = configsettings['token']
# res_str = json.dumps(res) # res_str = json.dumps(res)
ret = requests.post(config_url, json={}, data=res, headers=config_header) # ret = requests.post(config_url, json={}, data=res, headers=config_header)
ret = ret.json() # ret = ret.json()
logging.info('fetchCNC-ret:%s' % ret) # logging.info('fetchCNC-ret:%s' % ret)
if ret['status'] == 1: # if ret['status'] == 1:
self.write( # self.write(
{'programming_no': ret['programming_no'], 'programming_state': '编程中', 'work_state': '编程中'}) # {'programming_no': ret['programming_no'], 'programming_state': '编程中', 'work_state': '编程中'})
else: # else:
raise UserError(ret['message']) # raise UserError(ret['message'])
except Exception as e: except Exception as e:
logging.info('fetchCNC error:%s' % e) logging.info('fetchCNC error:%s' % e)
raise UserError("cnc程序获取编程单失败,请联系管理员") raise UserError("cnc程序获取编程单失败,请联系管理员")
@@ -1704,7 +1704,7 @@ class sf_programming_record(models.Model):
programming_method = fields.Selection([ programming_method = fields.Selection([
('auto', '自动'), ('auto', '自动'),
('manual operation', '人工')], string="编程方式") ('manual operation', '人工')], string="编程方式")
current_programming_count = fields.Integer('当前编程次数') current_programming_count = fields.Integer('重新编程次数')
target_production_id = fields.Char('目标制造单号') target_production_id = fields.Char('目标制造单号')
apply_time = fields.Datetime('申请时间') apply_time = fields.Datetime('申请时间')
send_time = fields.Datetime('下发时间') send_time = fields.Datetime('下发时间')

View File

@@ -80,22 +80,163 @@ class SFSaleOrderCancelLine(models.TransientModel):
lines.append(self.create(vals)) lines.append(self.create(vals))
sequence += 1 sequence += 1
# 检查销售订单直接关联的采购单
purchase_orders = self.env['purchase.order'].search([
('origin', '=', order.name)
])
if purchase_orders:
for po in purchase_orders:
vals = {
'wizard_id': wizard_id,
'sequence': sequence,
'category': '采购',
'doc_name': '采购单',
'operation_type': '销售采购',
'doc_number': po.name,
'product_name': po.order_line[0].product_id.name if po.order_line else '',
'quantity': po.order_line[0].product_qty if po.order_line else 0,
'doc_state': po.state,
'cancel_reason': '已有异动' if po.state not in ['draft', 'cancel'] else ''
}
lines.append(self.create(vals))
sequence += 1
# 检查制造订单 # 检查制造订单
manufacturing_orders = self.env['mrp.production'].search([ manufacturing_orders = self.env['mrp.production'].search([
('origin', '=', order.name) ('origin', '=', order.name)
]) ])
for mo in manufacturing_orders: for mo in manufacturing_orders:
# 添加制造订单本身
vals = { vals = {
'wizard_id': wizard_id, 'wizard_id': wizard_id,
'sequence': sequence, 'sequence': sequence,
'category': '制造', 'category': '制造',
'doc_name': '制造订单', 'doc_name': '制造订单',
'operation_type': '制造',
'doc_number': mo.name, 'doc_number': mo.name,
'product_name': mo.product_id.name, 'product_name': mo.product_id.name,
'quantity': mo.product_qty, 'quantity': mo.product_qty,
'doc_state': mo.state, 'doc_state': mo.state,
'cancel_reason': '已有异动' if mo.state not in ['draft', 'cancel'] else '' 'cancel_reason': '已有异动' if mo.state not in ['technology_to_confirmed'] else ''
}
lines.append(self.create(vals))
sequence += 1
# 检查制造订单关联的采购单
purchase_orders = self.env['purchase.order'].search([
('origin', '=', mo.name)
])
if purchase_orders:
for po in purchase_orders:
vals = {
'wizard_id': wizard_id,
'sequence': sequence,
'category': '制造',
'doc_name': '采购单',
'doc_number': po.name,
'operation_type': '制造采购',
'product_name': po.order_line[0].product_id.name if po.order_line else '',
'quantity': po.order_line[0].product_qty if po.order_line else 0,
'doc_state': po.state,
'cancel_reason': '已有异动' if po.state not in ['draft', 'cancel'] else ''
}
lines.append(self.create(vals))
sequence += 1
# 检查制造订单的领料单
if mo.picking_ids:
for picking in mo.picking_ids:
vals = {
'wizard_id': wizard_id,
'sequence': sequence,
'category': '制造',
'doc_name': '领料单',
'doc_number': picking.name,
'operation_type': picking.picking_type_id.name,
'product_name': picking.product_id.name if picking.product_id else '',
'quantity': picking.product_qty if hasattr(picking, 'product_qty') else 0,
'doc_state': picking.state,
'cancel_reason': '已有异动' if picking.state not in ['draft', 'cancel', 'waiting'] else ''
}
lines.append(self.create(vals))
sequence += 1
# 检查制造订单的工单
if mo.workorder_ids:
for workorder in mo.workorder_ids:
vals = {
'wizard_id': wizard_id,
'sequence': sequence,
'category': '制造',
'doc_name': '工单',
'doc_number': workorder.name,
'operation_type': workorder.workcenter_id.name,
'product_name': mo.product_id.name,
'quantity': workorder.qty_production,
'doc_state': workorder.state,
'cancel_reason': '已有异动' if workorder.state not in ['draft', 'cancel', 'pending'] else ''
}
lines.append(self.create(vals))
sequence += 1
# 检查制造订单组件的采购单和制造单
for move in mo.move_raw_ids:
# 检查组件的采购单
component_pos = self.env['purchase.order'].search([
('origin', '=', mo.name),
('order_line.product_id', '=', move.product_id.id)
])
for po in component_pos:
vals = {
'wizard_id': wizard_id,
'sequence': sequence,
'category': '制造',
'doc_name': '组件采购单',
'operation_type': '组件采购',
'doc_number': po.name,
'product_name': move.product_id.name,
'quantity': po.order_line[0].product_qty if po.order_line else 0,
'doc_state': po.state,
'cancel_reason': '已有异动' if po.state not in ['draft', 'cancel'] else ''
}
lines.append(self.create(vals))
sequence += 1
# 检查组件的制造单
component_mos = self.env['mrp.production'].search([
('origin', '=', mo.name),
('product_id', '=', move.product_id.id)
])
for comp_mo in component_mos:
vals = {
'wizard_id': wizard_id,
'sequence': sequence,
'category': '制造',
'doc_name': '组件制造单',
'operation_type': '组件制造',
'doc_number': comp_mo.name,
'product_name': move.product_id.name,
'quantity': comp_mo.product_qty,
'doc_state': comp_mo.state,
'cancel_reason': '已有异动' if comp_mo.state not in ['technology_to_confirmed'] else ''
}
lines.append(self.create(vals))
sequence += 1
# 检查制造订单的质检单
quality_checks = self.env['quality.check'].search([
('production_id', '=', mo.id)
])
if quality_checks:
for check in quality_checks:
vals = {
'wizard_id': wizard_id,
'sequence': sequence,
'category': '制造',
'doc_name': '质检单',
'doc_number': check.name,
'product_name': check.product_id.name,
'doc_state': check.state,
'cancel_reason': '已有异动' if check.state not in ['draft', 'cancel'] else ''
} }
lines.append(self.create(vals)) lines.append(self.create(vals))
sequence += 1 sequence += 1