[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
1ecdbfcfbf, 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) <xbo@odoo.com>
Signed-off-by: Levi Siuzdak <sile@odoo.com>
This commit is contained in:
Levi Siuzdak (sile)
2023-12-13 15:52:59 +00:00
parent 8f6e89bdd7
commit 95f12b4667
@@ -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 });
}
};