Пример #1
0
 def connect(self, cr, uid, server_id, context=None):
     if isinstance(server_id, (list, tuple)):
         server_id = server_id[0]
     if get_mode():
         raise Warning(_(
             "Can not Connect to server because Odoo is in %s mode.") % (
             get_mode()))
     return super(fetchmail_server, self).connect(
         cr, uid, server_id=server_id, context=context)
Пример #2
0
 def send_email(self,
                cr,
                uid,
                message,
                mail_server_id=None,
                smtp_server=None,
                smtp_port=None,
                smtp_user=None,
                smtp_password=None,
                smtp_encryption=None,
                smtp_debug=False,
                context=None):
     # TODO
     # if we raise ValidationError then can not install modules with demo
     # data, we should find a way to raise message when sending from
     # interface
     # raise ValidationError(_(
     if get_mode():
         _logger.warning(
             _("You Can not Send Mail Because Odoo is not in Production "
               "mode"))
         return True
     return super(ir_mail_server,
                  self).send_email(cr,
                                   uid,
                                   message,
                                   mail_server_id=mail_server_id,
                                   smtp_server=smtp_server,
                                   smtp_port=smtp_port,
                                   smtp_user=smtp_user,
                                   smtp_password=smtp_password,
                                   smtp_encryption=smtp_encryption,
                                   smtp_debug=smtp_debug,
                                   context=None)
Пример #3
0
 def button_try_not_prod(self):
     if not get_mode():
         raise ValidationError(
             _('You can not try a category on a production database'))
     self.contracted_product = 'try_not_prod'
     # refresh modules data
     self.env['ir.module.module'].update_uninstallable_state()
     # marcamos a instalar por categoria
     self.env['ir.module.module'].set_to_install_from_category()
     # ejecutamos instalacion y actualizacion
     self.env['base.module.upgrade'].sudo().upgrade_module()
Пример #4
0
 def _cron_update_adhoc_modules(self):
     if get_mode():
         _logger.info(
             'Update adhoc modules is disable by server_mode. '
             'If you want to enable it you should remove develop or test '
             'value for server_mode key on openerp server config file')
         return False
     try:
         self.get_adhoc_modules_data()
     except Exception, e:
         _logger.error("Error Updating ADHOC Modules Data. Error:\n%s" %
                       (e))
Пример #5
0
    def print_document(self, report, content, format, copies=1):
        """ Print a file

        Format could be pdf, qweb-pdf, raw, ...

        """
        if len(self) != 1:
            _logger.error('Google cloud print called with %s but singleton is'
                          'expeted. Check printers configuration.' % self)
            return super(PrintingPrinter, self).print_document(report,
                                                               content,
                                                               format,
                                                               copies=copies)
        # self.ensure_one()
        if self.printer_type != 'gcp':
            return super(PrintingPrinter, self).print_document(report,
                                                               content,
                                                               format,
                                                               copies=copies)
        if get_mode():
            _logger.warning(
                _("You Can not Send Mail Because Odoo is not in Production "
                  "mode"))
            return True

        fd, file_name = mkstemp()
        try:
            os.write(fd, content)
        finally:
            os.close(fd)

        options = self.print_options(report, format, copies)

        _logger.debug('Sending job to Google Cloud printer %s' %
                      (self.system_name))

        # atrapamos el error y lo mandamos por el log para que no de piedrazo
        # y posiblemente rompa interfaz
        try:
            self.env['google.cloudprint.config'].submit_job(
                self.uri,
                format,
                file_name,
                options,
            )
        except Exception, e:
            # access_token = self.get_access_token()
            _logger.error(
                'Could not submit job to google cloud. This is what we get:\n'
                '%s' % e)
Пример #6
0
    def update_adhoc_categories(self, client):
        contract_id = self._context.get('contract_id')
        fields = [
            'name',
            'code',
            'parent_id',
            'visibility',
            'description',
            'sequence',
        ]
        updated_records = local_model = self.env['adhoc.module.category']
        remote_model = client.model('adhoc.module.category.server')

        remote_datas = remote_model.search_read([], fields, 0, None,
                                                'parent_left')
        for remote_data in remote_datas:
            # we dont wont or need id
            category_id = remote_data.pop('id')
            parent_data = remote_data.pop('parent_id')
            if parent_data:
                parent_code = remote_model.search_read(
                    [('id', '=', parent_data[0])], ['code'])[0]['code']
                parent = local_model.search([('code', '=', parent_code)],
                                            limit=1)
                remote_data['parent_id'] = parent.id
            local_record = local_model.search(
                [('code', '=', remote_data.get('code'))], limit=1)
            if remote_data['visibility'] in [
                    'product_required', 'product_invisible'
            ]:
                remote_data['contracted_product'] = (
                    remote_model.get_related_contracted_product(
                        category_id, contract_id))
            # hacemos el commit para que no de error adhoc contra adhoc
            self._cr.commit()
            if local_record:
                # we dont deactivate categories that are being tryind if
                # server_mode is not production
                if ('contracted_product' in remote_data
                        and not remote_data.get('contracted_product')
                        and get_mode()
                        and local_record.contracted_product == 'try_not_prod'):
                    remote_data.pop('contracted_product')
                local_record.write(remote_data)
            else:
                # local_record.create(remote_data)
                local_record = local_record.create(remote_data)
            updated_records += local_record
        # remove records that has not been updated (they dont exist anymore)
        (local_model.search([]) - updated_records).unlink()
 def _cron_scan_repositories(self):
     if get_mode():
         _logger.info(
             'Scan repositories is disable by server_mode. '
             'If you want to enable it you should remove develop or test '
             'value for server_mode key on openerp server config file')
         return False
     for repository in self.search([('auto_update', '=', True)]):
         try:
             repository.scan_repository()
             self._cr.commit()
         except:
             # TODO we should set a last update in each repository and
             # make cron run more frequently
             _logger.error("Error updating repository %s" %
                           (repository.name))
