重写工单完成方法,添加接口调用

This commit is contained in:
mgw
2023-01-03 11:08:39 +08:00
parent ac383797e0
commit a5f79ea97d

View File

@@ -31,7 +31,7 @@ class ResMrpWorkOrder(models.Model):
], string="工序类型")
cnc_worksheet = fields.Binary(
'工作指令', readonly=True)
material_center_point = fields.Char(string='料中心点')
material_center_point = fields.Char(string='料中心点')
X1_axis = fields.Float(default=0)
Y1_axis = fields.Float(default=0)
Z1_axis = fields.Float(default=0)
@@ -284,6 +284,20 @@ class ResMrpWorkOrder(models.Model):
def button_start(self):
if self.state == 'waiting' or self.state == 'ready':
self.ensure_one()
if self.routing_type == '获取CNC加工程序':
json = {
'params': {
'model_name': 'jikimo.process.order',
'field_name': 'name',
'default_code': 'PO-2022-1123-0014',
'state': '加工中',
'date_start': datetime.now(),
},
}
url = 'https://bfm.cs.jikimo.com/api/get/state'
requests.post(url, json=json, data=None)
if any(not time.date_end for time in self.time_ids.filtered(lambda t: t.user_id.id == self.env.user.id)):
return True
# As button_start is automatically called in the new view
@@ -329,6 +343,41 @@ class ResMrpWorkOrder(models.Model):
else:
raise ValidationError(_('请先完成上一步工单'))
# 重写完成按钮
def button_finish(self):
end_date = datetime.now()
if self.routing_type == '解除装夹':
json = {
'params': {
'model_name': 'jikimo.process.order',
'field_name': 'name',
'default_code': 'PO-2022-1123-0014',
'state': '加工中',
'date_finishi': datetime.now(),
},
}
url = 'https://bfm.cs.jikimo.com/api/get/state'
requests.post(url, json=json, data=None)
for workorder in self:
if workorder.state in ('done', 'cancel'):
continue
workorder.end_all()
vals = {
'qty_produced': workorder.qty_produced or workorder.qty_producing or workorder.qty_production,
'state': 'done',
'date_finished': end_date,
'date_planned_finished': end_date,
'costs_hour': workorder.workcenter_id.costs_hour
}
if not workorder.date_start:
vals['date_start'] = end_date
if not workorder.date_planned_start or end_date < workorder.date_planned_start:
vals['date_planned_start'] = end_date
workorder.write(vals)
return True
class CNCprocessing(models.Model):
_name = 'sf.cnc.processing'
@@ -345,13 +394,13 @@ class CNCprocessing(models.Model):
depth_of_processing_z = fields.Char('加工深度(Z)')
cutting_tool_extension_length = fields.Char('刀具伸出长度')
cutting_tool_handle_type = fields.Char('刀柄型号')
estimated_processing_time = fields.Datetime('预计加工时间')
estimated_processing_time = fields.Char('预计加工时间')
remark = fields.Text('备注')
workorder_id = fields.Many2one('mrp.workorder', string="工单")
# mrs下发编程单创建CNC加工
def cnc_processing_create(self, obj):
workorder = self.env['mrp.workorder'].search([('production_id.name', '=', obj['manufacturing_order_no']),
workorder = self.env['mrp.workorder'].search([('production_id.name', '=', obj['production_order_no']),
('processing_panel', '=', obj['processing_panel']),
('routing_type', '=', 'CNC加工')])
vals = {