From 8e3136b36596e13fb028f22879c264a057aae4e1 Mon Sep 17 00:00:00 2001 From: Cybrosys Technologies Date: Sat, 5 Jul 2025 16:47:00 +0530 Subject: [PATCH] July 05: [FIX] Bug Fixed 'manufacturing_timesheet' --- manufacturing_timesheet/__manifest__.py | 2 +- manufacturing_timesheet/doc/RELEASE_NOTES.md | 7 +- .../models/mrp_workorder.py | 68 +++++++++++-------- 3 files changed, 45 insertions(+), 32 deletions(-) diff --git a/manufacturing_timesheet/__manifest__.py b/manufacturing_timesheet/__manifest__.py index 1f3f7729c..d4d4bd63e 100644 --- a/manufacturing_timesheet/__manifest__.py +++ b/manufacturing_timesheet/__manifest__.py @@ -21,7 +21,7 @@ ################################################################################ { 'name': 'Manufacturing (MRP) Timesheet', - 'version': '17.0.1.0.0', + 'version': '17.0.1.0.1', 'category': 'Manufacturing,Project', 'summary': 'Timesheet for manufacturing.', 'description': """ This module will help you to create timesheet for diff --git a/manufacturing_timesheet/doc/RELEASE_NOTES.md b/manufacturing_timesheet/doc/RELEASE_NOTES.md index edd0fab48..655f3e48d 100644 --- a/manufacturing_timesheet/doc/RELEASE_NOTES.md +++ b/manufacturing_timesheet/doc/RELEASE_NOTES.md @@ -8,4 +8,9 @@ #### 08.11.2024 #### Version 17.0.1.0.0 #### Updated -- Updated the code for adding the value to allocated hours while creating a project task in the MRP work order. Also updated it in index. \ No newline at end of file +- Updated the code for adding the value to allocated hours while creating a project task in the MRP work order. Also updated it in index. + +#### 04.07.2025 +#### Version 17.0.1.0.1 +#### FIX +- Fixed the singleton error that occurred when clicking the 'Produce All' button. \ No newline at end of file diff --git a/manufacturing_timesheet/models/mrp_workorder.py b/manufacturing_timesheet/models/mrp_workorder.py index 47e4f43f0..fce48f55d 100644 --- a/manufacturing_timesheet/models/mrp_workorder.py +++ b/manufacturing_timesheet/models/mrp_workorder.py @@ -168,35 +168,43 @@ class MrpWorkorder(models.Model): """ res = super(MrpWorkorder, self).button_finish() - allocated_hours = int(self.duration_expected) - allocated_minutes = int( - (self.duration_expected - allocated_hours) * 60) - allocated_time_str = f"{allocated_hours:02d}:{allocated_minutes:02d}" - allocated_minutes_str, allocated_seconds_str = allocated_time_str.split( - ":") - allocated_minutes = int(allocated_minutes_str) - allocated_seconds = int(allocated_minutes_str) - total_allocated_hours = ( - allocated_minutes + allocated_seconds / 60) / 60 - project = self.env['project.project'].search( - [('name', '=', ("MO: {}".format(self.production_id.name)))]) - task_id = project.task_ids.search([('name', '=', ( - "{} in {} for {} on {}".format(self.name, self.workcenter_id.name, - self.product_id.display_name, - str(self.date_start))))]) - task_id.write({ - 'allocated_hours': total_allocated_hours - }) - timesheet = task_id.mapped('timesheet_ids') - hours = int(self.duration) - minutes = int((self.duration - hours) * 60) - time_str = f"{hours:02d}:{minutes:02d}" - minutes_str, seconds_str = time_str.split(":") - minutes = int(minutes_str) - seconds = int(seconds_str) - total_hours = (minutes + seconds / 60) / 60 - for rec in timesheet: - rec.write({ - 'unit_amount': total_hours, + for workorder in self: + allocated_hours = int(workorder.duration_expected) + allocated_minutes = int((workorder.duration_expected - allocated_hours) * 60) + allocated_time_str = f"{allocated_hours:02d}:{allocated_minutes:02d}" + allocated_minutes_str, allocated_seconds_str = allocated_time_str.split(":") + + allocated_minutes = int(allocated_minutes_str) + allocated_seconds = int(allocated_seconds_str) + + total_allocated_hours = (allocated_minutes + allocated_seconds / 60) / 60 + + project = self.env['project.project'].search([ + ('name', '=', f"MO: {workorder.production_id.name}") + ], limit=1) + task_id = project.task_ids.search([ + ('name', '=', f"{workorder.name} in {workorder.workcenter_id.name} " + f"for {workorder.product_id.display_name} on {workorder.date_start}") + ], limit=1) + + task_id.write({ + 'allocated_hours': total_allocated_hours }) + + timesheet = task_id.mapped('timesheet_ids') + + hours = int(workorder.duration) + minutes = int((workorder.duration - hours) * 60) + time_str = f"{hours:02d}:{minutes:02d}" + minutes_str, seconds_str = time_str.split(":") + + minutes = int(minutes_str) + seconds = int(seconds_str) + total_hours = (minutes + seconds / 60) / 60 + + for rec in timesheet: + rec.write({ + 'unit_amount': total_hours, + }) + return res