This issue came up working on a client feature that depends on the Workstation Operating Cost feature. Currently, Inventory Tools will update the hour_rate field on Workstation in before_save, grabbing the appropriate current-date-based costs from the Workstation Operating Cost table and setting the field, with a fallback to ERPNext's calc to use the component fields (labor + electricity + etc).
The client's use-case is they will add new Workstation Operating Cost rows with valid_from dates happening in the future, evaluate costing, then trigger a 'rollover' (happens on the from_date), which also updates BOM costs. This bypasses the before_save hook, and ERPNext's BOM cost calcs grab a cached value from the hour_rate field on Workstation, which will be the stale rates.
Proposed fix:
- Create an InventoryToolsBOM class
- Create override in UI for when a row is added to the BOM Operation table, the row's
hour_rate should check the Workstation Op Cost table dates against current date (or if no Workstation Op Cost rows, uses fallback to sum of static field values for labor/electricity/etc)
- Create override on InventoryToolsBOM class for
update_rate_and_time when costs are updated
- If the rate changed in either case, should set the Workstation's
hour_rate field to the new value in the DB
This issue came up working on a client feature that depends on the Workstation Operating Cost feature. Currently, Inventory Tools will update the
hour_ratefield on Workstation inbefore_save, grabbing the appropriate current-date-based costs from the Workstation Operating Cost table and setting the field, with a fallback to ERPNext's calc to use the component fields (labor + electricity + etc).The client's use-case is they will add new Workstation Operating Cost rows with valid_from dates happening in the future, evaluate costing, then trigger a 'rollover' (happens on the
from_date), which also updates BOM costs. This bypasses thebefore_savehook, and ERPNext's BOM cost calcs grab a cached value from thehour_ratefield on Workstation, which will be the stale rates.Proposed fix:
hour_rateshould check the Workstation Op Cost table dates against current date (or if no Workstation Op Cost rows, uses fallback to sum of static field values for labor/electricity/etc)update_rate_and_timewhen costs are updatedhour_ratefield to the new value in the DB