Exemple #1
0
    def ir_set(self, cr, uid, key, key2, name, models, value, replace=True, isobject=False, meta=None, xml_id=False):
        obj = self.pool.get('ir.values')
        if type(models[0])==type([]) or type(models[0])==type(()):
            model,res_id = models[0]
        else:
            res_id=None
            model = models[0]

        clause = "model=%s AND key=%s AND name=%s"
        params = (model, key, name)
        if res_id:
            clause += ' AND res_id=%s'
            params += (res_id,)
        else:
            clause += ' AND (res_id IS NULL)'

        if key2:
            clause += ' AND key2=%s'
            params += (key2,)
        else:
            clause += ' AND (key2 IS NULL)'

        cr.execute('SELECT 1 FROM ir_values WHERE ' + clause, params)
        res = cr.fetchone()
        if not res:
            ir.ir_set(cr, uid, key, key2, name, models, value, replace, isobject, meta)
        elif xml_id:
            cr.execute('UPDATE ir_values SET value=%s WHERE ' + clause, (value,) + params)
        return True
 def _crea_cpostal(self, cr, uid, data, context):
     from comarca_cpostal import cod_postales
     pool = pooler.get_pool(cr.dbname)
     for m in cod_postales:
         ids = pool.get('res.country.state.comarca').search(cr, uid, [('name', '=', m[1])])
         if ids:
             ir.ir_set(cr, uid, 'default', 'zip='+m[0], 'comarca', [('res.partner.address', False)], ids[0])
     return {}
Exemple #3
0
 def _crea_cpostal(self, cr, uid, data, context):
     from comarca_cpostal import cod_postales
     pool = pooler.get_pool(cr.dbname)
     for m in cod_postales:
         ids = pool.get('res.country.state.comarca').search(cr, uid, [('name', '=', m[1])])
         if ids:
             ir.ir_set(cr, uid, 'default', 'zip='+m[0], 'comarca', [('res.partner.address', False)], ids[0])
     return {}
 def _crea_cpostal(self, cr, uid, data, context):
     from cpostal import cod_postales
     pool = pooler.get_pool(cr.dbname)
     for m in cod_postales:
         codi = m[0][:-3] #2 primeros dígitos del cp
         ids = pool.get('res.country.cautonoma').search(cr, uid, [('code', '=', com_auto[codi])])
         if ids:
             ir.ir_set(cr, uid, 'default', 'zip='+m[0], 'cautonoma', [('res.partner.address', False)], ids[0])
     return {}
Exemple #5
0
 def create_values(self, cr, uid, id, context=None):
     doc = self.browse(cr, uid, id, context=context)
     if not self.action_values(cr, uid, doc.report_id.id, context=context):
         value = 'ir.actions.report.xml,%d' % doc.report_id.id
         ir.ir_set(cr,
                   uid,
                   'action',
                   'client_print_multi',
                   doc.name, [doc.model_id.model],
                   value,
                   replace=False,
                   isobject=True)
     return True
    def do_action(self, cr, uid, ids, context=None):
        """ This Function Open added Action.
         @param self: The object pointer.
         @param cr: A database cursor
         @param uid: ID of the user currently logged in
         @param ids: List of report.webkit.actions's ID
         @param context: A standard dictionary 
         @return: Dictionary of ir.values form.
        """
        if context is None:
            context = {}
        report_obj = self.pool.get("ir.actions.report.xml")
        for current in self.browse(cr, uid, ids, context=context):
            report = report_obj.browse(cr, uid, context.get("active_id"), context=context)
            if current.print_button:
                res = ir.ir_set(
                    cr,
                    uid,
                    "action",
                    "client_print_multi",
                    report.report_name,
                    [report.model],
                    "ir.actions.report.xml,%d" % context.get("active_id", False),
                    isobject=True,
                )
            else:
                res = ir.ir_set(
                    cr,
                    uid,
                    "action",
                    "client_print_multi",
                    report.report_name,
                    [report.model, 0],
                    "ir.actions.report.xml,%d" % context.get("active_id", False),
                    isobject=True,
                )
            if res[0]:
                if not current.open_action:
                    return {"type": "ir.actions.act_window_close"}

                return {
                    "name": _("Client Actions Connections"),
                    "view_type": "form",
                    "view_mode": "form",
                    "res_id": res[0],
                    "res_model": "ir.values",
                    "view_id": False,
                    "type": "ir.actions.act_window",
                }
    def do_action(self, cr, uid, ids, context=None):
        """ This Function Open added Action.
         @param self: The object pointer.
         @param cr: A database cursor
         @param uid: ID of the user currently logged in
         @param ids: List of report.webkit.actions's ID
         @param context: A standard dictionary 
         @return: Dictionary of ir.values form.
        """
        if context is None:
            context = {}
        report_obj = self.pool.get('ir.actions.report.xml')
        for current in self.browse(cr, uid, ids, context=context):
            report = report_obj.browse(cr,
                                       uid,
                                       context.get('active_id'),
                                       context=context)
            if current.print_button:
                res = ir.ir_set(cr,
                                uid,
                                'action',
                                'client_print_multi',
                                report.report_name, [report.model],
                                'ir.actions.report.xml,%d' %
                                context.get('active_id', False),
                                isobject=True)
            else:
                res = ir.ir_set(cr,
                                uid,
                                'action',
                                'client_print_multi',
                                report.report_name, [report.model, 0],
                                'ir.actions.report.xml,%d' %
                                context.get('active_id', False),
                                isobject=True)
            if res[0]:
                if not current.open_action:
                    return {'type': 'ir.actions.act_window_close'}

                return {
                    'name': _('Client Actions Connections'),
                    'view_type': 'form',
                    'view_mode': 'form',
                    'res_id': res[0],
                    'res_model': 'ir.values',
                    'view_id': False,
                    'type': 'ir.actions.act_window',
                }
