Example #1
0
    def test_multiselection_field(self):
        "Test eval multiselection field"
        pool = Pool()
        Model = pool.get('test.modelstorage.eval_environment')

        record = Model(multiselection=['value1', 'value2'])
        env = EvalEnvironment(record, Model)

        self.assertEqual(env.get('multiselection'), ['value1', 'value2'])
Example #2
0
    def test_parent_field(self):
        "Test eval parent field"
        pool = Pool()
        Model = pool.get('test.modelstorage.eval_environment')

        record = Model(many2one=Model(char="Test"))
        env = EvalEnvironment(record, Model)

        self.assertEqual(env.get('_parent_many2one').get('char'), "Test")
Example #3
0
    def test_many2one_field(self):
        "Test eval many2one field"
        pool = Pool()
        Model = pool.get('test.modelstorage.eval_environment')

        record = Model(many2one=Model(id=1))
        env = EvalEnvironment(record, Model)

        self.assertEqual(env.get('many2one'), 1)
Example #4
0
    def test_one2many_field(self):
        "Test eval one2many field"
        pool = Pool()
        Model = pool.get('test.modelstorage.eval_environment')

        record = Model(one2many=[Model(id=1), Model(id=2)])
        env = EvalEnvironment(record, Model)

        self.assertEqual(env.get('one2many'), [1, 2])
Example #5
0
    def test_char_field(self):
        "Test eval simple field"
        pool = Pool()
        Model = pool.get('test.modelstorage.eval_environment')

        record = Model(char="Test")
        env = EvalEnvironment(record, Model)

        self.assertEqual(env.get('char'), "Test")
Example #6
0
    def test_reference_field(self):
        "Test eval reference field"
        pool = Pool()
        Model = pool.get('test.modelstorage.eval_environment')

        record = Model(reference=Model(id=1))
        env = EvalEnvironment(record, Model)

        self.assertEqual(env.get('reference'),
                         'test.modelstorage.eval_environment,1')
Example #7
0
 def _get_context():
     User = Pool().get('res.user')
     user_id = Transaction().user
     with Transaction().set_context(_check_access=False, _datetime=None):
         user = EvalEnvironment(User(user_id), User)
     return {
         'user': user,
     }
Example #8
0
 def eval(self, record, pyson, _env=None):
     'Evaluate the pyson with the record'
     if _env is None:
         env = {}
     else:
         env = _env.copy()
     env['context'] = Transaction().context
     env['self'] = EvalEnvironment(record, record.__class__)
     return PYSONDecoder(env).decode(pyson)
Example #9
0
 def eval(self, record):
     """
     Evaluate the condition of trigger
     """
     env = {}
     env['current_date'] = datetime.datetime.today()
     env['time'] = time
     env['context'] = Transaction().context
     env['self'] = EvalEnvironment(record, record.__class__)
     return bool(PYSONDecoder(env).decode(self.condition))
Example #10
0
 def _get_context():
     User = Pool().get('res.user')
     transaction = Transaction()
     user_id = transaction.user
     with transaction.set_context(_check_access=False, _datetime=None), \
             transaction.set_user(0):
         user = EvalEnvironment(User(user_id), User)
     return {
         'user': user,
         'groups': User.get_groups()
         }
Example #11
0
File: ir.py Project: alljp/company
 def _get_context(cls):
     pool = Pool()
     User = pool.get('res.user')
     Employee = pool.get('company.employee')
     context = super()._get_context()
     # Use root to avoid infinite loop when accessing user attributes
     with Transaction().set_user(0):
         user = User(Transaction().user)
     if user.employee:
         with Transaction().set_context(_check_access=False,
                                        _datetime=None):
             context['employee'] = EvalEnvironment(
                 Employee(user.employee.id), Employee)
     return context
Example #12
0
 def _get_context(cls):
     pool = Pool()
     User = pool.get('res.user')
     Employee = pool.get('company.employee')
     context = super()._get_context()
     # Use root to avoid infinite loop when accessing user attributes
     user_id = Transaction().user
     with Transaction().set_user(0):
         user = User(user_id)
     if user.employee:
         with Transaction().set_context(_check_access=False,
                                        _datetime=None):
             context['employee'] = EvalEnvironment(
                 Employee(user.employee.id), Employee)
     if user.company_filter == 'one':
         context['companies'] = [user.company.id] if user.company else []
         context['employees'] = [user.employee.id] if user.employee else []
     elif user.company_filter == 'all':
         context['companies'] = [c.id for c in user.companies]
         context['employees'] = [e.id for e in user.employees]
     else:
         context['companies'] = []
         context['employees'] = []
     return context
Example #13
0
 def eval(self, record, pyson):
     'Evaluate the pyson with the record'
     env = {}
     env['context'] = Transaction().context
     env['self'] = EvalEnvironment(record, record.__class__)
     return PYSONDecoder(env).decode(pyson)