Example #1
0
def _convert_action(action, data=None, context=None, config=None):
    if config is None:
        config = proteus.config.get_config()
    if data is None:
        data = {}
    else:
        data = data.copy()

    if 'type' not in (action or {}):
        return None

    data['action_id'] = action['id']
    if action['type'] == 'ir.action.act_window':
        from .pyson import PYSONDecoder

        action.setdefault('pyson_domain', '[]')
        ctx = {
            'active_model': data.get('model'),
            'active_id': data.get('id'),
            'active_ids': data.get('ids', []),
        }
        ctx.update(config.context)
        ctx['_user'] = config.user
        decoder = PYSONDecoder(ctx)
        action_ctx = decoder.decode(action.get('pyson_context') or '{}')
        ctx.update(action_ctx)
        ctx.update(context)
        action_ctx.update(context)
        if 'date_format' not in action_ctx:
            action_ctx['date_format'] = config.context.get(
                'locale', {}).get('date', '%x')

        ctx['context'] = ctx
        decoder = PYSONDecoder(ctx)
        domain = decoder.decode(action['pyson_domain'])

        res_model = action.get('res_model', data.get('res_model'))
        res_id = action.get('res_id', data.get('res_id'))
        Model_ = Model.get(res_model)
        with config.set_context(action_ctx):
            if res_id is None:
                return Model_.find(domain)
            else:
                return [Model_(id_) for id_ in res_id]
    elif action['type'] == 'ir.action.wizard':
        kwargs = {
            'action': action,
            'config': config,
            'context': context,
            }
        if 'model' in data:
            Model_ = Model.get(data['model'])
            kwargs['models'] = [Model_(id_) for id_ in data.get('ids', [])]
        return Wizard(action['wiz_name'], **kwargs)
    elif action['type'] == 'ir.action.report':
        ActionReport = Report(action['report_name'], context=context)
        return ActionReport.execute(data=data)
    elif action['type'] == 'ir.action.url':
        return action.get('url')
Example #2
0
def _convert_action(action, data=None, context=None, config=None):
    if config is None:
        config = proteus.config.get_config()
    if data is None:
        data = {}
    else:
        data = data.copy()

    if 'type' not in (action or {}):
        return None

    data['action_id'] = action['id']
    if action['type'] == 'ir.action.act_window':
        from .pyson import PYSONDecoder

        action.setdefault('pyson_domain', '[]')
        ctx = {
            'active_model': data.get('model'),
            'active_id': data.get('id'),
            'active_ids': data.get('ids', []),
        }
        ctx.update(config.context)
        ctx['_user'] = config.user
        decoder = PYSONDecoder(ctx)
        action_ctx = decoder.decode(action.get('pyson_context') or '{}')
        ctx.update(action_ctx)
        ctx.update(context)
        action_ctx.update(context)
        if 'date_format' not in action_ctx:
            action_ctx['date_format'] = config.context.get(
                'locale', {}).get('date', '%x')

        ctx['context'] = ctx
        decoder = PYSONDecoder(ctx)
        domain = decoder.decode(action['pyson_domain'])

        res_model = action.get('res_model', data.get('res_model'))
        res_id = action.get('res_id', data.get('res_id'))
        Model_ = Model.get(res_model)
        with config.set_context(action_ctx):
            if res_id is None:
                return Model_.find(domain)
            else:
                return [Model_(id_) for id_ in res_id]
    elif action['type'] == 'ir.action.wizard':
        kwargs = {
            'action': action,
            'config': config,
            'context': context,
            }
        if 'model' in data:
            Model_ = Model.get(data['model'])
            kwargs['models'] = [Model_(id_) for id_ in data.get('ids', [])]
        return Wizard(action['wiz_name'], **kwargs)
    elif action['type'] == 'ir.action.report':
        ActionReport = Report(action['report_name'], context=context)
        return ActionReport.execute(data=data)
    elif action['type'] == 'ir.action.url':
        return action.get('url')
