[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) <whe@odoo.com>
This commit is contained in:
Adrien Widart (awt)
2023-01-24 10:20:12 +01:00
committed by William Henrotin
parent d395d1f4de
commit 4ceb57fa64
2 changed files with 8 additions and 15 deletions
+7
View File
@@ -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."""
+1 -15
View File
@@ -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