From 4ceb57fa648d205fd684627b8eb9a5323eafce25 Mon Sep 17 00:00:00 2001 From: "Adrien Widart (awt)" Date: Thu, 5 Jan 2023 15:11:44 +0000 Subject: [PATCH] [REF] mrp{,_account}: extract computation of WO cost Extract that part so it can be overridden closes odoo/odoo#109340 X-original-commit: 39ff78b1dd2d4ae7017fde0282f78ead34637696 Related: odoo/enterprise#35533 Related: odoo/upgrade#4220 Signed-off-by: William Henrotin (whe) --- addons/mrp/models/mrp_workorder.py | 7 +++++++ addons/mrp_account/models/mrp_production.py | 16 +--------------- 2 files changed, 8 insertions(+), 15 deletions(-) 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