From 95f12b46677a57447bbee86eb7a6eea3ef1f43cd Mon Sep 17 00:00:00 2001 From: "Levi Siuzdak (sile)" Date: Mon, 11 Dec 2023 14:42:39 +0100 Subject: [PATCH] [FIX] sale_timesheet: set `is_so_line_edited` when clearing `so_line` Versions: --------- - 16.0+ Steps to reproduce: ------------------- 1. In Timesheets, add a new line; 2. link it to a Sale Order project; 3. make it non-billable by clearing the Sale Order Item field; 4. select related project in Project / Configuration / Projects; 5. in Invoicing tab, add yourself and a Sales Order Item, then save; 6. go back to Timesheets; 7. check the Sales Order Item field of the timesheet you created. Issue: ------ Sales Order Item was changed automatically, this shouldn't happen after a manual change. Cause: ------ The `so_line_field` widget used the `this.changeOnEmpty` attribute to check whether `is_so_line_edited` should be set, but this was removed in 1ecdbfcfbffae66544bfec578359ac4a6b6bc416, hence the field will never be set when clearing the `so_field` value. Solution: --------- On a field change, compare the previous ID of `so_line` with the new ID, and set `is_so_line_edited` to `true` if they're different. Related: -------- odoo/enterprise#52544 opw-3547725 closes odoo/odoo#146062 X-original-commit: bc1ad08286be9bb02d111e49fe095879b649449e Signed-off-by: Xavier Bol (xbo) Signed-off-by: Levi Siuzdak --- .../static/src/components/so_line_field/so_line_field.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/sale_timesheet/static/src/components/so_line_field/so_line_field.js b/addons/sale_timesheet/static/src/components/so_line_field/so_line_field.js index 9a3d2ab959991..01f6d41cde522 100644 --- a/addons/sale_timesheet/static/src/components/so_line_field/so_line_field.js +++ b/addons/sale_timesheet/static/src/components/so_line_field/so_line_field.js @@ -11,7 +11,10 @@ export class SoLineField extends Many2OneField { const update = this.update; this.update = (value, params = {}) => { update(value, params); - if (value || this.updateOnEmpty) { + if ( // field is unset AND the old & new so_lines are different + !this.props.record.data.is_so_line_edited && + this.props.value[0] != (value[0] && value[0].id) + ) { this.props.record.update({ is_so_line_edited: true }); } };