[FIX] website_blog: archive multiple blog.post throws a server error

Step to reproduce:
  - Go to 'Blog' > 'Blog Posts' in the 'Website Admin' module
  - Select several blog.post on the list view
  - Click on 'Archive' in the 'Action' dropdown

This will throw a server error since write() is overriden for blog.post and
do an ensure_one()

This commit closes #22208
This commit is contained in:
Romain Derie
2018-01-24 15:48:49 +01:00
committed by Jeremy Kersten
parent 34bfadb2f2
commit 3c998acaaf
+6 -5
View File
@@ -207,11 +207,12 @@ class BlogPost(models.Model):
@api.multi
def write(self, vals):
self.ensure_one()
if 'website_published' in vals and 'published_date' not in vals:
if self.published_date <= fields.Datetime.now():
vals['published_date'] = vals['website_published'] and fields.Datetime.now()
result = super(BlogPost, self).write(vals)
result = True
for post in self:
copy_vals = vals
if 'website_published' in vals and 'published_date' not in vals and post.published_date <= fields.Datetime.now():
copy_vals['published_date'] = vals['website_published'] and fields.Datetime.now() or False
result &= super(BlogPost, self).write(copy_vals)
self._check_for_publication(vals)
return result