diff options
| author | qsm-odoo <qsm@odoo.com> | 2018-11-15 17:43:40 +0000 |
|---|---|---|
| committer | qsm-odoo <qsm@odoo.com> | 2018-11-16 10:03:13 +0000 |
| commit | ec7aa3c1f16d76008dbd83e723591a04da6a868b (patch) | |
| tree | 2fe2af593078ef0ea4dd9890241497f579ced92d | |
| parent | de76e5e081792eab757b06de37a04b0b2753dbdc (diff) | |
[FIX] website: properly enable a website view from its generic view
Before this commit, when enabling a generic view from a specific website
context and that view already had a specific view for this website, the
view was duplicated again instead of writing on the already existing
specific one.
This is because we did not consider inactive views when checking if a
view that is being written already has a website-specific view.
closes odoo/odoo#28743
| -rw-r--r-- | addons/website/models/ir_ui_view.py | 2 | ||||
| -rw-r--r-- | addons/website/tests/test_views.py | 13 |
2 files changed, 9 insertions, 6 deletions
diff --git a/addons/website/models/ir_ui_view.py b/addons/website/models/ir_ui_view.py index d3c6a55a6b7..75b1a8d4fe4 100644 --- a/addons/website/models/ir_ui_view.py +++ b/addons/website/models/ir_ui_view.py @@ -45,7 +45,7 @@ class View(models.Model): view.with_context(no_cow=True).key = 'website.key_%s' % str(uuid.uuid4())[:6] if not view.website_id and current_website_id and not self._context.get('no_cow'): # If already a specific view for this generic view, write on it - website_specific_view = self.env['ir.ui.view'].search([ + website_specific_view = view.search([ ('key', '=', view.key), ('website_id', '=', current_website_id) ], limit=1) diff --git a/addons/website/tests/test_views.py b/addons/website/tests/test_views.py index 5bbfbd07112..49a76cf78ab 100644 --- a/addons/website/tests/test_views.py +++ b/addons/website/tests/test_views.py @@ -421,10 +421,13 @@ class TestCowViewSaving(common.TransactionCase): 'arch': '<div>content</div>', }) - total_views = View.search_count([]) + total_views = View.with_context(active_test=False).search_count([]) base_view.with_context(website_id=1).write({'name': 'New Name'}) # This will not write on `base_view` but will copy it to a specific view on which the `name` change will be applied + specific_view = View.search([['name', '=', 'New Name'], ['website_id', '=', 1]]) base_view.with_context(website_id=1).write({'name': 'Another New Name'}) - self.assertEqual(total_views + 1, View.search_count([]), "Second write should have wrote on the view copied during first write") + specific_view.active = False + base_view.with_context(website_id=1).write({'name': 'Yet Another New Name'}) + self.assertEqual(total_views + 1, View.with_context(active_test=False).search_count([]), "Subsequent writes should have written on the view copied during first write") # 2. Test with calling save() from ir.ui.view view_arch = '''<t name="Second View" t-name="website.second_view"> @@ -444,12 +447,12 @@ class TestCowViewSaving(common.TransactionCase): 'arch': view_arch, }) - total_views = View.search_count([]) + total_views = View.with_context(active_test=False).search_count([]) second_view.with_context(website_id=1).save('<div class="editable_part" data-oe-id="%s" data-oe-xpath="/t[1]/t[1]/div[1]/div[1]" data-oe-field="arch" data-oe-model="ir.ui.view">First editable_part</div>' % second_view.id, "/t[1]/t[1]/div[1]/div[1]") second_view.with_context(website_id=1).save('<div class="editable_part" data-oe-id="%s" data-oe-xpath="/t[1]/t[1]/div[1]/div[3]" data-oe-field="arch" data-oe-model="ir.ui.view">Second editable_part</div>' % second_view.id, "/t[1]/t[1]/div[1]/div[3]") - self.assertEqual(total_views + 1, View.search_count([]), "Second save should have wrote on the view copied during first save") + self.assertEqual(total_views + 1, View.with_context(active_test=False).search_count([]), "Second save should have written on the view copied during first save") - total_specific_view = View.search_count([('arch_db', 'like', 'First editable_part'), ('arch_db', 'like', 'Second editable_part')]) + total_specific_view = View.with_context(active_test=False).search_count([('arch_db', 'like', 'First editable_part'), ('arch_db', 'like', 'Second editable_part')]) self.assertEqual(total_specific_view, 1, "both editable_part should have been replaced on a created specific view") def test_cow_complete_flow(self): |
