[imp] mail_digest: fallback to default website

Depending on the request  might fail
nevertheless the website should be there to be found.
Fallback to search and use it if possible for digest' site name
pull/228/head
Simone Orsi 2018-01-12 15:46:57 +01:00 committed by Holger Brunn
parent fffc27787e
commit 6a76103814
1 changed files with 9 additions and 2 deletions

View File

@ -131,12 +131,19 @@ class MailDigest(models.Model):
# default to company # default to company
name = self.env.user.company_id.name name = self.env.user.company_id.name
if 'website' in self.env: if 'website' in self.env:
# TODO: shall we make this configurable at digest or global level?
# Maybe you have a website but
# your digest msgs are not related to it at all or partially.
ws = None
try: try:
ws = self.env['website'].get_current_website() ws = self.env['website'].get_current_website()
name = ws.name name = ws.name
except RuntimeError: except RuntimeError:
# RuntimeError: object unbound -> no website request # RuntimeError: object unbound -> no website request.
pass # Fallback to default website if any.
ws = self.env['website'].search([], limit=1)
if ws:
name = ws.name
return name return name
@api.multi @api.multi