移除托盘对象 并清除所有关联关系

This commit is contained in:
qihao.gong@jikimo.com
2023-08-17 16:33:40 +08:00
parent 6193fa3c09
commit 08ac2978a1
12 changed files with 291 additions and 292 deletions

View File

@@ -99,7 +99,7 @@ class ResMrpWorkOrder(models.Model):
test_results = fields.Selection([("合格", "合格"), ("返工", "返工"), ("报废", "报废")], default='合格',
string="检测结果")
cnc_ids = fields.One2many("sf.cnc.processing", 'workorder_id', string="CNC加工")
tray_code = fields.Char(string="托盘")
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="表面工艺可选参数")
@@ -252,32 +252,32 @@ class ResMrpWorkOrder(models.Model):
'domain': [('workorder_id', '=', self.id)]
}
tray_id = fields.Many2one('sf.tray', string="托盘信息", tracking=True)
# tray_id = fields.Many2one('sf.tray', string="托盘信息", tracking=True)
# 扫码绑定托盘方法
def gettray(self):
if self.tray_code != False:
values = self.env['sf.tray'].search([("code", "=", self.tray_code)])
if values:
if values.state == "占用":
raise UserError('该托盘已占用')
if values.state == "报损":
raise UserError('该托盘已损坏')
else:
values.update({
'workorder_id': self,
'production_id': self.production_id,
'state': '占用',
})
self.work_state = "已绑定"
orders = self.env['mrp.workorder'].search([('production_id', '=', self.production_id.id)])
for a in orders:
a.tray_id = values
else:
raise UserError('该托盘编码已失效')
else:
raise UserError('托盘码不能为空')
# def gettray(self):
# if self.tray_code != False:
# values = self.env['sf.tray'].search([("code", "=", self.tray_code)])
# if values:
# if values.state == "占用":
# raise UserError('该托盘已占用')
# if values.state == "报损":
# raise UserError('该托盘已损坏')
# else:
# values.update({
# 'workorder_id': self,
# 'production_id': self.production_id,
# 'state': '占用',
# })
# self.work_state = "已绑定"
# orders = self.env['mrp.workorder'].search([('production_id', '=', self.production_id.id)])
# for a in orders:
# a.tray_id = values
# else:
# raise UserError('该托盘编码已失效')
# else:
# raise UserError('托盘码不能为空')
# 验证坯料序列号是否正确
def pro_code_is_ok(self, barcode):
@@ -293,50 +293,50 @@ 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)])
if values:
if values.state == "占用":
raise UserError('该托盘已占用')
if values.state == "报损":
raise UserError('该托盘已损坏')
else:
values.update({
'workorder_id': self,
'production_id': self.production_id,
'state': '占用',
})
self.work_state = "已绑定"
orders = self.env['mrp.workorder'].search([('production_id', '=', self.production_id.id)])
for a in orders:
a.tray_id = values
return values
# return {
# 'name': _('New Maintenance Request'),
# 'view_mode': 'form',
# 'res_model': 'maintenance.request',
# 'type': 'ir.actions.act_window',
# 'context': {
# 'default_company_id': self.company_id.id,
# 'default_production_id': self.id,
# },
# 'domain': [('production_id', '=', self.id)],
# }
else:
raise UserError('该托盘编码已失效')
else:
raise UserError('托盘码不能为空')
# def gettray_auto(self, barcode):
# if barcode != False:
# values = self.env['sf.tray'].search([("code", "=", barcode)])
#
# if values:
# if values.state == "占用":
# raise UserError('该托盘已占用')
# if values.state == "报损":
# raise UserError('该托盘已损坏')
# else:
# values.update({
# 'workorder_id': self,
# 'production_id': self.production_id,
# 'state': '占用',
# })
# self.work_state = "已绑定"
# orders = self.env['mrp.workorder'].search([('production_id', '=', self.production_id.id)])
# for a in orders:
# a.tray_id = values
#
# return values
#
# # return {
# # 'name': _('New Maintenance Request'),
# # 'view_mode': 'form',
# # 'res_model': 'maintenance.request',
# # 'type': 'ir.actions.act_window',
# # 'context': {
# # 'default_company_id': self.company_id.id,
# # 'default_production_id': self.id,
# # },
# # 'domain': [('production_id', '=', self.id)],
# # }
# else:
# raise UserError('该托盘编码已失效')
# else:
# raise UserError('托盘码不能为空')
# 解除托盘绑定
def unbindtray(self):
tray = self.env['sf.tray'].search([("production_id", "=", self.production_id.id)])
if tray:
tray.unclamp()
self.tray_id = False
# def unbindtray(self):
# tray = self.env['sf.tray'].search([("production_id", "=", self.production_id.id)])
# if tray:
# tray.unclamp()
# self.tray_id = False
# return {
# 'name': _('New Maintenance Request'),
@@ -682,51 +682,51 @@ class SfWorkOrderBarcodes(models.Model):
_name = "mrp.workorder"
_inherit = ["mrp.workorder", "barcodes.barcode_events_mixin"]
def on_barcode_scanned(self, barcode):
workorder = self.env['mrp.workorder'].browse(self.ids)
if "*" not in barcode:
if self.routing_type == '装夹':
tray_code = self.env['sf.tray'].search([('code', '=', barcode)])
self.tray_code = tray_code.code
self.tray_id = workorder.gettray_auto(barcode)
elif self.routing_type == '前置三元定位检测':
print('我是前置三元检测')
logging.info('我是前置三元检测')
elif self.routing_type == 'CNC加工':
if barcode == 'UP-ALL':
print("我是一键合并下发")
logging.info('我是一键合并下发')
self.up_merge_all()
else:
print('CNC加工')
# print(barcode)
# a = self.env['sf.tray'].search([('code', '=', barcode)])
# print(a)
# # workorder_obj = self.env['mrp.workorder'].search([('tray_code', '=', barcode)], limit=1)
# workorder_obj = self.env['mrp.workorder'].search([('tray_code', '=', barcode)])
# e = workorder_obj.id
# print(workorder_obj)
# action = {
# 'name': '工单',
# 'type': 'ir.actions.act_window',
# # 'view_type': 'form',
# 'view_mode': 'form',
# 'res_model': 'mrp.workorder',
# 'view_id': self.env.ref('mrp.mrp_production_workorder_form_view_inherit').id,
# # 'res_id': workorder_obj.id,
# 'res_id': 1023,
# 'target': 'current',
# # 'context': self.env.context,
# # 'flags': {'initial_mode': 'edit'},
# }
# return action
elif self.routing_type == '后置三元质量检测':
print('后置三元检测')
elif self.routing_type == '解除装夹':
print("我是解除装夹")
else:
pass
else:
self.pro_code_ok = workorder.pro_code_is_ok(barcode)
# def on_barcode_scanned(self, barcode):
# workorder = self.env['mrp.workorder'].browse(self.ids)
# if "*" not in barcode:
# if self.routing_type == '装夹':
# tray_code = self.env['sf.tray'].search([('code', '=', barcode)])
# self.tray_code = tray_code.code
# self.tray_id = workorder.gettray_auto(barcode)
# elif self.routing_type == '前置三元定位检测':
# print('我是前置三元检测')
# logging.info('我是前置三元检测')
# elif self.routing_type == 'CNC加工':
# if barcode == 'UP-ALL':
# print("我是一键合并下发")
# logging.info('我是一键合并下发')
# self.up_merge_all()
# else:
# print('CNC加工')
# # print(barcode)
# # a = self.env['sf.tray'].search([('code', '=', barcode)])
# # print(a)
# # # workorder_obj = self.env['mrp.workorder'].search([('tray_code', '=', barcode)], limit=1)
# # workorder_obj = self.env['mrp.workorder'].search([('tray_code', '=', barcode)])
# # e = workorder_obj.id
# # print(workorder_obj)
# # action = {
# # 'name': '工单',
# # 'type': 'ir.actions.act_window',
# # # 'view_type': 'form',
# # 'view_mode': 'form',
# # 'res_model': 'mrp.workorder',
# # 'view_id': self.env.ref('mrp.mrp_production_workorder_form_view_inherit').id,
# # # 'res_id': workorder_obj.id,
# # 'res_id': 1023,
# # 'target': 'current',
# # # 'context': self.env.context,
# # # 'flags': {'initial_mode': 'edit'},
# # }
# # return action
#
# elif self.routing_type == '后置三元质量检测':
# print('后置三元检测')
# elif self.routing_type == '解除装夹':
# print("我是解除装夹")
# else:
# pass
#
# else:
# self.pro_code_ok = workorder.pro_code_is_ok(barcode)