diff --git a/addons/mrp/models/mrp_workorder.py b/addons/mrp/models/mrp_workorder.py index bdb4f89f6d6..19765c80652 100644 --- a/addons/mrp/models/mrp_workorder.py +++ b/addons/mrp/models/mrp_workorder.py @@ -553,6 +553,13 @@ class MrpWorkorder(models.Model): vals['leave_id'] = leave.id self.write(vals) + def _cal_cost(self): + total = 0 + for wo in self: + duration = sum(wo.time_ids.mapped('duration')) + total += (duration / 60.0) * wo.workcenter_id.costs_hour + return total + @api.model def gantt_unavailability(self, start_date, end_date, scale, group_bys=None, rows=None): """Get unavailabilities data to display in the Gantt view.""" diff --git a/addons/mrp_account/models/mrp_production.py b/addons/mrp_account/models/mrp_production.py index 4769916a8e5..687c33abb8d 100644 --- a/addons/mrp_account/models/mrp_production.py +++ b/addons/mrp_account/models/mrp_production.py @@ -7,15 +7,6 @@ from odoo import api, fields, models, _ from odoo.tools import float_is_zero, float_round -class MrpProductionWorkcenterLineTime(models.Model): - _inherit = 'mrp.workcenter.productivity' - - # checked when a ongoing production posts journal entries for its costs. - # This way, we can record one production's cost multiple times and only - # consider new entries in the work centers time lines." - cost_already_recorded = fields.Boolean('Cost Recorded') - - class MrpProduction(models.Model): _inherit = 'mrp.production' @@ -87,12 +78,7 @@ class MrpProduction(models.Model): if finished_move: finished_move.ensure_one() for work_order in self.workorder_ids: - time_lines = work_order.time_ids.filtered( - lambda x: x.date_end and not x.cost_already_recorded) - duration = sum(time_lines.mapped('duration')) - time_lines.write({'cost_already_recorded': True}) - work_center_cost += (duration / 60.0) * \ - work_order.workcenter_id.costs_hour + work_center_cost += work_order._cal_cost() qty_done = finished_move.product_uom._compute_quantity( finished_move.quantity_done, finished_move.product_id.uom_id) extra_cost = self.extra_cost * qty_done