Example #3
0
 def find(self, condition=None, offset=0, limit=None, order=None):
     'Returns records matching condition taking into account list domain'
     from .pyson import PYSONDecoder
     decoder = PYSONDecoder(_EvalEnvironment(self.parent))
     Relation = Model.get(self.model_name, self.parent._config)
     if condition is None:
         condition = []
     field_domain = decoder.decode(self.domain)
     add_remove_domain = (decoder.decode(self.add_remove)
         if self.add_remove else [])
     new_domain = [field_domain, add_remove_domain, condition]
     with Relation._config.set_context(self._get_context()):
         return Relation.find(new_domain, offset, limit, order)
Example #4
0
 def find(self, condition=None, offset=0, limit=None, order=None):
     'Returns records matching condition taking into account list domain'
     from .pyson import PYSONDecoder
     decoder = PYSONDecoder(_EvalEnvironment(self.parent))
     Relation = Model.get(self.model_name, self.parent._config)
     if condition is None:
         condition = []
     field_domain = decoder.decode(self.domain)
     add_remove_domain = (decoder.decode(self.add_remove)
         if self.add_remove else [])
     new_domain = [field_domain, add_remove_domain, condition]
     with Relation._config.set_context(self._get_context()):
         return Relation.find(new_domain, offset, limit, order)
Example #5
0
 def __get__(self, instance, owner):
     from .pyson import PYSONDecoder
     relation = Model.get(self.definition['relation'], instance._config)
     value = super(One2ManyDescriptor, self).__get__(instance, owner)
     if not isinstance(value, ModelList):
         ctx = instance._context.copy() if instance._context else {}
         if self.definition.get('context'):
             decoder = PYSONDecoder(_EvalEnvironment(instance))
             ctx.update(decoder.decode(self.definition.get('context')))
         with instance._config.set_context(ctx):
             value = ModelList(self.definition, (relation(id)
                     for id in value or []), instance, self.name)
         instance._values[self.name] = value
     return value
Example #6
0
 def __get__(self, instance, owner):
     from .pyson import PYSONDecoder
     relation = Model.get(self.definition['relation'], instance._config)
     value = super(One2ManyDescriptor, self).__get__(instance, owner)
     if not isinstance(value, ModelList):
         ctx = instance._context.copy() if instance._context else {}
         if self.definition.get('context'):
             decoder = PYSONDecoder(_EvalEnvironment(instance))
             ctx.update(decoder.decode(self.definition.get('context')))
         with instance._config.set_context(ctx):
             value = ModelList(self.definition, (relation(id)
                     for id in value or []), instance, self.name)
         instance._values[self.name] = value
     return value
Example #7
0
 def __get__(self, instance, owner):
     from .pyson import PYSONDecoder
     Relation = Model.get(self.definition['relation'], instance._config)
     value = super(One2ManyDescriptor, self).__get__(instance, owner)
     if not isinstance(value, ModelList):
         ctx = instance._context.copy() if instance._context else {}
         if self.definition.get('context'):
             decoder = PYSONDecoder(_EvalEnvironment(instance))
             ctx.update(decoder.decode(self.definition.get('context')))
         config = Relation._config
         with config.reset_context(), config.set_context(ctx):
             # JCA : Instantiate function O2M, which are read as dicts
             # rather than ids
             value = ModelList(
                 self.definition,
                 (Relation(**id) if isinstance(id, dict) else Relation(id)
                  for id in value or []), instance, self.name)
         instance._values[self.name] = value
     return value
Example #8
0
 def _get_context(self):
     from .pyson import PYSONDecoder
     decoder = PYSONDecoder(_EvalEnvironment(self.parent))
     ctx = self.parent._context.copy() if self.parent._context else {}
     ctx.update(decoder.decode(self.context) if self.context else {})
     return ctx
Example #9
0
 def _get_context(self):
     from .pyson import PYSONDecoder
     decoder = PYSONDecoder(_EvalEnvironment(self.parent))
     ctx = self.parent._context.copy() if self.parent._context else {}
     ctx.update(decoder.decode(self.context) if self.context else {})
     return ctx