Merge branch develop into feature/增加一键合并下发功能,修正合并下发逻辑

This commit is contained in:
马广威
2023-04-24 14:33:44 +08:00
1075 changed files with 245703 additions and 5606 deletions

View File

@@ -29,7 +29,7 @@ class ResMrpWorkOrder(models.Model):
('CNC加工', 'CNC加工'),
('后置三元质量检测', '后置三元质量检测'),
('解除装夹', '解除装夹'),
('切割', '切割')
('切割', '切割'), ('表面工艺', '表面工艺')
], string="工序类型")
results = fields.Char('检测结果')
@@ -54,7 +54,7 @@ class ResMrpWorkOrder(models.Model):
programming_state = fields.Char('编程状态')
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)
@@ -91,6 +91,16 @@ class ResMrpWorkOrder(models.Model):
cnc_ids = fields.One2many("sf.cnc.processing", 'workorder_id', string="CNC加工")
tray_code = fields.Char(string="托盘")
glb_file = fields.Binary("glb模型文件")
is_subcontract = fields.Boolean(string='是否外协')
surface_technics_parameters_id = fields.Many2one('sf.production.process.parameter', string="表面工艺可选参数")
picking_in_id = fields.Many2one('stock.picking', string='外协入库单')
picking_out_id = fields.Many2one('stock.picking', string='外协出库单')
supplier_id = fields.Many2one('res.partner', string='外协供应商')
def get_no_data(self, production_id):
process_parameter_workorder = self.search(
[('surface_technics_parameters_id', '!=', False), ('production_id', '=', production_id)])
return process_parameter_workorder
# 计算配料中心点和与x轴倾斜度方法
def getcenter(self):
@@ -137,7 +147,7 @@ class ResMrpWorkOrder(models.Model):
except:
raise UserError("参数计算有误")
#拼接工单对象属性值
# 拼接工单对象属性值
def json_workorder_str(self, k, production, route):
workorders_values_str = [0, '', {
'product_uom_id': production.product_uom_id.id,
@@ -145,6 +155,7 @@ class ResMrpWorkOrder(models.Model):
'operation_id': False,
'name': route.route_workcenter_id.name,
'processing_panel': k,
'quality_point_ids':route.route_workcenter_id.quality_point_ids,
'routing_type': route.routing_type,
'work_state': '' if not route.routing_type == '获取CNC加工程序' else '待发起',
'workcenter_id': self.env['mrp.routing.workcenter'].get_workcenter(route.workcenter_ids.ids,
@@ -153,6 +164,32 @@ class ResMrpWorkOrder(models.Model):
'date_planned_start': False,
'date_planned_finished': False,
'duration_expected': 60,
'duration': 0,
}]
return workorders_values_str
# 拼接工单对象属性值(表面工艺)
def _json_workorder_surface_process_str(self, production, route, process_parameter, supplier_id):
workorders_values_str = [0, '', {
'product_uom_id': production.product_uom_id.id,
'qty_producing': 0,
'operation_id': False,
'name': '%s-%s' % (route.name, process_parameter.name),
'processing_panel': '',
'routing_type': '表面工艺',
'surface_technics_parameters_id': process_parameter.id,
'work_state': '',
'supplier_id': supplier_id,
'is_subcontract': True if process_parameter.gain_way == '外协' else False,
'workcenter_id': self.env[
'mrp.workcenter'].get_process_outsourcing_workcenter() if process_parameter.gain_way == '外协' else
self.env['mrp.routing.workcenter'].get_workcenter(route.workcenter_ids.ids,
route.routing_type,
production.product_id),
'date_planned_start': False,
'date_planned_finished': False,
'duration_expected': 60,
'duration': 0
}]
return workorders_values_str
@@ -203,9 +240,9 @@ class ResMrpWorkOrder(models.Model):
else:
raise UserError('托盘码不能为空')
#验证坯料序列号是否正确
def pro_code_is_ok(self,barcode):
if barcode!=False:
# 验证坯料序列号是否正确
def pro_code_is_ok(self, barcode):
if barcode != False:
if barcode != self.pro_code:
raise UserError('坯料序列号错误')
return False
@@ -216,7 +253,7 @@ class ResMrpWorkOrder(models.Model):
pro_code_ok = fields.Boolean(default=False)
#托盘扫码绑定
# 托盘扫码绑定
def gettray_auto(self, barcode):
if barcode != False:
values = self.env['sf.tray'].search([("code", "=", barcode)])
@@ -255,7 +292,6 @@ class ResMrpWorkOrder(models.Model):
else:
raise UserError('托盘码不能为空')
# 解除托盘绑定
def unbindtray(self):
tray = self.env['sf.tray'].search([("production_id", "=", self.production_id.id)])
@@ -389,16 +425,17 @@ class ResMrpWorkOrder(models.Model):
'date_planned_start': False,
'date_planned_finished': False,
'duration_expected': 60,
'duration': 0
'duration': 0,
}]
return workorders_values_str
# 重写工单开始按钮方法
def button_start(self):
if self.routing_type == '装夹':
self.pro_code = self.production_id.move_raw_ids[0].move_line_ids[0].lot_id.name
if self.state == 'waiting' or self.state == 'ready' or self.state == 'progress':
self.move_raw_ids = self.production_id.move_raw_ids
self.ensure_one()
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
@@ -445,6 +482,51 @@ class ResMrpWorkOrder(models.Model):
else:
raise UserError(_('请先完成上一步工单'))
def button_finish(self):
end_date = datetime.now()
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.with_context(bypass_duration_calculation=True).write(vals)
self.env.cr.commit()
finish_workorder_count = self.env['mrp.workorder'].search_count(
[('production_id', '=', workorder.production_id.id),
('is_subcontract', '=', True)])
subcontract_workorder_count = self.env['mrp.workorder'].search_count(
[('production_id', '=', workorder.production_id.id), ('is_subcontract', '=', True),
('state', '=', 'done')])
if finish_workorder_count > 0 and subcontract_workorder_count > 0:
subcontract_workorder = self.env['mrp.workorder'].search(
[('production_id', '=', workorder.production_id.id), ('is_subcontract', '=', True),
('state', '=', 'done')])
for item in subcontract_workorder:
order_line_ids = []
server_product = self.env['product.template'].search(
[('server_product_process_parameters_id', '=', item.surface_technics_parameters_id.id),
('categ_type', '=', '服务'), ('detailed_type', '=', 'service')])
order_line_ids.append((0, 0, {
'product_id': server_product.product_variant_id.id,
'product_qty': 1,
'product_uom': server_product.uom_id.id
}))
self.env['purchase.order'].create({
'partner_id': server_product.seller_ids.partner_id.id,
'state': 'draft',
'order_line': order_line_ids,
})
class CNCprocessing(models.Model):
_name = 'sf.cnc.processing'
@@ -467,7 +549,6 @@ class CNCprocessing(models.Model):
workorder_id = fields.Many2one('mrp.workorder', string="工单")
button_state = fields.Boolean(string='是否已经下发')
# mrs下发编程单创建CNC加工
def cnc_processing_create(self, cnc_workorder, ret):
logging.info('ret:%s' % ret)
@@ -550,6 +631,25 @@ class CNCprocessing(models.Model):
else:
return False
# end_date = datetime.now()
# 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.with_context(bypass_duration_calculation=True).write(vals)
return True
class SfWorkOrderBarcodes(models.Model):
"""