Skip to content
Permalink
Browse files

[FIX] lunch: avoid rewriting ids

The wrong order was used in the row_number call, which lead to ids
changing when writing on `is_favorite`

closes #38092

Signed-off-by: Romain Libert (rli) <rli@odoo.com>
  • Loading branch information...
RomainLibert committed Oct 7, 2019
1 parent fcf03ea commit 28ebe6d4849a692d234b4c256332525aa71132e5
Showing with 13 additions and 1 deletion.
  1. +1 −1 addons/lunch/report/lunch_product_report.py
  2. +12 −0 addons/lunch/tests/test_product_report.py
@@ -79,7 +79,7 @@ def init(self):
self._cr.execute("""
CREATE or REPLACE view %s AS (
SELECT
row_number() over (ORDER BY user_id,product.id) AS id,
row_number() over (ORDER BY users.id,product.id) AS id,
product.id AS product_id,
product.name,
product.category_id,
@@ -7,3 +7,15 @@
class TestLunchProductReport(TestsCommon):
def test_product_available(self):
self.assertTrue(self.env['lunch.product.report'].search([]), 'There should be some record on lunch_product_report')

def test_order_in_report(self):
pizza = self.env['lunch.product.report'].search([('product_id', '=', self.product_pizza.id)], limit=1)
self.assertEqual(pizza.name, 'Pizza')
pizza = pizza.with_user(pizza.user_id)
pizza.write({'is_favorite': True})
self.assertTrue(pizza.product_id in pizza.user_id.favorite_lunch_product_ids)

new_pizza = self.env['lunch.product.report'].search([('product_id', '=', self.product_pizza.id), ('user_id', '=', pizza.user_id.id)])

self.assertEqual(new_pizza.id, pizza.id)
self.assertEqual(new_pizza.name, 'Pizza')

0 comments on commit 28ebe6d

Please sign in to comment.
You can’t perform that action at this time.