From b5339046b9aa83ee37664561888e71e3e3afa49a Mon Sep 17 00:00:00 2001 From: liaodanlong Date: Thu, 8 May 2025 16:42:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=A5=E8=89=BA=E5=A4=96=E5=8D=8F=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/models/mrp_workorder.py | 27 ++++++--- sf_manufacturing/models/stock.py | 76 +++++++++++++++++------- 2 files changed, 75 insertions(+), 28 deletions(-) diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index ad5230ad..35cd2234 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -85,6 +85,7 @@ class ResMrpWorkOrder(models.Model): item.pr_mp_count = len(pr_ids) else: item.pr_mp_count = 0 + @api.depends('state') def _compute_back_button_display(self): for record in self: @@ -484,6 +485,7 @@ class ResMrpWorkOrder(models.Model): 'view_mode': 'tree,form', }) return action + def action_view_surface_technics_purchase(self): self.ensure_one() # if self.routing_type == '表面工艺': @@ -512,7 +514,8 @@ class ResMrpWorkOrder(models.Model): return result def _get_surface_technics_purchase_ids(self): - domain = [('origin', 'like', '%' + self.production_id.name + '%'), ('purchase_type', '=', 'consignment'), ('state', '!=', 'cancel')] + domain = [('origin', 'like', '%' + self.production_id.name + '%'), ('purchase_type', '=', 'consignment'), + ('state', '!=', 'cancel')] # domain = [('origin', 'like', '%' + self.production_id.name + '%'), ('purchase_type', '=', 'consignment')] # domain = [('group_id', '=', self.production_id.procurement_group_id.id), ('purchase_type', '=', 'consignment')] purchase_orders = self.env['purchase.order'].search(domain, order='id desc') @@ -1248,6 +1251,7 @@ class ResMrpWorkOrder(models.Model): lambda line: line.lot_id.id == lot_id ) ) + def _process_compute_state(self): sorted_workorders = sorted(self, key=lambda x: x.sequence) for workorder in sorted_workorders: @@ -1288,7 +1292,10 @@ class ResMrpWorkOrder(models.Model): purchase_orders_id = self._get_surface_technics_purchase_ids() if purchase_orders_id.state == 'purchase': workorder.state = 'ready' - move_out = workorder.move_subcontract_workorder_ids[1] + picking_id = workorder.production_id.picking_ids.filtered( + lambda wk: wk.location_id.name == '制造前' and wk.location_dest_id.name == '外协加工区') + move_out = picking_id.move_ids + # move_out = workorder.move_subcontract_workorder_ids[1] for mo in move_out: if mo.state != 'done': mo.write({'state': 'assigned', 'production_id': False}) @@ -1327,7 +1334,10 @@ class ResMrpWorkOrder(models.Model): if purchase_orders_id: if purchase_orders_id.state == 'purchase': workorder.state = 'ready' - move_out = workorder.move_subcontract_workorder_ids[1] + picking_id = workorder.production_id.picking_ids.filtered( + lambda + wk: wk.location_id.name == '制造前' and wk.location_dest_id.name == '外协加工区') + move_out = picking_id.move_ids for mo in move_out: if mo.state != 'done': mo.write({'state': 'assigned', 'production_id': False}) @@ -1337,7 +1347,6 @@ class ResMrpWorkOrder(models.Model): else: workorder.state = 'waiting' - @api.depends('production_availability', 'blocked_by_workorder_ids', 'blocked_by_workorder_ids.state', 'production_id.tool_state', 'production_id.schedule_state', 'sequence', 'production_id.programming_state') @@ -1369,7 +1378,8 @@ class ResMrpWorkOrder(models.Model): # 判断是否有坯料的序列号信息 boolean = False if self.production_id.move_raw_ids: - if self.production_id.move_raw_ids[0].product_id.categ_type == '坯料' and self.production_id.move_raw_ids[0].product_id.tracking == 'serial': + if self.production_id.move_raw_ids[0].product_id.categ_type == '坯料' and \ + self.production_id.move_raw_ids[0].product_id.tracking == 'serial': if self.production_id.move_raw_ids[0].move_line_ids: if self.production_id.move_raw_ids[0].move_line_ids[0].lot_id.name: boolean = True @@ -1401,7 +1411,10 @@ class ResMrpWorkOrder(models.Model): # 表面工艺外协出库单 if self.routing_type == '表面工艺': if self.is_subcontract is True: - move_out = self.move_subcontract_workorder_ids[1] + picking_id = self.production_id.picking_ids.filtered( + lambda wk: wk.location_id.name == '制造前' and wk.location_dest_id.name == '外协加工区') + move_out = picking_id.move_ids + # move_out = self.move_subcontract_workorder_ids[1] # move_out = self.env['stock.move'].search( # [('location_id', '=', self.env['stock.location'].search( # [('barcode', 'ilike', 'WH-PREPRODUCTION')]).id), @@ -1820,7 +1833,7 @@ class ResMrpWorkOrder(models.Model): orderby=orderby, lazy=lazy ) - + model_id = fields.Char('模型ID', related='production_id.model_id') diff --git a/sf_manufacturing/models/stock.py b/sf_manufacturing/models/stock.py index 249c3d9b..1b60e68a 100644 --- a/sf_manufacturing/models/stock.py +++ b/sf_manufacturing/models/stock.py @@ -631,28 +631,62 @@ class StockPicking(models.Model): move.action_clear_lines_show_details() move.action_show_details() res = super().button_validate() - picking_type_in = self.env.ref('sf_manufacturing.outcontract_picking_in').id - if res is True and self.picking_type_id.id == picking_type_in: + lot_ids = None + product_ids = self.move_ids.mapped('product_id') + if not self.move_ids[0].product_id.single_manufacturing and self.move_ids[0].product_id.tracking == 'none': + lot_ids = self.move_ids.move_line_ids.mapped('lot_id') + production_ids = self.sale_order_id.mrp_production_ids if self.sale_order_id else self.env['mrp.production'] + if res and self.location_id.name == '外协收料区' and self.location_dest_id.name == '制造前': # 如果是最后一张外协入库单,则设置库存位置的预留数量 - move_in = self.move_ids - if move_in: - workorder = move_in.subcontract_workorder_id - workorders = workorder.production_id.workorder_ids - subcontract_workorders = workorders.filtered( - lambda wo: wo.is_subcontract == True and wo.state != 'cancel').sorted('sequence') - # if workorder == subcontract_workorders[-1]: - # self.env['stock.quant']._update_reserved_quantity( - # move_in.product_id, move_in.location_dest_id, move_in.product_uom_qty, - # lot_id=move_in.move_line_ids.lot_id, - # package_id=False, owner_id=False, strict=False - # ) - workorder.button_finish() - picking_type_out = self.env.ref('sf_manufacturing.outcontract_picking_out').id - if res and self.picking_type_id.id == picking_type_out: - move_out = self.move_ids - if move_out: - workorder = move_out.subcontract_workorder_id - workorder.button_start() + for production_id in production_ids: + if lot_ids: + lot_id = production_id.move_raw_ids.move_line_ids.lot_id + # picking_ids = production_id.picking_ids.filtered( + # lambda wk: wk.location_id.name == '外协收料区' and wk.location_dest_id.name == '制造前') + if lot_id in lot_ids: + workorder_id = production_id.workorder_ids.filtered( + lambda a: a.state == 'progress' and a.is_subcontract) + if not workorder_id: + continue + workorder_id.button_finish() + else: + workorder_id = production_id.workorder_ids.filtered(lambda a: a.state == 'progress' and a.is_subcontract) + if not workorder_id: + continue + workorder_id.button_finish() + # lot_id = workorder.production_id.move_raw_ids.move_line_ids.lot_id + # picking_ids = workorder.production_id.picking_ids.filtered( + # lambda wk: wk.location_id.name == '外协收料区' and wk.location_dest_id.name == '制造前') + + # if move_in: + # workorder = move_in.subcontract_workorder_id + # workorders = workorder.production_id.workorder_ids + # subcontract_workorders = workorders.filtered( + # lambda wo: wo.is_subcontract == True and wo.state != 'cancel').sorted('sequence') + # # if workorder == subcontract_workorders[-1]: + # # self.env['stock.quant']._update_reserved_quantity( + # # move_in.product_id, move_in.location_dest_id, move_in.product_uom_qty, + # # lot_id=move_in.move_line_ids.lot_id, + # # package_id=False, owner_id=False, strict=False + # # ) + # workorder.button_finish() + if res and self.location_id.name == '制造前' and self.location_dest_id.name == '外协加工区': + for production_id in production_ids: + if lot_ids: + lot_id = production_id.move_raw_ids.move_line_ids.lot_id + # picking_ids = production_id.picking_ids.filtered( + # lambda wk: wk.location_id.name == '外协收料区' and wk.location_dest_id.name == '制造前') + if lot_id in lot_ids: + workorder_id = production_id.workorder_ids.filtered( + lambda a: a.state == 'progress' and a.is_subcontract) + if not workorder_id: + continue + workorder_id.button_finish() + else: + workorder_id = production_id.workorder_ids.filtered(lambda a: a.state == 'ready' and a.is_subcontract) + if not workorder_id: + continue + workorder_id.button_start() if self.location_id.name == '成品存货区' and self.location_dest_id.name == '客户': sale_id = self.env['sale.order'].sudo().search( [('name', '=', self.origin)])