1# -*- coding: utf-8 -*- 2# Part of Odoo. See LICENSE file for full copyright and licensing details. 3 4from odoo import api, fields, models 5from ast import literal_eval 6 7 8class Company(models.Model): 9 _inherit = "res.company" 10 11 @api.model 12 def action_open_website_theme_selector(self): 13 action = self.env["ir.actions.actions"]._for_xml_id("website.theme_install_kanban_action") 14 action['target'] = 'new' 15 return action 16 17 def google_map_img(self, zoom=8, width=298, height=298): 18 partner = self.sudo().partner_id 19 return partner and partner.google_map_img(zoom, width, height) or None 20 21 def google_map_link(self, zoom=8): 22 partner = self.sudo().partner_id 23 return partner and partner.google_map_link(zoom) or None 24 25 def _compute_website_theme_onboarding_done(self): 26 """ The step is marked as done if one theme is installed. """ 27 # we need the same domain as the existing action 28 action = self.env["ir.actions.actions"]._for_xml_id("website.theme_install_kanban_action") 29 domain = literal_eval(action['domain']) 30 domain.append(('state', '=', 'installed')) 31 installed_themes_count = self.env['ir.module.module'].sudo().search_count(domain) 32 for record in self: 33 record.website_theme_onboarding_done = (installed_themes_count > 0) 34 35 website_theme_onboarding_done = fields.Boolean("Onboarding website theme step done", 36 compute='_compute_website_theme_onboarding_done') 37 38 def _get_public_user(self): 39 self.ensure_one() 40 # We need sudo to be able to see public users from others companies too 41 public_users = self.env.ref('base.group_public').sudo().with_context(active_test=False).users 42 public_users_for_website = public_users.filtered(lambda user: user.company_id == self) 43 44 if public_users_for_website: 45 return public_users_for_website[0] 46 else: 47 return self.env.ref('base.public_user').sudo().copy({ 48 'name': 'Public user for %s' % self.name, 49 'login': 'public-user@company-%s.com' % self.id, 50 'company_id': self.id, 51 'company_ids': [(6, 0, [self.id])], 52 }) 53