45 lines
2.5 KiB
Python
45 lines
2.5 KiB
Python
from odoo import api, fields, models
|
|
from odoo.tools.float_utils import float_round
|
|
|
|
class MrpProductionSchedule(models.Model):
|
|
_inherit = 'mrp.production.schedule'
|
|
|
|
packaging_id = fields.Many2one('mrp.packaging', string='Packaging', domain="[('product_tmpl_id', '=', product_tmpl_id)]", check_company=True)
|
|
|
|
def get_production_schedule_view_state(self, period_scale=False, use_all_schedules=False):
|
|
res = super().get_production_schedule_view_state(period_scale, use_all_schedules)
|
|
for state in res:
|
|
# When use_all_schedules is True, it means we are in the context of replenishment calculation
|
|
# (action_replenish -> get_production_schedule_view_state), so we should NOT convert units
|
|
# because the system expects base units for procurement.
|
|
if use_all_schedules:
|
|
continue
|
|
|
|
mps = self.browse(state['id'])
|
|
if mps.packaging_id:
|
|
packaging_qty = mps.packaging_id.qty
|
|
if packaging_qty:
|
|
# Adjust header details if needed, but mostly we modify forecast_ids
|
|
for forecast in state['forecast_ids']:
|
|
forecast['forecast_qty'] = forecast['forecast_qty'] / packaging_qty
|
|
forecast['replenish_qty'] = forecast['replenish_qty'] / packaging_qty
|
|
forecast['safety_stock_qty'] = forecast['safety_stock_qty'] / packaging_qty
|
|
forecast['starting_inventory_qty'] = forecast['starting_inventory_qty'] / packaging_qty
|
|
forecast['incoming_qty'] = forecast['incoming_qty'] / packaging_qty
|
|
forecast['outgoing_qty'] = forecast['outgoing_qty'] / packaging_qty
|
|
forecast['indirect_demand_qty'] = forecast['indirect_demand_qty'] / packaging_qty
|
|
|
|
if state.get('product_uom_id'):
|
|
state['product_uom_id'] = (state['product_uom_id'][0], mps.packaging_id.name)
|
|
return res
|
|
|
|
def set_forecast_qty(self, date_index, quantity, period_scale=False):
|
|
if self.packaging_id:
|
|
quantity = float(quantity) * self.packaging_id.qty
|
|
return super().set_forecast_qty(date_index, quantity, period_scale)
|
|
|
|
def set_replenish_qty(self, date_index, quantity, period_scale=False):
|
|
if self.packaging_id:
|
|
quantity = float(quantity) * self.packaging_id.qty
|
|
return super().set_replenish_qty(date_index, quantity, period_scale)
|