Exemple #8
0
    def make_action(self, cr, uid, id, context=None):
        """
        Create an entry in ir_actions_report_xml
        and ir.values
        """
        b = self.browse(cr, uid, id, context=context)
        act_report_obj = self.pool.get('ir.actions.report.xml')

        doc = self.browse(cr, uid, id, context=context)
        if doc.report_id:
            _logger.info('Update "%s" service' % doc.name)
            args = {
                'name': doc.name,
                'report_name': 'jasper.' + doc.service,
                'model': doc.model_id.model,
                'groups_id': [(6, 0, [x.id for x in doc.group_ids])],
                'header': False,
                'multi': doc.toolbar,
            }
            act_report_obj.write(cr,
                                 uid, [doc.report_id.id],
                                 args,
                                 context=context)
        else:
            _logger.info('Create "%s" service' % doc.name)
            args = {
                'name': doc.name,
                'report_name': 'jasper.' + doc.service,
                'model': doc.model_id.model,
                'report_type': 'jasper',
                'groups_id': [(6, 0, [x.id for x in doc.group_ids])],
                'header': False,
                'multi': doc.toolbar,
            }
            report_id = act_report_obj.create(cr, uid, args, context=context)
            cr.execute(
                """UPDATE jasper_document SET report_id=%s WHERE id=%s""",
                (report_id, id))
            value = 'ir.actions.report.xml,' + str(report_id)
            ir.ir_set(cr,
                      uid,
                      'action',
                      'client_print_multi',
                      doc.name, [doc.model_id.model],
                      value,
                      replace=False,
                      isobject=True)
        registered_report('jasper.' + doc.service)
Exemple #9
0
    def ir_set(self, cr, uid, key, key2, name, models, value, replace=True, isobject=False, meta=None, xml_id=False):
        if type(models[0]) == type([]) or type(models[0]) == type(()):
            model, res_id = models[0]
        else:
            res_id = None
            model = models[0]

        if res_id:
            where = " and res_id=%s" % (res_id,)
        else:
            where = " and (res_id is null)"

        if key2:
            where += " and key2='%s'" % (key2,)
        else:
            where += " and (key2 is null)"

        cr.execute("select * from ir_values where model=%s and key=%s and name=%s" + where, (model, key, name))
        res = cr.fetchone()
        if not res:
            res = ir.ir_set(cr, uid, key, key2, name, models, value, replace, isobject, meta)
        elif xml_id:
            cr.execute(
                "UPDATE ir_values set value=%s WHERE model=%s and key=%s and name=%s" + where, (value, model, key, name)
            )
        return True
Exemple #10
0
    def _do_action(self, cr, uid, data, context):
        pool = pooler.get_pool(cr.dbname)
        report = pool.get(data['model']).browse(cr, uid, data['id'], context=context)
        #if data['form']['print_button']:
        res = ir.ir_set(cr, uid, 'action', 'client_print_multi', report.report_name, [report.model], 'ir.actions.report.xml,%d' % data['id'], isobject=True)
        #else:
	    #    res = ir.ir_set(cr, uid, 'action', 'client_print_multi', report.report_name, [report.model,0], 'ir.actions.report.xml,%d' % data['id'], isobject=True)
        return {'value_id':res[0]}
