From b6acbb835783b1dd12983b8518f24bdfc2060256 Mon Sep 17 00:00:00 2001 From: yuxianghui <3437689193@qq.com> Date: Wed, 5 Jun 2024 10:23:13 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E5=8A=9F=E8=83=BD=E5=88=80=E5=85=B7?= =?UTF-8?q?=E6=8B=86=E8=A7=A3=E5=8D=95=E6=96=B0=E5=A2=9E=E6=8B=86=E8=A7=A3?= =?UTF-8?q?=E5=8D=95=E5=8F=B7=EF=BC=8C=E4=BC=98=E5=8C=96=E6=8B=86=E8=A7=A3?= =?UTF-8?q?=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_tool_management/models/base.py | 42 ++++++++++++++------ sf_tool_management/views/tool_base_views.xml | 7 +++- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/sf_tool_management/models/base.py b/sf_tool_management/models/base.py index 87dcfb28..1d482781 100644 --- a/sf_tool_management/models/base.py +++ b/sf_tool_management/models/base.py @@ -679,6 +679,22 @@ class FunctionalToolDismantle(models.Model): raise ValidationError('该功能刀具因为%s拆解,无需录入库位' % self.dismantle_cause) name = fields.Char('名称', related='functional_tool_id.name') + code = fields.Char('拆解单号', default=lambda self: self._get_code(), readonly=True) + + def _get_code(self): + """ + 自动生成拆解单编码 + """ + new_time = str(fields.Date.today()) + datetime = new_time[2:4] + new_time[5:7] + new_time[-2:] + functional_tool_dismantle = self.env['sf.functional.tool.dismantle'].sudo().search( + [('code', 'ilike', datetime)], limit=1, order="id desc") + if not functional_tool_dismantle: + num = "%03d" % 1 + else: + m = int(functional_tool_dismantle.code[-3:]) + 1 + num = "%03d" % m + return 'GNDJ-CJD-%s-%s' % (datetime, num) functional_tool_id = fields.Many2one('sf.functional.cutting.tool.entity', '功能刀具', required=True, domain=[('functional_tool_status', '!=', '已拆除')]) @@ -824,7 +840,7 @@ class FunctionalToolDismantle(models.Model): def confirmation_disassembly(self): logging.info('%s刀具确认开始拆解' % self.dismantle_cause) - t_id = self.id + code = self.code if self.functional_tool_id.functional_tool_status == '已拆除': raise ValidationError('Rfid为【%s】的功能刀具已经拆解,请勿重复操作!' % self.functional_tool_id.rfid_dismantle) location = self.env['stock.location'].search([('name', '=', '刀具组装位置')]) @@ -849,19 +865,19 @@ class FunctionalToolDismantle(models.Model): # 除刀柄外物料报废 入库到Scrap if self.integral_product_id: self.integral_product_id.dismantle_stock_moves(False, self.integral_lot_id, location, - location_dest_scrap, t_id) + location_dest_scrap, code) elif self.blade_product_id: self.blade_product_id.dismantle_stock_moves(False, self.blade_lot_id, location, location_dest_scrap, - t_id) + code) if self.bar_product_id: self.bar_product_id.dismantle_stock_moves(False, self.bar_lot_id, location, location_dest_scrap, - t_id) + code) elif self.pad_product_id: self.pad_product_id.dismantle_stock_moves(False, self.pad_lot_id, location, location_dest_scrap, - t_id) + code) if self.chuck_product_id: self.chuck_product_id.dismantle_stock_moves(False, self.chuck_lot_id, location, location_dest_scrap, - t_id) + code) # ===========功能刀具[磨削]拆解============== # elif self.dismantle_cause in ['刀具需磨削']: # location_dest = self.env['stock.location'].search([('name', '=', '磨削房')]) @@ -881,19 +897,19 @@ class FunctionalToolDismantle(models.Model): # 除刀柄外物料拆解 入库到具体货位 if self.integral_freight_id: self.integral_product_id.dismantle_stock_moves(self.integral_freight_id, self.integral_lot_id, location, - location_dest, t_id) + location_dest, code) elif self.blade_freight_id: self.blade_product_id.dismantle_stock_moves(self.blade_freight_id, self.blade_lot_id, location, - location_dest, t_id) + location_dest, code) if self.bar_freight_id: self.bar_product_id.dismantle_stock_moves(self.bar_freight_id, self.bar_lot_id, location, - location_dest, t_id) + location_dest, code) elif self.pad_freight_id: self.pad_product_id.dismantle_stock_moves(self.pad_freight_id, self.pad_lot_id, location, - location_dest, t_id) + location_dest, code) if self.chuck_freight_id: self.chuck_product_id.dismantle_stock_moves(self.chuck_freight_id, self.chuck_lot_id, location, - location_dest, t_id) + location_dest, code) # ===============删除功能刀具的Rfid字段的值, 赋值给Rfid(已拆解)字段===== self.functional_tool_id.write({ 'rfid_dismantle': self.functional_tool_id.rfid, @@ -914,10 +930,10 @@ class FunctionalToolDismantle(models.Model): class ProductProduct(models.Model): _inherit = 'product.product' - def dismantle_stock_moves(self, shelf_location_id, lot_id, location_id, location_dest_id, t_id): + def dismantle_stock_moves(self, shelf_location_id, lot_id, location_id, location_dest_id, code): # 创建功能刀具拆解单产品库存移动记录 stock_move_id = self.env['stock.move'].sudo().create({ - 'name': 'DJCJ/%s' % t_id, + 'name': code, 'product_id': self.id, 'location_id': location_id.id, 'location_dest_id': location_dest_id.id, diff --git a/sf_tool_management/views/tool_base_views.xml b/sf_tool_management/views/tool_base_views.xml index 7e74b8fc..54f9d7f9 100644 --- a/sf_tool_management/views/tool_base_views.xml +++ b/sf_tool_management/views/tool_base_views.xml @@ -778,6 +778,7 @@ sf.functional.tool.dismantle + @@ -805,13 +806,14 @@

- +

+ @@ -946,6 +948,7 @@ +