[FIX] website: don't flag generic view as noupdate when COWing
Once `website` module is installed, the `save` method will always write on the specific view or create it if it does not exist yet. This means that actually, the generic view will never have his `arch` modified through the `save` method. Thus, there is no need to flag it as noupdate as we want to receive update for that view (that might be used by other website without a specific view).
This commit is contained in:
committed by
Jeremy Kersten
parent
5a692c3417
commit
01d925e052
@@ -160,6 +160,10 @@ class IrUiView(models.Model):
|
||||
out.tail = el.tail
|
||||
return out
|
||||
|
||||
@api.model
|
||||
def _set_noupdate(self):
|
||||
self.sudo().mapped('model_data_id').write({'noupdate': True})
|
||||
|
||||
@api.multi
|
||||
def save(self, value, xpath=None):
|
||||
""" Update a view section. The view section may embed fields to write
|
||||
@@ -196,7 +200,7 @@ class IrUiView(models.Model):
|
||||
new_arch = self.replace_arch_section(xpath, arch_section)
|
||||
old_arch = etree.fromstring(self.arch.encode('utf-8'))
|
||||
if not self._are_archs_equal(old_arch, new_arch):
|
||||
self.sudo().model_data_id.write({'noupdate': True}) # TODO check if we remove this
|
||||
self._set_noupdate()
|
||||
self.write({'arch': self._pretty_arch(new_arch)})
|
||||
|
||||
@api.model
|
||||
|
||||
@@ -372,6 +372,15 @@ class View(models.Model):
|
||||
res['website_id'] = self.env['website'].get_current_website().id
|
||||
return res
|
||||
|
||||
@api.model
|
||||
def _set_noupdate(self):
|
||||
'''If website is installed, any call to `save` from the frontend will
|
||||
actually write on the specific view (or create it if not exist yet).
|
||||
In that case, we don't want to flag the generic view as noupdate.
|
||||
'''
|
||||
if not self._context.get('website_id'):
|
||||
super(View, self)._set_noupdate()
|
||||
|
||||
@api.multi
|
||||
def save(self, value, xpath=None):
|
||||
self.ensure_one()
|
||||
|
||||
@@ -159,6 +159,12 @@ class TestViewSaving(common.TransactionCase):
|
||||
h.LI(h.SPAN("+12 3456789", attrs(model='res.company', id=1, field='phone', expression="edmund", type='char'))),
|
||||
)
|
||||
), encoding='unicode')
|
||||
|
||||
self.view_id.with_context(website_id=1).save(value=replacement, xpath='/div/div[2]')
|
||||
self.assertFalse(imd.noupdate, "view's xml_id shouldn't be set to 'noupdate' in a website context as `save` method will COW")
|
||||
# remove newly created COW view so next `save()`` wont be redirected to COW view
|
||||
self.env['website'].with_context(website_id=1).viewref(self.view_id.key).unlink()
|
||||
|
||||
self.view_id.save(value=replacement, xpath='/div/div[2]')
|
||||
|
||||
# the xml_id of the view should be flagged as 'noupdate'
|
||||
|
||||
Reference in New Issue
Block a user