From 5f55c954d1232c19eacf00ed2d213ebca7c33b59 Mon Sep 17 00:00:00 2001 From: guanhuan Date: Mon, 16 Jun 2025 11:42:21 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E7=A1=AE=E8=AE=A4=E5=B7=A5=E8=89=BA?= =?UTF-8?q?=E8=B7=AF=E7=BA=BF=E6=96=B0=E5=A2=9E=E8=A1=A8=E9=9D=A2=E5=B7=A5?= =?UTF-8?q?=E8=89=BA=E5=8F=82=E6=95=B0=E9=9C=80=E8=A6=81=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E5=88=B0=E4=BA=A7=E5=93=81=E7=9A=84=E5=8A=A0=E5=B7=A5=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/models/mrp_production.py | 7 ++++ .../models/sf_technology_design.py | 40 +++++++++++-------- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py index 74460d4c..f3de0fb2 100644 --- a/sf_manufacturing/models/mrp_production.py +++ b/sf_manufacturing/models/mrp_production.py @@ -333,6 +333,13 @@ class MrpProduction(models.Model): technology_design_ids = fields.One2many('sf.technology.design', 'production_id', string='工艺设计') is_adjust = fields.Boolean('是否退回调整', default=False) + def write(self, vals): + res = super(MrpProduction, self).write(vals) + if 'technology_design_ids' in vals: + process_parameters_id = self.technology_design_ids.mapped('process_parameters_id') + self.product_id.model_process_parameters_ids = process_parameters_id.ids + return res + @api.depends('remanufacture_production_id') def _compute_remanufacture_production_ids(self): for production in self: diff --git a/sf_manufacturing/models/sf_technology_design.py b/sf_manufacturing/models/sf_technology_design.py index 826c147d..7b79d485 100644 --- a/sf_manufacturing/models/sf_technology_design.py +++ b/sf_manufacturing/models/sf_technology_design.py @@ -23,7 +23,6 @@ class sf_technology_design(models.Model): # def _compute_group_uniq_id(self): # for record in self: - def json_technology_design_str(self, k, route, i, process_parameter): workorders_values_str = [0, '', { 'route_id': route.id if route.routing_type in ['表面工艺'] else route.route_workcenter_id.id, @@ -36,11 +35,16 @@ class sf_technology_design(models.Model): return workorders_values_str def write(self, vals): - return super(sf_technology_design, self).write(vals) + res = super(sf_technology_design, self).write(vals) + if 'active' in vals: + if self.production_id: + process_parameters_id = self.production_id.technology_design_ids.mapped('process_parameters_id') + self.production_id.product_id.model_process_parameters_ids = process_parameters_id.ids + return res + def unlink_technology_design(self): self.active = False - @api.model_create_multi def create(self, vals_list): for vals in vals_list: @@ -48,10 +52,12 @@ class sf_technology_design(models.Model): raise ValidationError(_("工序不能为空")) result = super(sf_technology_design, self).create(vals_list) for res in result: - record = self.search([('production_id', '=', res.production_id.id), ('active', 'in', [True, False])], order='group_uniq_id desc', limit=1) - res.group_uniq_id=record.group_uniq_id + 1 + record = self.search([('production_id', '=', res.production_id.id), ('active', 'in', [True, False])], + order='group_uniq_id desc', limit=1) + res.group_uniq_id = record.group_uniq_id + 1 return result - def get_duplicates_with_inactive(self,technology_designs): + + def get_duplicates_with_inactive(self, technology_designs): # 统计每个 'sequence' 出现的次数 sequence_count = Counter(technology_design.sequence for technology_design in technology_designs) @@ -62,6 +68,7 @@ class sf_technology_design(models.Model): ] return result + # def rearrange_numbering(self,self_technology_designs): # inactive_designs = self.get_duplicates_with_inactive(self_technology_designs) # if inactive_designs: @@ -75,7 +82,7 @@ class sf_technology_design(models.Model): def get_technology_design(self): return { - 'sequence':self.sequence, + 'sequence': self.sequence, 'route_id': self.route_id.id, 'process_parameters_id': self.process_parameters_id.id, 'panel': self.panel, @@ -83,17 +90,19 @@ class sf_technology_design(models.Model): 'time_cycle_manual': self.time_cycle_manual, 'is_auto': self.is_auto, 'active': self.active, - 'group_uniq_id':self.group_uniq_id, + 'group_uniq_id': self.group_uniq_id, } - def sync_technology_designs(self,production_technology_designs, self_technology_designs): + + def sync_technology_designs(self, production_technology_designs, self_technology_designs): production_id = production_technology_designs[0].production_id.id - self_technology_design_dict = {item.group_uniq_id:item for item in self_technology_designs} - production_technology_designs_dict = {item.group_uniq_id:item for item in production_technology_designs} + self_technology_design_dict = {item.group_uniq_id: item for item in self_technology_designs} + production_technology_designs_dict = {item.group_uniq_id: item for item in production_technology_designs} for technology_design in production_technology_designs: if not self_technology_design_dict.get(technology_design.group_uniq_id): technology_design.write({'production_id': False}) else: - technology_design.write(self_technology_design_dict.get(technology_design.group_uniq_id).get_technology_design()) + technology_design.write( + self_technology_design_dict.get(technology_design.group_uniq_id).get_technology_design()) for technology_design in self_technology_designs: if not production_technology_designs_dict.get(technology_design.group_uniq_id): technology_design = technology_design.get_technology_design() @@ -101,9 +110,8 @@ class sf_technology_design(models.Model): technology_design.pop('group_uniq_id') self.env['sf.technology.design'].create(technology_design) - - - def unified_procedure_multiple_work_orders(self,self_technology_designs,production_item): + def unified_procedure_multiple_work_orders(self, self_technology_designs, production_item): technology_designs = self.env['sf.technology.design'].sudo().search( [('production_id', '=', production_item.id), ('active', 'in', [True, False])]) - self.sync_technology_designs(self_technology_designs=self_technology_designs,production_technology_designs=technology_designs) \ No newline at end of file + self.sync_technology_designs(self_technology_designs=self_technology_designs, + production_technology_designs=technology_designs) From fa03b562a21e2c364c012e8aeb73e39495a0563d Mon Sep 17 00:00:00 2001 From: guanhuan Date: Mon, 16 Jun 2025 11:52:22 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E7=A1=AE=E8=AE=A4=E5=B7=A5=E8=89=BA?= =?UTF-8?q?=E8=B7=AF=E7=BA=BF=E6=96=B0=E5=A2=9E=E8=A1=A8=E9=9D=A2=E5=B7=A5?= =?UTF-8?q?=E8=89=BA=E5=8F=82=E6=95=B0=E9=9C=80=E8=A6=81=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E5=88=B0=E4=BA=A7=E5=93=81=E7=9A=84=E5=8A=A0=E5=B7=A5=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/models/sf_technology_design.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sf_manufacturing/models/sf_technology_design.py b/sf_manufacturing/models/sf_technology_design.py index 7b79d485..c3006a94 100644 --- a/sf_manufacturing/models/sf_technology_design.py +++ b/sf_manufacturing/models/sf_technology_design.py @@ -39,7 +39,10 @@ class sf_technology_design(models.Model): if 'active' in vals: if self.production_id: process_parameters_id = self.production_id.technology_design_ids.mapped('process_parameters_id') - self.production_id.product_id.model_process_parameters_ids = process_parameters_id.ids + if process_parameters_id.ids: + self.production_id.product_id.model_process_parameters_ids = process_parameters_id.ids + else: + self.production_id.product_id.model_process_parameters_ids = None return res def unlink_technology_design(self): From 2febc369bbedac8786b8b87d72362d0ae7dcaa84 Mon Sep 17 00:00:00 2001 From: guanhuan Date: Mon, 16 Jun 2025 13:44:55 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E7=A1=AE=E8=AE=A4=E5=B7=A5=E8=89=BA?= =?UTF-8?q?=E8=B7=AF=E7=BA=BF=E6=96=B0=E5=A2=9E=E8=A1=A8=E9=9D=A2=E5=B7=A5?= =?UTF-8?q?=E8=89=BA=E5=8F=82=E6=95=B0=E9=9C=80=E8=A6=81=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E5=88=B0=E4=BA=A7=E5=93=81=E7=9A=84=E5=8A=A0=E5=B7=A5=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/models/mrp_production.py | 7 ------- sf_manufacturing/models/sf_technology_design.py | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py index f3de0fb2..74460d4c 100644 --- a/sf_manufacturing/models/mrp_production.py +++ b/sf_manufacturing/models/mrp_production.py @@ -333,13 +333,6 @@ class MrpProduction(models.Model): technology_design_ids = fields.One2many('sf.technology.design', 'production_id', string='工艺设计') is_adjust = fields.Boolean('是否退回调整', default=False) - def write(self, vals): - res = super(MrpProduction, self).write(vals) - if 'technology_design_ids' in vals: - process_parameters_id = self.technology_design_ids.mapped('process_parameters_id') - self.product_id.model_process_parameters_ids = process_parameters_id.ids - return res - @api.depends('remanufacture_production_id') def _compute_remanufacture_production_ids(self): for production in self: diff --git a/sf_manufacturing/models/sf_technology_design.py b/sf_manufacturing/models/sf_technology_design.py index c3006a94..463ad206 100644 --- a/sf_manufacturing/models/sf_technology_design.py +++ b/sf_manufacturing/models/sf_technology_design.py @@ -36,7 +36,7 @@ class sf_technology_design(models.Model): def write(self, vals): res = super(sf_technology_design, self).write(vals) - if 'active' in vals: + if 'group_uniq_id' in vals or 'process_parameters_id' in vals or 'active' in vals: if self.production_id: process_parameters_id = self.production_id.technology_design_ids.mapped('process_parameters_id') if process_parameters_id.ids: From 9123aeaee8b03679adff1f10114fe6dc9408bf9a Mon Sep 17 00:00:00 2001 From: guanhuan Date: Mon, 16 Jun 2025 14:35:28 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BA=BA=E5=B7=A5=E7=BA=BF=E4=B8=8B?= =?UTF-8?q?=E5=8A=A0=E5=B7=A5=E6=9C=80=E5=90=8E=E4=B8=80=E4=B8=AA=E5=B7=A5?= =?UTF-8?q?=E5=8D=95=E5=AE=8C=E5=B7=A5=E5=90=8E=E6=9C=AA=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E5=AE=8C=E5=B7=A5=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../models/sf_production_demand_plan.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/sf_demand_plan/models/sf_production_demand_plan.py b/sf_demand_plan/models/sf_production_demand_plan.py index d484fb8e..ef11adcc 100644 --- a/sf_demand_plan/models/sf_production_demand_plan.py +++ b/sf_demand_plan/models/sf_production_demand_plan.py @@ -259,7 +259,9 @@ class SfProductionDemandPlan(models.Model): manufacturing_orders = record.sale_order_id.mrp_production_ids.filtered( lambda mo: mo.product_id == record.product_id) finished_orders = manufacturing_orders.filtered(lambda mo: mo.state == 'done') - if len(finished_orders) >= record.product_uom_qty: + sum_product_qty = sum(finished_orders.mapped('product_qty')) + if finished_orders and float_compare(sum_product_qty, record.product_uom_qty, + precision_rounding=record.product_id.uom_id.rounding) >= 0: end_dates = [ workorder.date_finished for mo in finished_orders for workorder in mo.workorder_ids if workorder.date_finished @@ -361,7 +363,8 @@ class SfProductionDemandPlan(models.Model): ) for order in purchase_orders ) - if total_purchase_quantity < record.product_uom_qty: + if float_compare(total_purchase_quantity, record.product_uom_qty, + precision_rounding=record.product_id.uom_id.rounding) == -1: pr_ids = self.env['purchase.request'].sudo().search( [('line_ids.product_id', 'in', raw_materials.ids), ('state', '!=', 'done')]) outsourcing_purchase_request.extend(pr_ids.ids) @@ -378,7 +381,9 @@ class SfProductionDemandPlan(models.Model): ) for order in purchase_orders ) - if total_purchase_quantity < record.product_uom_qty: + + if float_compare(total_purchase_quantity, record.product_uom_qty, + precision_rounding=record.product_id.uom_id.rounding) == -1: pr_ids = self.env['purchase.request'].sudo().search( [('origin', 'like', record.sale_order_id.name), ('state', '!=', 'done')]) outsourcing_purchase_request.extend(pr_ids.ids) @@ -400,7 +405,9 @@ class SfProductionDemandPlan(models.Model): ) for order in product_purchase_orders ) - if total_outsourcing_purchase_quantity / total_product_qty < record.product_uom_qty: + quantity = total_outsourcing_purchase_quantity / total_product_qty + if float_compare(quantity, record.product_uom_qty, + precision_rounding=record.product_id.uom_id.rounding) == -1: purchase_request = self.env['purchase.request'].sudo().search( [('line_ids.product_id', 'in', bom_product_ids.ids), ('line_ids.purchase_state', 'not in', ('purchase', 'done')), ('state', '!=', 'done')])