Пример #8
0
 def cron_check_databases(self):
     # TODO mejorar y solo verificar las que no fueron verificadas en el
     # ultimo intervalo de cron
     if get_mode():
         _logger.info(
             'Check databases cron is disable by server_mode. '
             'If you want to enable it you should remove develop or test '
             'value for server_mode key on openerp server config file')
         return False
     databases = self.with_context(do_not_raise=True).search([
         ('check_database', '=', True),
         ('state', '!=', 'inactive'),
     ])
     for db in databases:
         db.refresh_overall_state()
         db._cr.commit()
     return True
Пример #9
0
 def check_automatic_backup_enable(self):
     """
     Para que se hagan backups al hacer fix on con el cron, se requiere:
     1. Que no haya server mode definido
     2. Que haya un parametro database.backups.enable = 'True'
     """
     if get_mode():
         _logger.info(
             'Backups are disable by server_mode test or develop. '
             'If you want to enable it you should remove develop or test '
             'value for server_mode key on openerp server config file')
         return False
     backups_enable = self.env['ir.config_parameter'].get_param(
         'database.backups.enable')
     if backups_enable != 'True':
         _logger.info(
             'Backups are disable. If you want to enable it you should add '
             'the parameter database.backups.enable with value True')
         return False
     return True
Пример #10
0
    def cron_database_backup(self):
        """If backups enable in ir parameter, then:
        * Check if backups are enable
        * Make backup according to period defined
        * """
        if get_mode():
            _logger.warning(
                'Backups are disable by server_mode test or develop.\
                If you want to enable it you should remove develop or test\
                value for server_mode key on openerp server config file')
            return False
        backups_enable = self.env['ir.config_parameter'].get_param(
            'database.backups.enable')
        if backups_enable != 'True':
            _logger.warning(
                'Backups are disable. If you want to enable it you should add\
                the parameter database.backups.enable with value True')
            return False
        _logger.info('Running backups cron')
        current_date = fields.Datetime.now()
        # get databases
        databases = self.search([
            ('backup_next_date', '<=', current_date),
        ])

        # make bakcup
        # we make a loop to commit after each backup
        for database in databases:
            database.database_backup(
                bu_type='automatic',
                backup_format=database.backup_format)
            database._cr.commit()

        # clean databases
        databases = self.search([])

        databases.database_backup_clean()

        # clean databas information
        self.update_backups_data()
Пример #11
0
 def check_credentials(self, password):
     """
     Si el usuario es admin permitimos login con pass de instancia tmb
     Si el usuario es otro, permitimos con pass intancia o admin solo si:
     * no produccion
     * producción y allow on production True
     """
     passkey_allowed = True
     if not get_mode():
         if not literal_eval(
                 self.env['ir.config_parameter'].sudo().get_param(
                     'auth_admin_passkey.allow_on_production',
                     'True')):
             passkey_allowed = False
     if self.env.uid != SUPERUSER_ID and passkey_allowed:
         # try with user pass
         try:
             super(ResUsers, self).check_credentials(password)
             return True
         except exceptions.AccessDenied:
             # try with instance password
             try:
                 self.check_super(password)
                 return True
             except exceptions.AccessDenied:
                 # try with admin password
                 return self.sudo().check_credentials(password)
     # si es super admin, probamos tmb con clave de instancia
     elif self.env.uid == SUPERUSER_ID:
         # try with instance password
         try:
             self.check_super(password)
         except exceptions.AccessDenied:
             return super(ResUsers, self).check_credentials(password)
     # si no es super admin y no hay passkey allowed, entonces por defecto
     else:
         return super(ResUsers, self).check_credentials(password)
Пример #12
0
 def fetch_mail(self):
     if get_mode():
         raise UserError(
             _("You Can not Fetch Mail Because Odoo is in %s mode.") %
             (get_mode()))
     return super(fetchmail_server, self).fetch_mail()
Пример #13
0
 def button_confirm_login(self):
     if get_mode():
         raise UserError(
             _("You Can not Confirm & Test Because Odoo is in %s mode.") %
             (get_mode()))
     return super(fetchmail_server, self).button_confirm_login()
Пример #14
0
 def _compute_server_mode(self):
     for rec in self:
         rec.server_mode = get_mode()
Пример #15
0
# -*- encoding: utf-8 -*-
##############################################################################
# For copyright and license notices, see __openerp__.py file in module root
# directory
##############################################################################
from . import controllers

from openerp.tools import config
from openerp.addons.server_mode.mode import get_mode

# Disable crons if server mode (not production)
if get_mode():
    config['max_cron_threads'] = 0
Пример #16
0
 def get_mode(self, req, db=False):
     if custom_mode.get_mode():
         return custom_mode.get_mode().upper()
     return False