Exemple #11
0
    def make_action(self, cr, uid, id, context=None):
        """
        Create an entry in ir_actions_report_xml
        and ir.values
        """
        b = self.browse(cr, uid, id, context=context)
        act_report_obj = self.pool.get('ir.actions.report.xml')

        doc = self.browse(cr, uid, id, context=context)
        if doc.report_id:
            _logger.info('Update "%s" service' % doc.name)
            args = {
                'name': doc.name,
                'report_name': 'jasper.' + doc.service,
                'model': doc.model_id.model,
                'groups_id': [(6, 0, [x.id for x in doc.group_ids])],
                'header': False,
                'multi': doc.toolbar,
            }
            act_report_obj.write(cr, uid, [doc.report_id.id], args, context=context)
        else:
            _logger.info('Create "%s" service' % doc.name)
            args = {
                'name': doc.name,
                'report_name': 'jasper.' + doc.service,
                'model': doc.model_id.model,
                'report_type': 'jasper',
                'groups_id': [(6, 0, [x.id for x in doc.group_ids])],
                'header': False,
                'multi': doc.toolbar,
            }
            report_id = act_report_obj.create(cr, uid, args, context=context)
            cr.execute("""UPDATE jasper_document SET report_id=%s WHERE id=%s""", (report_id, id))
            value = 'ir.actions.report.xml,' + str(report_id)
            ir.ir_set(cr, uid, 'action', 'client_print_multi', doc.name, [doc.model_id.model], value, replace=False, isobject=True)
        registered_report('jasper.' + doc.service)
Exemple #12
0
    def ir_set(self,
               cr,
               uid,
               key,
               key2,
               name,
               models,
               value,
               replace=True,
               isobject=False,
               meta=None,
               xml_id=False):
        obj = self.pool.get('ir.values')
        if type(models[0]) == type([]) or type(models[0]) == type(()):
            model, res_id = models[0]
        else:
            res_id = None
            model = models[0]

        if res_id:
            where = ' and res_id=%s' % (res_id, )
        else:
            where = ' and (res_id is null)'

        if key2:
            where += ' and key2=\'%s\'' % (key2, )
        else:
            where += ' and (key2 is null)'

        cr.execute(
            'select * from ir_values where model=%s and key=%s and name=%s' +
            where, (model, key, name))
        res = cr.fetchone()
        if not res:
            res = ir.ir_set(cr, uid, key, key2, name, models, value, replace,
                            isobject, meta)
        elif xml_id:
            cr.execute(
                'UPDATE ir_values set value=%s WHERE model=%s and key=%s and name=%s'
                + where, (value, model, key, name))
        return True
Exemple #13
0
 def exp_ir_set(self, cr, uid, keys, args, name, value, replace=True, isobject=False):
     res = ir.ir_set(cr,uid, keys, args, name, value, replace, isobject)
     return res
Exemple #14
0
    def subscribe(self, cr, uid, ids, context={}):
        for report in self.browse(cr, uid, ids):
            report.fields_child0.sort(lambda x,y : x.sequence - y.sequence)
        
            # required on field0 does not seem to work( cause we use o2m_l ?)
            if not report.fields_child0:
                raise osv.except_osv(_('Invalid operation'), _('Enter at least one field !'))
            
            if report.type in ['pie', 'bar', 'line'] and report.field_parent:
                raise osv.except_osv(_('Invalid operation'), _('Tree can only be used in tabular reports'))
            
            # Otherwise it won't build a good tree. See level.pop in custom.py.
            if report.type == 'table' and report.field_parent and report.fields_child0 and not report.fields_child0[0].groupby:
                raise osv.except_osv('Invalid operation :', 'When creating tree (field child) report, data must be group by the first field')

            if report.type == 'pie':
                if len(report.fields_child0) != 2:
                    raise osv.except_osv(_('Invalid operation'), _('Pie charts need exactly two fields'))
                else:
                    c_f = {}
                    for i in range(2):
                        c_f[i] = []
                        tmp = report.fields_child0[i]
                        for j in range(3):
                            c_f[i].append((not isinstance(eval('tmp.field_child'+str(j)), browse_null) and eval('tmp.field_child'+str(j)+'.ttype')) or None)
                    if not reduce(lambda x,y : x or y, map(lambda x: x in ['integer', 'float'], c_f[1])):
                        raise osv.except_osv(_('Invalid operation'), _('Second field should be figures'))
                    
            if report.type == 'bar':
                if len(report.fields_child0) < 2:
                    raise osv.except_osv(_('Invalid operation'), _('Bar charts need at least two fields'))
                else:
                    c_f = {}
                    for i in range(len(report.fields_child0)):
                        c_f[i] = []
                        tmp = report.fields_child0[i]
                        for j in range(3):
                            c_f[i].append((not isinstance(eval('tmp.field_child'+str(j)), browse_null) and eval('tmp.field_child'+str(j)+'.ttype')) or None)

                        if i == 0:
                            pass
                        else:
                            if not reduce(lambda x,y : x or y, map(lambda x: x in ['integer', 'float'], c_f[i])):
                                raise osv.except_osv(_('Invalid operation'), _('Field %d should be a figure') %(i,))

            if report.state=='subscribed':
                continue

            name = report.name
            model = report.model_id.model

            action_def = {'report_id':report.id, 'type':'ir.actions.report.custom', 'model':model, 'name':name}
            id = self.pool.get('ir.actions.report.custom').create(cr, uid, action_def)
            m_id = report.menu_id.id
            action = "ir.actions.report.custom,%d" % (id,)
            if not report.menu_id:
                ir.ir_set(cr, uid, 'action', 'client_print_multi', name, [(model, False)], action, False, True)
            else:
                ir.ir_set(cr, uid, 'action', 'tree_but_open', 'Menuitem', [('ir.ui.menu', int(m_id))], action, False, True)

            self.write(cr, uid, [report.id], {'state':'subscribed'}, context)
        return True
