From 5aa848de535744b7e2d67a6eff8c71fd21c15aa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=B0=A7?= Date: Wed, 7 May 2025 11:01:01 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E5=9D=AF=E6=96=99=E5=BA=8F=E5=88=97=E5=8F=B7=E7=9A=84=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/models/mrp_workorder.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index 070ff404..2c32ed9c 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -1357,11 +1357,10 @@ 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 == '坯料': + 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: - if self.production_id.move_raw_ids[0].move_line_ids[0].lot_id.name: - boolean = True + if self.production_id.move_raw_ids[0].move_line_ids[0].lot_id.name: + boolean = True else: boolean = True if not boolean: From fffbfc21c21233cac2960d39c0747b827abde84c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=B0=A7?= Date: Wed, 7 May 2025 13:02:13 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E8=A1=A8=E9=9D=A2=E5=B7=A5=E8=89=BA?= =?UTF-8?q?=E5=A4=96=E5=8D=8F=E5=B7=A5=E5=8D=95=E6=B5=81=E7=A8=8B=E6=95=B0?= =?UTF-8?q?=E9=87=8F=E6=8C=89=E7=85=A7=E5=88=B6=E9=80=A0=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E7=9A=84product=5Fuom=5Fqty=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/models/stock.py | 9 +++++---- sf_sale/models/sale_order.py | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/sf_manufacturing/models/stock.py b/sf_manufacturing/models/stock.py index 3a1b3cd9..249c3d9b 100644 --- a/sf_manufacturing/models/stock.py +++ b/sf_manufacturing/models/stock.py @@ -675,6 +675,7 @@ class StockPicking(models.Model): # 创建 外协出库入单 def create_outcontract_picking(self, workorders, item, sorted_workorders): + production = workorders[0].production_id for workorder in workorders: if workorder.move_subcontract_workorder_ids: workorder.move_subcontract_workorder_ids.write({'state': 'cancel'}) @@ -706,7 +707,7 @@ class StockPicking(models.Model): }) moves_in = self.env['stock.move'].sudo().with_context(context).create( self.env['stock.move']._get_stock_move_values_Res(item, outcontract_picking_type_in, - procurement_group_id.id, move_dest_id)) + procurement_group_id.id, move_dest_id, production.product_uom_qty)) picking_in = self.create( moves_in._get_new_picking_values_Res(item, workorder, 'WH/OCIN/')) # pick_ids.append(picking_in.id) @@ -716,7 +717,7 @@ class StockPicking(models.Model): # self.env.context.get('default_production_id') moves_out = self.env['stock.move'].sudo().with_context(context).create( self.env['stock.move']._get_stock_move_values_Res(item, outcontract_picking_type_out, - procurement_group_id.id, moves_in.id)) + procurement_group_id.id, moves_in.id, production.product_uom_qty)) workorder.write({'move_subcontract_workorder_ids': [(6, 0, [moves_in.id, moves_out.id])]}) picking_out = self.create( moves_out._get_new_picking_values_Res(item, workorder, 'WH/OCOUT/')) @@ -848,7 +849,7 @@ class ReStockMove(models.Model): traceback_error = traceback.format_exc() logging.error("零件图号 零件名称获取失败:%s" % traceback_error) - def _get_stock_move_values_Res(self, item, picking_type_id, group_id, move_dest_ids=False): + def _get_stock_move_values_Res(self, item, picking_type_id, group_id, move_dest_ids=False, product_uom_qty=1.0): route_id = self.env.ref('sf_manufacturing.route_surface_technology_outsourcing').id stock_rule = self.env['stock.rule'].sudo().search( [('route_id', '=', route_id), ('picking_type_id', '=', picking_type_id)]) @@ -857,7 +858,7 @@ class ReStockMove(models.Model): 'company_id': item.company_id.id, 'product_id': item.bom_id.bom_line_ids.product_id.id, 'product_uom': item.bom_id.bom_line_ids.product_uom_id.id, - 'product_uom_qty': 1.0, + 'product_uom_qty': product_uom_qty, 'location_id': stock_rule.location_src_id.id, 'location_dest_id': stock_rule.location_dest_id.id, 'origin': item.name, diff --git a/sf_sale/models/sale_order.py b/sf_sale/models/sale_order.py index ced49414..dea7a57a 100644 --- a/sf_sale/models/sale_order.py +++ b/sf_sale/models/sale_order.py @@ -419,7 +419,7 @@ class RePurchaseOrder(models.Model): ('detailed_type', '=', 'service')]) server_product_process.append((0, 0, { 'product_id': server_template.product_variant_id.id, - 'product_qty': 1, + 'product_qty': production.product_uom_qty, 'product_uom': server_template.uom_id.id, 'related_product': production.product_id.id, 'manual_part_number': pp.part_number, From c24bba313745f6d202743646b378a4a047449b09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=B0=A7?= Date: Wed, 7 May 2025 16:34:45 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=87=87=E8=B4=AD?= =?UTF-8?q?=E7=94=B3=E8=AF=B7=E5=AF=B9=E4=BA=8E=E5=8D=95=E4=BB=B6=E5=88=B6?= =?UTF-8?q?=E9=80=A0=E9=9D=9E=E9=A6=96=E4=B8=AA=E5=88=B6=E9=80=A0=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E7=9A=84=E6=98=BE=E7=A4=BA=EF=BC=8C=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E9=87=87=E8=B4=AD=E7=94=B3=E8=AF=B7=E5=AF=B9=E4=BA=8E=E5=90=8C?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E8=A1=A5=E8=B4=A7=E7=BB=84=E5=90=8C=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E4=BA=A7=E5=93=81=E7=9A=84=E5=90=88=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../models/mrp_production.py | 20 ++++++++--- jikimo_purchase_request/models/stock_rule.py | 35 ++++++++++++++++++- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/jikimo_purchase_request/models/mrp_production.py b/jikimo_purchase_request/models/mrp_production.py index dd9d4aa9..02bff9fb 100644 --- a/jikimo_purchase_request/models/mrp_production.py +++ b/jikimo_purchase_request/models/mrp_production.py @@ -9,12 +9,16 @@ class MrpProduction(models.Model): @api.depends('state') def _compute_pr_mp_count(self): for item in self: - pr_ids = self.env['purchase.request'].sudo().search([('origin', 'like', item.name)]) - # pr_ids = self.env['purchase.request'].sudo().search([('origin', 'like', item.name), ('is_subcontract', '!=', 'True')]) - if pr_ids: + if item.product_id.product_tmpl_id.single_manufacturing == True and not item.is_remanufacture: + first_order = self.env['mrp.production'].search( + [('origin', '=', item.origin), ('product_id', '=', item.product_id.id)], limit=1, order='id asc') + pr_ids = self.env['purchase.request'].sudo().search([('origin', 'like', first_order.name)]) item.pr_mp_count = len(pr_ids) else: - item.pr_mp_count = 0 + pr_ids = self.env['purchase.request'].sudo().search([('origin', 'like', item.name)]) + item.pr_mp_count = len(pr_ids) + + # pr_ids = self.env['purchase.request'].sudo().search([('origin', 'like', item.name), ('is_subcontract', '!=', 'True')]) def action_view_pr_mp(self): """ @@ -22,7 +26,13 @@ class MrpProduction(models.Model): """ self.ensure_one() # pr_ids = self.env['purchase.request'].sudo().search([('origin', 'like', self.name),('is_subcontract', '!=', True)]) - pr_ids = self.env['purchase.request'].sudo().search([('origin', 'like', self.name)]) + if self.product_id.product_tmpl_id.single_manufacturing == True and not self.is_remanufacture: + first_order = self.env['mrp.production'].search( + [('origin', '=', self.origin), ('product_id', '=', self.product_id.id)], limit=1, order='id asc') + pr_ids = self.env['purchase.request'].sudo().search([('origin', 'like', first_order.name)]) + else: + pr_ids = self.env['purchase.request'].sudo().search([('origin', 'like', self.name)]) + action = { 'res_model': 'purchase.request', 'type': 'ir.actions.act_window', diff --git a/jikimo_purchase_request/models/stock_rule.py b/jikimo_purchase_request/models/stock_rule.py index 08f32b2d..81f4f8ee 100644 --- a/jikimo_purchase_request/models/stock_rule.py +++ b/jikimo_purchase_request/models/stock_rule.py @@ -1,4 +1,5 @@ from odoo import api, fields, models +from collections import defaultdict class StockRule(models.Model): @@ -44,7 +45,39 @@ class StockRule(models.Model): purchase_request_line_model.create(request_line_data) def _run_buy(self, procurements): - res = super(StockRule, self)._run_buy(procurements) + # 如果补货组相同,并且产品相同,则合并 + procurements_dict = defaultdict() + for procurement, rule in procurements: + if (procurement.product_id, procurement.values['group_id'], rule) not in procurements_dict: + procurements_dict[(procurement.product_id, procurement.values['group_id'], rule)] = { + 'product_id': procurement.product_id, + 'product_qty': procurement.product_qty, + 'product_uom': procurement.product_uom, + 'location_id': procurement.location_id, + 'name': procurement.name, + 'origin': procurement.origin, + 'company_id': procurement.company_id, + 'values': procurement.values, + 'rule': rule + } + else: + procurements_dict[(procurement.product_id, procurement.values['group_id'], rule)]['product_qty'] += procurement.product_qty + new_procurements = [] + for k, p in procurements_dict.items(): + new_procurements.append(( + self.env['procurement.group'].Procurement( + product_id=p['product_id'], + product_qty=p['product_qty'], + product_uom=p['product_uom'], + location_id=p['location_id'], + name=p['name'], + origin=p['origin'], + company_id=p['company_id'], + values=p['values'] + ), p['rule']) + ) + + res = super(StockRule, self)._run_buy(new_procurements) # 判断是否根据规则生成新的采购申请单据,如果生成则修改状态为 approved origins = list(set([procurement[0].origin for procurement in procurements])) for origin in origins: