Esempio n. 1
0
 def create_an_experiment(self, data, website_id):
     gs_pool = self.env['google.service']
     website = self.env['website'].browse(website_id)[0]
     webPropertyId = website.google_analytics_key
     action_id = self.env['ir.model.data'].xmlid_to_res_id(
         'website_version.action_website_view')
     if not webPropertyId:
         raise exceptions.RedirectWarning(
             'Click on the website you want to make A/B testing and configure the Google Analytics Key and View ID',
             action_id, 'go to the websites menu')
     accountId = webPropertyId.split('-')[1]
     profileId = website.google_analytics_view_id
     if not profileId:
         raise exceptions.RedirectWarning(
             'Click on the website you want to make A/B testing and configure the Google Analytics Key and View ID',
             action_id, 'go to the websites menu')
     url = '/analytics/v3/management/accounts/%s/webproperties/%s/profiles/%s/experiments?access_token=%s' % (
         accountId, webPropertyId, profileId, self.get_token())
     headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
     data_json = simplejson.dumps(data)
     try:
         x = gs_pool._do_request(url, data_json, headers, type='POST')
         result = x[1]['id']
     except Exception, e:
         _logger.info(
             _('An exception occured during the google analytics rquest: %s'
               ) % e)
         raise
Esempio n. 2
0
 def _company_warning(self, cr, uid, translated_msg, context=None):
     """ Raise a error with custom message, asking user to configure company settings """
     xmlid_mod = self.pool['ir.model.data']
     action_id = xmlid_mod.xmlid_to_res_id(cr, uid,
                                           'base.action_res_company_form')
     raise exceptions.RedirectWarning(
         translated_msg, action_id, _('Go to company configuration screen'))
Esempio n. 3
0
    def _onchange_journal_id(self):
        if self.journal_id:
            session = self.env['account.invoicing.session'].search([('user_id', '=', self.env.user.id), ('state', '=', 'opened'), ('journal_id', '=', self.journal_id.id)])

            if session:
                self.invoicing_session_ids = session[0]
            else:
                journal = self.journal_id
                if journal.require_invoicing_session and len(session) == 0:
                    journal_type = journal.type
                    if journal_type == 'purchase':
                        action = self.env.ref('account_invoicing_session.purchase_list_action')
                        raise exceptions.RedirectWarning(_('At least one purchase session should be open for this user.'), action.id, _('Go to the sessions menu'))
                    if journal_type == 'sale':
                        action = self.env.ref('account_invoicing_session.sale_list_action')
                        raise exceptions.RedirectWarning(_('At least one sale session should be open for this user.'), action.id, _('Go to the sessions menu'))
Esempio n. 4
0
    def get_config_warning(self, cr, msg, context=None):
        """
        Helper: return a Warning exception with the given message where the %(field:xxx)s
        and/or %(menu:yyy)s are replaced by the human readable field's name and/or menuitem's
        full path.

        Usage:
        ------
        Just include in your error message %(field:model_name.field_name)s to obtain the human
        readable field's name, and/or %(menu:module_name.menuitem_xml_id)s to obtain the menuitem's
        full path.

        Example of use:
        ---------------
        from openerp.addons.base.res.res_config import get_warning_config
        raise get_warning_config(cr, _("Error: this action is prohibited. You should check the field %(field:sale.config.settings.fetchmail_lead)s in %(menu:base.menu_sale_config)s."), context=context)

        This will return an exception containing the following message:
            Error: this action is prohibited. You should check the field Create leads from incoming mails in Settings/Configuration/Sales.

        What if there is another substitution in the message already?
        -------------------------------------------------------------
        You could have a situation where the error message you want to upgrade already contains a substitution. Example:
            Cannot find any account journal of %s type for this company.\n\nYou can create one in the menu: \nConfiguration\Journals\Journals.
        What you want to do here is simply to replace the path by %menu:account.menu_account_config)s, and leave the rest alone.
        In order to do that, you can use the double percent (%%) to escape your new substitution, like so:
            Cannot find any account journal of %s type for this company.\n\nYou can create one in the %%(menu:account.menu_account_config)s.
        """

        res_config_obj = openerp.registry(cr.dbname)['res.config.settings']
        regex_path = r'%\(((?:menu|field):[a-z_\.]*)\)s'

        # Process the message
        # 1/ find the menu and/or field references, put them in a list
        references = re.findall(regex_path, msg, flags=re.I)

        # 2/ fetch the menu and/or field replacement values (full path and
        #    human readable field's name) and the action_id if any
        values = {}
        action_id = None
        for item in references:
            ref_type, ref = item.split(':')
            if ref_type == 'menu':
                values[item], action_id = res_config_obj.get_option_path(
                    cr, SUPERUSER_ID, ref, context=context)
            elif ref_type == 'field':
                values[item] = res_config_obj.get_option_name(cr,
                                                              SUPERUSER_ID,
                                                              ref,
                                                              context=context)

        # 3/ substitute and return the result
        if (action_id):
            return exceptions.RedirectWarning(
                msg % values, action_id, _('Go to the configuration panel'))
        return exceptions.Warning(msg % values)