-
Notifications
You must be signed in to change notification settings - Fork 30.2k
[FIX] mrp: dont compute oee with intermediary rounding #218310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FIX] mrp: dont compute oee with intermediary rounding #218310
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix and test !
I left a few comments concerning details of the technical aspect of the fix :)
I totally agree with the direction of the fix since it only improves the accuracy of the computed value. However, I am wondering if such a change is really suitable for 16.0 which we will not support in 3 months. My issues are that:
- The rounding issue only ever happen in cases that the cumulative duration of the
mrp.workcenter.productivityis not suitable to be rounded in hours (e.g. is two smalls like close to the minutes and not to the hour), the use cases were this improved computation is really relevant might be a bit niche. - Since the oee value is only used in the kanban view and on that smart button for display purposes, the issue does not seem blocking/too impacting.
I personally think it is still worth fixing as the change does not seem that risky but I leave the decision to the stock team oif they want to retarget higher versions !
addons/mrp/models/mrp_workcenter.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The computations of productive_time and blocked_time do not need to sum as they are both fields are floats fields (and hence will be aggregated using the sum by the read_group:
Line 1515 in fd5fe84
| group_operator = 'sum' |
I therefore guess that you wrote this sum with an if condition to filter out the record with the appropriate
loss_type. Wouldn't it be clearer to access the value directly define the blocked_time as such (just as in the compute method of blocked_time) ?
It would also highlight that your on "hand" computation of the productive_time and of the blocked_time does the exact same as the regular one except that it keeps the raw value for your computation of the oee.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, we need to sum because we get both the productive and blocked (non-productive) time in the same _read_group()
8628b4e to
43ce769
Compare
43ce769 to
74425e1
Compare
74425e1 to
2925d17
Compare
addons/mrp/models/mrp_workcenter.py
Outdated
| time_data = self.env['mrp.workcenter.productivity'].read_group( | ||
| domain=[ | ||
| ('date_start', '>=', fields.Datetime.to_string(datetime.now() - relativedelta.relativedelta(months=1))), | ||
| ('workcenter_id', 'in', self.ids), | ||
| ('date_end', '!=', False), | ||
| ], | ||
| fields=['workcenter_id', 'loss_type', 'duration'], | ||
| groupby=['workcenter_id', 'loss_type'], | ||
| lazy=False, | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| time_data = self.env['mrp.workcenter.productivity'].read_group( | |
| domain=[ | |
| ('date_start', '>=', fields.Datetime.to_string(datetime.now() - relativedelta.relativedelta(months=1))), | |
| ('workcenter_id', 'in', self.ids), | |
| ('date_end', '!=', False), | |
| ], | |
| fields=['workcenter_id', 'loss_type', 'duration'], | |
| groupby=['workcenter_id', 'loss_type'], | |
| lazy=False, | |
| ) | |
| time_data = self.env['mrp.workcenter.productivity']._read_group( | |
| domain=[ | |
| ('date_start', '>=', fields.Datetime.to_string(datetime.now() - relativedelta.relativedelta(months=1))), | |
| ('workcenter_id', 'in', self.ids), | |
| ('date_end', '!=', False), | |
| ], | |
| groupby=['workcenter_id', 'loss_type'], | |
| aggregates=['duration:sum'], | |
| ) |
As a rule of thumb, always prefer _read_group. More details on the why here.
addons/mrp/models/mrp_workcenter.py
Outdated
| time_by_order = defaultdict(lambda: {'productive_time': 0.0, 'blocked_time': 0.0}) | ||
| for td in time_data: | ||
| time_to_update = 'productive_time' if td['loss_type'] == 'productive' else 'blocked_time' | ||
| time_by_order[td['workcenter_id'][0]][time_to_update] += td['duration'] | ||
| for order in self: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| for order in self: | |
| for workcenter in self: |
Pet peeve of mine, but since we're rewriting the compute anyway... Using order used here is misleading.
2fe05a0 to
edd5cd2
Compare
|
Thanks for the fix! |
|
@ethanrobv @clesgow 'ci/runbot' failed on this reviewed PR. |
**Current behavior:** The form view for a workcenter has an OEE smart button which can display a different value from the real OEE displayed by the `mrp_workcenter_productivity_report_oee` displayed when actually clicking the button and looking at the report. **Expected behavior:** Same values **Steps to reproduce:** 1. Make a workcenter and a BoM with an operation performed at the workcenter 2. Use the BoM in an MO such that there is some un-productive time (e.g., recorded production duration takes longer than expected duration) * example: 0:20 expected, 1:01 actual 3. Go to the workcenter list view -> click on the created workcenter -> look at OEE smart button display value -> click on it to see report -> report values are different **Cause of the issue:** the `oee` field on the workcenter is computed with rounded intermediary `blocked_time` and `productive_time` values, the actual report uses the raw values. **Fix:** Don't use the rounded intermediary values in computing `oee`. Post-this-diff, we actually do one less `_read_group` (along with computing a more accurate field value). opw-4795463
edd5cd2 to
22d9cd0
Compare
|
@robodoo r+ |
**Current behavior:** The form view for a workcenter has an OEE smart button which can display a different value from the real OEE displayed by the `mrp_workcenter_productivity_report_oee` displayed when actually clicking the button and looking at the report. **Expected behavior:** Same values **Steps to reproduce:** 1. Make a workcenter and a BoM with an operation performed at the workcenter 2. Use the BoM in an MO such that there is some un-productive time (e.g., recorded production duration takes longer than expected duration) * example: 0:20 expected, 1:01 actual 3. Go to the workcenter list view -> click on the created workcenter -> look at OEE smart button display value -> click on it to see report -> report values are different **Cause of the issue:** the `oee` field on the workcenter is computed with rounded intermediary `blocked_time` and `productive_time` values, the actual report uses the raw values. **Fix:** Don't use the rounded intermediary values in computing `oee`. Post-this-diff, we actually do one less `_read_group` (along with computing a more accurate field value). opw-4795463 closes #218310 Signed-off-by: Quentin Wolfs (quwo) <quwo@odoo.com>
**Current behavior:** The form view for a workcenter has an OEE smart button which can display a different value from the real OEE displayed by the `mrp_workcenter_productivity_report_oee` displayed when actually clicking the button and looking at the report. **Expected behavior:** Same values **Steps to reproduce:** 1. Make a workcenter and a BoM with an operation performed at the workcenter 2. Use the BoM in an MO such that there is some un-productive time (e.g., recorded production duration takes longer than expected duration) * example: 0:20 expected, 1:01 actual 3. Go to the workcenter list view -> click on the created workcenter -> look at OEE smart button display value -> click on it to see report -> report values are different **Cause of the issue:** the `oee` field on the workcenter is computed with rounded intermediary `blocked_time` and `productive_time` values, the actual report uses the raw values. **Fix:** Don't use the rounded intermediary values in computing `oee`. Post-this-diff, we actually do one less `_read_group` (along with computing a more accurate field value). opw-4795463 closes #218310 Signed-off-by: Quentin Wolfs (quwo) <quwo@odoo.com>

Current behavior:
The form view for a workcenter has an OEE smart button which can display a different value from the real OEE displayed by the
mrp_workcenter_productivity_report_oeedisplayed when actually clicking the button and looking at the report.Expected behavior:
Same values
Steps to reproduce:
Make a workcenter and a BoM with an operation performed at the workcenter
Use the BoM in an MO such that there is some un-productive time (e.g., recorded production duration takes longer than expected duration)
Cause of the issue:
the
oeefield on the workcenter is computed with rounded intermediaryblocked_timeandproductive_timevalues, the actual report uses the raw values.Fix:
Don't use the rounded intermediary values in computing
oee.Post-this-diff, we actually do one less
_read_group(along with computing a more accurate field value).opw-4795463