Exemple #15
0
 def create_values(self, cr, uid, id, context=None):
     doc = self.browse(cr, uid, id, context=context)
     if not self.action_values(cr, uid, doc.report_id.id, context=context):
         value = 'ir.actions.report.xml,%d' % doc.report_id.id
         ir.ir_set(cr, uid, 'action', 'client_print_multi', doc.name, [doc.model_id.model], value, replace=False, isobject=True)
     return True
Exemple #16
0
 def exp_ir_set(self, cr, uid, keys, args, name, value, replace=True, isobject=False):
     res = ir.ir_set(cr,uid, keys, args, name, value, replace, isobject)
     return res
Exemple #17
0
    def subscribe(self, cr, uid, ids, context={}):
        for report in self.browse(cr, uid, ids):
            report.fields_child0.sort(lambda x, y: x.sequence - y.sequence)

            # required on field0 does not seem to work( cause we use o2m_l ?)
            if not report.fields_child0:
                raise osv.except_osv(_('Invalid operation'),
                                     _('Enter at least one field !'))

            if report.type in ['pie', 'bar', 'line'] and report.field_parent:
                raise osv.except_osv(
                    _('Invalid operation'),
                    _('Tree can only be used in tabular reports'))

            # Otherwise it won't build a good tree. See level.pop in custom.py.
            if report.type == 'table' and report.field_parent and report.fields_child0 and not report.fields_child0[
                    0].groupby:
                raise osv.except_osv(
                    'Invalid operation :',
                    'When creating tree (field child) report, data must be group by the first field'
                )

            if report.type == 'pie':
                if len(report.fields_child0) != 2:
                    raise osv.except_osv(
                        _('Invalid operation'),
                        _('Pie charts need exactly two fields'))
                else:
                    c_f = {}
                    for i in range(2):
                        c_f[i] = []
                        tmp = report.fields_child0[i]
                        for j in range(3):
                            c_f[i].append((not isinstance(
                                eval('tmp.field_child' + str(j)), browse_null)
                                           and eval('tmp.field_child' +
                                                    str(j) + '.ttype'))
                                          or None)
                    if not reduce(
                            lambda x, y: x or y,
                            map(lambda x: x in ['integer', 'float'], c_f[1])):
                        raise osv.except_osv(
                            _('Invalid operation'),
                            _('Second field should be figures'))

            if report.type == 'bar':
                if len(report.fields_child0) < 2:
                    raise osv.except_osv(
                        _('Invalid operation'),
                        _('Bar charts need at least two fields'))
                else:
                    c_f = {}
                    for i in range(len(report.fields_child0)):
                        c_f[i] = []
                        tmp = report.fields_child0[i]
                        for j in range(3):
                            c_f[i].append((not isinstance(
                                eval('tmp.field_child' + str(j)), browse_null)
                                           and eval('tmp.field_child' +
                                                    str(j) + '.ttype'))
                                          or None)

                        if i == 0:
                            pass
                        else:
                            if not reduce(
                                    lambda x, y: x or y,
                                    map(lambda x: x in ['integer', 'float'],
                                        c_f[i])):
                                raise osv.except_osv(
                                    _('Invalid operation'),
                                    _('Field %d should be a figure') % (i, ))

            if report.state == 'subscribed':
                continue

            name = report.name
            model = report.model_id.model

            action_def = {
                'report_id': report.id,
                'type': 'ir.actions.report.custom',
                'model': model,
                'name': name
            }
            id = self.pool.get('ir.actions.report.custom').create(
                cr, uid, action_def)
            m_id = report.menu_id.id
            action = "ir.actions.report.custom,%d" % (id, )
            if not report.menu_id:
                ir.ir_set(cr, uid, 'action', 'client_print_multi', name,
                          [(model, False)], action, False, True)
            else:
                ir.ir_set(cr, uid, 'action', 'tree_but_open', 'Menuitem',
                          [('ir.ui.menu', int(m_id))], action, False, True)

            self.write(cr, uid, [report.id], {'state': 'subscribed'}, context)
        return True