[FIX] stock: remove old lines when generating serials

When generating serial numbers or importing them, the old lines are still present
and the quantity done gets raised by the quantity of the added lines. This forces
the user to manually remove each old line one by one.

This ensures that old lines are removed by the amount of newly created lines.

closes odoo/odoo#140618

Signed-off-by: Arnold Moyaux (arm) <arm@odoo.com>
This commit is contained in:
snd
2023-11-04 00:38:26 +00:00
committed by Arnold Moyaux
parent e9225d52af
commit 7c45aca3be
2 changed files with 28 additions and 0 deletions
@@ -20,6 +20,7 @@ export class GenerateDialog extends Component {
this.nextSerial = useRef('nextSerial');
this.nextSerialCount = useRef('nextSerialCount');
this.keepLines = useRef('keepLines');
this.lots = useRef('lots');
this.orm = useService("orm");
onMounted(() => {
@@ -51,11 +52,18 @@ export class GenerateDialog extends Component {
})
);
}
if (!this.keepLines.el.checked) {
await lines._applyCommands(lines._currentIds.map((currentId) => [
x2ManyCommands.DELETE,
currentId,
]));
}
lines.records.push(...newlines);
lines._commands.push(...newlines.map((record) => [
x2ManyCommands.CREATE,
record._virtualId,
]));
lines._currentIds.push(...newlines.map((record) => record._virtualId));
await lines._onUpdate();
this.props.close();
}
@@ -31,6 +31,16 @@
</div>
</div>
</div>
<div class="d-flex d-sm-contents">
<div class="o_cell flex-grow-0 flex-sm-grow-0 text-900 pe-3">
<label class="o_form_label" for="keep_lines_0">Keep current lines</label>
</div>
<div class="o_cell flex-grow-1 flex-sm-grow-0">
<div name="keep_lines" class="o_input">
<input type="checkbox" t-ref="keepLines" id="keep_lines_0"/>
</div>
</div>
</div>
</div>
</t>
<t t-if="props.type === 'import'" class="d-flex">
@@ -47,6 +57,16 @@
class="o_input" t-ref="lots" id="next_serial_0" type="text"/>
</div>
</div>
<div class="d-flex d-sm-contents">
<div class="o_cell flex-grow-0 flex-sm-grow-0 text-900 pe-3">
<label class="o_form_label" for="keep_lines_0">Keep current lines</label>
</div>
</div>
<div class="o_cell flex-grow-1 flex-sm-grow-0">
<div name="keep_lines" class="o_input">
<input type="checkbox" t-ref="keepLines" id="keep_lines_0"/>
</div>
</div>
</div>
</t>
</div>