[FIX] pos_sale: decrease sale.report ID conflict
issues:
- search sale.report with `('order_id', '!=', False)` in list view =>
you might get lines without sale order, with the wrong product, ...
- group sale.report by product on list view => you might get lines with
a different product than the group
cause:
the sale.report IDs are an union of sale_order_line.id and
pos_order_line.id => so there can be 2 lines of sale.report with same
IDs but pointing two completely different record.
rejected solution:
using row_number() over() for ID after the UNION ALL => rejected since
there was a `row_number` on sale.report at one point that was removed
because of performance issue (03bd6f5243e189cd05b3fc7ad774cc07ea733e14).
solution:
using negative IDs for pos_order_line lines
drawback:
in 14.0, we already use negative IDs for sale_order without lines =>
the probability of conflict is lower for this case and sale.order.line
not being in conflict is better.
opw-2586062
opw-2694529
closes odoo/odoo#83621
X-original-commit: cdaf046637704b53047b79984669ed2044cd8da6
Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com>
This commit is contained in:
@@ -24,7 +24,7 @@ class SaleReport(models.Model):
|
||||
|
||||
def _select_pos(self):
|
||||
select_ = """
|
||||
MIN(l.id) AS id,
|
||||
-MIN(l.id) AS id,
|
||||
l.product_id AS product_id,
|
||||
t.uom_id AS product_uom,
|
||||
SUM(l.qty) AS product_uom_qty,
|
||||
|
||||
@@ -31,8 +31,8 @@ class TestPoSSaleReport(TestPoSCommon):
|
||||
|
||||
session.action_pos_session_closing_control()
|
||||
|
||||
# Orders are reversed, so reports[0] will correspond to the second order
|
||||
reports = self.env['sale.report'].sudo().search([('product_id', '=', self.product0.id)], order='id desc', limit=2)
|
||||
# PoS Orders have negative IDs to avoid conflict, so reports[0] will correspond to the newest order
|
||||
reports = self.env['sale.report'].sudo().search([('product_id', '=', self.product0.id)], order='id', limit=2)
|
||||
self.assertEqual(reports[0].weight, 3)
|
||||
self.assertEqual(reports[0].volume, 4)
|
||||
self.assertEqual(reports[1].weight, 18)
|
||||
|
||||
Reference in New Issue
Block a user