去掉重写state方法

This commit is contained in:
jinling.yang
2024-06-04 15:59:35 +08:00
parent 6fc94042ee
commit 8bd5841d7a
2 changed files with 28 additions and 22 deletions

View File

@@ -77,6 +77,7 @@ class MrpProduction(models.Model):
part_drawing = fields.Binary('零件图纸') part_drawing = fields.Binary('零件图纸')
manual_quotation = fields.Boolean('人工编程', default=False, readonly=True) manual_quotation = fields.Boolean('人工编程', default=False, readonly=True)
rework_production = fields.Many2one('mrp.production', string='返工的制造订单')
@api.depends( @api.depends(
'move_raw_ids.state', 'move_raw_ids.quantity_done', 'move_finished_ids.state', 'move_raw_ids.state', 'move_raw_ids.quantity_done', 'move_finished_ids.state',

View File

@@ -809,28 +809,28 @@ class ResMrpWorkOrder(models.Model):
}] }]
return workorders_values_str return workorders_values_str
@api.depends('production_availability', 'blocked_by_workorder_ids', 'blocked_by_workorder_ids.state') # @api.depends('production_availability', 'blocked_by_workorder_ids', 'blocked_by_workorder_ids.state')
def _compute_state(self): # def _compute_state(self):
super(ResMrpWorkOrder, self)._compute_state() # super(ResMrpWorkOrder, self)._compute_state()
for item in self: # for item in self:
print(item.name) # print(item.name)
print(item.state) # print(item.state)
print(item.is_remanufacture) # print(item.is_remanufacture)
scrap_workorder = self.env['mrp.workorder'].search( # scrap_workorder = self.env['mrp.workorder'].search(
[('production_id', '=', item.production_id.id), ('routing_type', '=', 'CNC加工'), # [('production_id', '=', item.production_id.id), ('routing_type', '=', 'CNC加工'),
('state', '=', 'done'), ('test_results', 'in', ['返工', '报废'])]) # ('state', '=', 'done'), ('test_results', 'in', ['返工', '报废'])])
print(scrap_workorder) # print(scrap_workorder)
# if item.routing_type == 'CNC加工' and item.state in ['done'] and item.test_results in ['返工', '报废']: # # if item.routing_type == 'CNC加工' and item.state in ['done'] and item.test_results in ['返工', '报废']:
if item.routing_type == '解除装夹': # if item.routing_type == '解除装夹':
if scrap_workorder and item.state not in ['cancel']: # if scrap_workorder and item.state not in ['cancel']:
item.state = 'cancel' # item.state = 'cancel'
elif item.routing_type == '表面工艺': # elif item.routing_type == '表面工艺':
if scrap_workorder: # if scrap_workorder:
stock_move = self.env['stock.move'].search( # stock_move = self.env['stock.move'].search(
[('origin', '=', item.production_id.name)]) # [('origin', '=', item.production_id.name)])
stock_move.write({'state': 'cancel'}) # stock_move.write({'state': 'cancel'})
item.picking_ids.write({'state': 'cancel'}) # item.picking_ids.write({'state': 'cancel'})
item.state = 'cancel' # item.state = 'cancel'
# 重写工单开始按钮方法 # 重写工单开始按钮方法
def button_start(self): def button_start(self):
@@ -987,6 +987,7 @@ class ResMrpWorkOrder(models.Model):
raise UserError( raise UserError(
'请先在产品中配置表面工艺为%s相关的外协服务产品' % item.surface_technics_parameters_id.name) '请先在产品中配置表面工艺为%s相关的外协服务产品' % item.surface_technics_parameters_id.name)
tem_date_planned_finished = record.date_planned_finished tem_date_planned_finished = record.date_planned_finished
tem_date_finished = record.date_finished
logging.info('routing_type:%s' % record.routing_type) logging.info('routing_type:%s' % record.routing_type)
super().button_finish() super().button_finish()
logging.info('date_planned_finished:%s' % record.date_planned_finished) logging.info('date_planned_finished:%s' % record.date_planned_finished)
@@ -995,6 +996,10 @@ class ResMrpWorkOrder(models.Model):
record.write({ record.write({
'date_planned_finished': tem_date_planned_finished # 保持原值 'date_planned_finished': tem_date_planned_finished # 保持原值
}) })
if record.routing_type == 'CNC加工':
record.write({
'date_finished': tem_date_finished # 保持原值
})
if record.routing_type == 'CNC加工' and record.test_results in ['返工', '报废']: if record.routing_type == 'CNC加工' and record.test_results in ['返工', '报废']:
record.production_id.action_cancel() record.production_id.action_cancel()
record.production_id.workorder_ids.write({'rfid_code': False, 'rfid_code_old': record.rfid_code}) record.production_id.workorder_ids.write({'rfid_code': False, 'rfid_code_old': record.rfid_code})