odoo/odoo#285827

Created by fw-bot
Merged at 12c00e4b6e3b6cd597847cca884c374460bfdbe6

Statuses:

label
odoo-dev:saas-19.3-18.0-pos-opw-6401146-2-pebr-562727-fw
head
46c363ce3b50a22e49e626c0286ee61a4617914b
merged
3 days ago by Pedram Bi Ria (pebr)
odoo/odoo
18.0 #284695
saas-18.3 #285427
saas-18.4 #285662
19.0 #285769
saas-19.1 #285793
saas-19.2 #285813
saas-19.3 #285827
saas-19.4 #285835
master #285848

[FIX] point_of_sale: do not unlink a reloaded orderline

Steps to reproduce:
- Restaurant config with two POS devices on the same session
- Device A: open a table, add two products, press Order (the order is synced as a draft, its lines get server ids)
- Device A: remove both lines, without syncing
- Device B: touch the same order, so device A re-reads it from the server through the synchronisation websocket
- Device A: pay and validate the order

Issue:
The order is saved as paid, with its total and its payment, but without any orderline. The lines are deleted on the server: odoo.models.unlink: deleted pos.order.line records with IDs: [...]

Cause:
Removing an orderline queues an unlink command in
models.commands['pos.order'].unlink['lines_<order id>'] (delete_ in related_models.js). That command is only discarded by clearCommands(), which syncAllOrders() calls after a successful sync, so it stays pending in between.

Any read of the order in that window puts the line back: a deleted record counts as missing in missingRecursive(), so it is fetched again and loadData() re-creates it with its server id.

serialize() then emits both the update of the live line and the still pending unlink, and sync_from_ui writes
lines: [[1, id, {...}], [3, id]]. The ORM applies commands in order, and pos.order.line.order_id is ondelete='cascade', so Command.UNLINK deletes the line right after writing it.

Fix:
Skip a removal command when the record is still linked to the parent at serialization time. A record cannot be both linked and removed in the same payload, so the pending command is stale and dropping it keeps the local state. Genuine removals, where the record is no longer linked, are still sent.

opw-6401146


I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr

Forward-Port-Of: #285427
Forward-Port-Of: #284695