[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 odoo/odoo#38278

X-original-commit: 28ebe6d4849a692d234b4c256332525aa71132e5
Signed-off-by: Romain Libert (rli) <rli@odoo.com>
This commit is contained in:
RomainLibert
2019-10-09 12:20:08 +00:00
committed by fw-bot
parent 1abd0f6a63
commit c0f6e50fdd
2 changed files with 13 additions and 1 deletions
+1 -1
View File
@@ -79,7 +79,7 @@ class LunchProductReport(models.Model):
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,
+12
View File
@@ -7,3 +7,15 @@ from odoo.addons.lunch.tests.common import TestsCommon
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')