From 3742a3b16342e48a07bc63b1249683221e178e9a Mon Sep 17 00:00:00 2001 From: "qihao.gong@jikimo.com" Date: Mon, 8 Jan 2024 17:51:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=87=AA=E5=8A=A8=E5=AE=8C?= =?UTF-8?q?=E6=88=90=E5=88=B6=E9=80=A0=E8=AE=A2=E5=8D=95=E5=BE=97=E6=96=B9?= =?UTF-8?q?=E6=B3=95=EF=BC=8C=E5=AE=8C=E5=B7=A5=E4=BA=A7=E5=93=81=E6=8D=A1?= =?UTF-8?q?=E5=8F=96=E9=9C=80=E5=8F=98=E6=88=90=E5=B0=B1=E7=BB=AA=E7=8A=B6?= =?UTF-8?q?=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_base/models/tool_other_features.py | 1 + sf_manufacturing/models/mrp_production.py | 87 +++++++++++++++++++++++ sf_manufacturing/models/mrp_workorder.py | 3 +- 3 files changed, 90 insertions(+), 1 deletion(-) diff --git a/sf_base/models/tool_other_features.py b/sf_base/models/tool_other_features.py index 154bf275..ec3ad238 100644 --- a/sf_base/models/tool_other_features.py +++ b/sf_base/models/tool_other_features.py @@ -162,6 +162,7 @@ class FeedPerTooth(models.Model): _order = 'blade_diameter,cutting_width_depth_id,materials_type_id' name = fields.Char('名称') + cutting_speed = fields.Char('切削速度', required=True) product_template_id = fields.Many2one('product.template') standard_library_id = fields.Many2one('sf.cutting_tool.standard.library', string='标准库') blade_diameter = fields.Integer('刃部直径(mm)', readonly=True) diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py index 809462a9..dd474527 100644 --- a/sf_manufacturing/models/mrp_production.py +++ b/sf_manufacturing/models/mrp_production.py @@ -426,3 +426,90 @@ class MrpProduction(models.Model): self._create_workorder3() self._reset_work_order_sequence() return True + + #修改标记已完成方法 + def button_mark_done1(self): + self._button_mark_done_sanity_checks() + + if not self.env.context.get('button_mark_done_production_ids'): + self = self.with_context(button_mark_done_production_ids=self.ids) + res = self._pre_button_mark_done() + if res is not True: + return res + + if self.env.context.get('mo_ids_to_backorder'): + productions_to_backorder = self.browse(self.env.context['mo_ids_to_backorder']) + productions_not_to_backorder = self - productions_to_backorder + else: + productions_not_to_backorder = self + productions_to_backorder = self.env['mrp.production'] + + + backorders = productions_to_backorder and productions_to_backorder._split_productions() + backorders = backorders - productions_to_backorder + + productions_not_to_backorder._post_inventory(cancel_backorder=True) + productions_to_backorder._post_inventory(cancel_backorder=True) + + # if completed products make other confirmed/partially_available moves available, assign them + done_move_finished_ids = (productions_to_backorder.move_finished_ids | productions_not_to_backorder.move_finished_ids).filtered(lambda m: m.state == 'done') + done_move_finished_ids._trigger_assign() + + # Moves without quantity done are not posted => set them as done instead of canceling. In + # case the user edits the MO later on and sets some consumed quantity on those, we do not + # want the move lines to be canceled. + (productions_not_to_backorder.move_raw_ids | productions_not_to_backorder.move_finished_ids).filtered(lambda x: x.state not in ('done', 'cancel')).write({ + 'state': 'done', + 'product_uom_qty': 0.0, + }) + + for production in self: + production.write({ + 'date_finished': fields.Datetime.now(), + 'product_qty': production.qty_produced, + 'priority': '0', + 'is_locked': True, + 'state': 'done', + }) + + for workorder in self.workorder_ids.filtered(lambda w: w.state not in ('done', 'cancel')): + workorder.duration_expected = workorder._get_duration_expected() + + if not backorders: + if self.env.context.get('from_workorder'): + return { + 'type': 'ir.actions.act_window', + 'res_model': 'mrp.production', + 'views': [[self.env.ref('mrp.mrp_production_form_view').id, 'form']], + 'res_id': self.id, + 'target': 'main', + } + if self.user_has_groups('mrp.group_mrp_reception_report') and self.picking_type_id.auto_show_reception_report: + lines = self.move_finished_ids.filtered(lambda m: m.product_id.type == 'product' and m.state != 'cancel' and m.quantity_done and not m.move_dest_ids) + if lines: + if any(mo.show_allocation for mo in self): + action = self.action_view_reception_report() + return action + return True + context = self.env.context.copy() + context = {k: v for k, v in context.items() if not k.startswith('default_')} + for k, v in context.items(): + if k.startswith('skip_'): + context[k] = False + action = { + 'res_model': 'mrp.production', + 'type': 'ir.actions.act_window', + 'context': dict(context, mo_ids_to_backorder=None, button_mark_done_production_ids=None) + } + if len(backorders) == 1: + action.update({ + 'view_mode': 'form', + 'res_id': backorders[0].id, + }) + else: + action.update({ + 'name': _("Backorder MO"), + 'domain': [('id', 'in', backorders.ids)], + 'view_mode': 'tree,form', + }) + return action \ No newline at end of file diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index 53307af7..7ecec223 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -581,7 +581,8 @@ class ResMrpWorkOrder(models.Model): if is_production_id == True and self.name == '解除装夹': for move_raw_id in self.production_id.move_raw_ids: move_raw_id.quantity_done = move_raw_id.product_uom_qty - self.production_id.state = 'done' + self.production_id.button_mark_done1() + # self.production_id.state = 'done'