Ejemplo n.º 1
0
 def test0050uom_compute_price(self):
     '''
     Test uom compute_price function.
     '''
     tests = [
         ('Kilogram', Decimal('100'), 'Gram', Decimal('0.1')),
         ('Gram', Decimal('1'), 'Pound', Decimal('453.59237')),
         ('Second', Decimal('5'), 'Minute', Decimal('300')),
         ('Second', Decimal('25'), 'Hour', Decimal('90000')),
         ('Millimeter', Decimal('3'), 'Inch', Decimal('76.2')),
     ]
     cursor = DB.cursor()
     for from_name, price, to_name, result in tests:
         from_uom = self.uom.browse(
             cursor, USER,
             self.uom.search(cursor,
                             USER, [
                                 ('name', '=', from_name),
                             ],
                             limit=1)[0])
         to_uom = self.uom.browse(
             cursor, USER,
             self.uom.search(cursor,
                             USER, [
                                 ('name', '=', to_name),
                             ],
                             limit=1)[0])
         self.assert_(result == self.uom.compute_price(
             cursor, USER, from_uom, price, to_uom))
     cursor.close()
Ejemplo n.º 2
0
    def test0040rate_unicity(self):
        '''
        Rate unicity
        '''
        cursor = DB.cursor()
        today = self.date.today(cursor, USER, CONTEXT)

        cu_id = self.currency.create(cursor, USER, {
            'name': 'cu',
            'symbol': 'cu',
            'code': 'cu'
            }, CONTEXT)

        rate1_id = self.rate.create(cursor, USER, {
            'rate': Decimal("1.3"),
            'currency': cu_id,
            'date': today,
            }, CONTEXT)

        self.assertRaises(Exception, self.rate.create, cursor, USER, {
                'rate': Decimal("1.3"),
                'currency': cu_id,
                'date': today,
                }, CONTEXT)

        cursor.rollback()
        cursor.close()
Ejemplo n.º 3
0
    def test0030rate(self):
        '''
        Create rates.
        '''
        cursor = DB.cursor()
        cu1_id = self.get_currency(cursor, 'cu1')
        cu2_id = self.get_currency(cursor, 'cu2')

        rate1 = Decimal("1.3")
        rate1_id = self.rate.create(cursor, USER, {
            'rate': rate1,
            'currency': cu1_id,
            }, CONTEXT)
        self.assert_(rate1_id)

        rate2_id = self.rate.create(cursor, USER, {
            'rate': Decimal("1"),
            'currency': cu2_id,
            }, CONTEXT)
        self.assert_(rate2_id)

        self.assertEqual(rate1, self.currency.read(cursor, USER,
                cu1_id, ['rate'], CONTEXT)['rate'])

        cursor.commit()
        cursor.close()
Ejemplo n.º 4
0
    def test0080compute_same(self):
        '''
        Conversion to the same currency
        '''
        cursor = DB.cursor()
        cu1_id = self.get_currency(cursor, 'cu1')

        amount = Decimal("10")
        converted_amount = self.currency.compute(cursor, USER,
                cu1_id, amount, cu1_id, True, CONTEXT)
        self.assert_(converted_amount == amount)

        cursor.close()
Ejemplo n.º 5
0
    def test0060compute_nonfinite(self):
        '''
        Conversion with rounding on non-finite decimal representation
        '''
        cursor = DB.cursor()
        cu1_id = self.get_currency(cursor, 'cu1')
        cu2_id = self.get_currency(cursor, 'cu2')

        amount = Decimal("10")
        expected = Decimal("7.69")
        converted_amount = self.currency.compute(cursor, USER,
                cu1_id, amount, cu2_id, True, CONTEXT)
        self.assert_(converted_amount == expected)

        cursor.close()
Ejemplo n.º 6
0
    def test0070compute_nonfinite_worounding(self):
        '''
        Same without rounding
        '''
        cursor = DB.cursor()
        cu1_id = self.get_currency(cursor, 'cu1')
        cu2_id = self.get_currency(cursor, 'cu2')

        amount = Decimal("10")
        expected = Decimal('7.692307692307692307692307692')
        converted_amount = self.currency.compute(cursor, USER,
                cu1_id, amount, cu2_id, False, CONTEXT)
        self.assert_(converted_amount == expected)

        cursor.close()
Ejemplo n.º 7
0
    def test0090compute_zeroamount(self):
        '''
        Conversion with zero amount
        '''
        cursor = DB.cursor()
        cu1_id = self.get_currency(cursor, 'cu1')
        cu2_id = self.get_currency(cursor, 'cu2')

        amount = Decimal("10")
        expected = Decimal("0")
        converted_amount = self.currency.compute(cursor, USER,
                cu1_id, Decimal("0"), cu2_id, True, CONTEXT)
        self.assert_(converted_amount == expected)

        cursor.close()
Ejemplo n.º 8
0
    def test0010uom_non_zero_rate_factor(self):
        '''
        Test uom non_zero_rate_factor constraint.
        '''
        cursor = DB.cursor()

        category_id = self.uom_category.create(cursor, USER, {
            'name': 'Test',
        })
        cursor.commit()

        self.failUnlessRaises(
            Exception, self.uom.create, cursor, USER, {
                'name': 'Test',
                'symbol': 'T',
                'category': category_id,
                'rate': 0,
                'factor': 0,
            })
        cursor.rollback()

        uom_id = self.uom.create(
            cursor, USER, {
                'name': 'Test',
                'symbol': 'T',
                'category': category_id,
                'rate': 1.0,
                'factor': 1.0,
            })
        cursor.commit()

        self.failUnlessRaises(Exception, self.uom.write, cursor, USER, {
            'rate': 0.0,
        })
        cursor.rollback()

        self.failUnlessRaises(Exception, self.uom.write, cursor, USER, {
            'factor': 0.0,
        })
        cursor.rollback()

        self.failUnlessRaises(Exception, self.uom.write, cursor, USER, {
            'rate': 0.0,
            'factor': 0.0,
        })
        cursor.rollback()

        cursor.close()
Ejemplo n.º 9
0
    def test0050compute_simple(self):
        '''
        Simple conversion
        '''
        cursor = DB.cursor()
        cu1_id = self.get_currency(cursor, 'cu1')
        cu2_id = self.get_currency(cursor, 'cu2')

        amount = Decimal("10")
        expected = Decimal("13")
        converted_amount = self.currency.compute(cursor, USER,
                cu2_id, amount, cu1_id, True, CONTEXT)
        self.assertEqual(converted_amount, expected)

        cursor.commit()
        cursor.close()
Ejemplo n.º 10
0
    def test0130delete_cascade(self):
        '''
        Test deletion of currency deletes rates
        '''
        cursor = DB.cursor()
        codes = ['cu%s' % (i + 1) for i in range(2)]
        currency_ids = [self.get_currency(cursor, i) for i in codes]
        self.currency.delete(cursor, USER, currency_ids, CONTEXT)

        rate_ids = self.rate.search(cursor, USER, [(
                'currency', 'in', currency_ids,
                )], 0, None, None, CONTEXT)
        self.assertFalse(rate_ids)

        cursor.rollback()
        cursor.close()
Ejemplo n.º 11
0
    def test0040uom_compute_qty(self):
        '''
        Test uom compute_qty function.
        '''
        tests = [
            ('Kilogram', 100, 'Gram', 100000, 100000),
            ('Gram', 1, 'Pound', 0.0022046226218487759, 0.0),
            ('Second', 5, 'Minute', 0.083333333333333343, 0.08),
            ('Second', 25, 'Hour', 0.0069444444444444441, 0.01),
            ('Millimeter', 3, 'Inch', 0.11811023622047245, 0.12),
        ]
        cursor = DB.cursor()
        for from_name, qty, to_name, result, rounded_result in tests:
            from_uom = self.uom.browse(
                cursor, USER,
                self.uom.search(cursor,
                                USER, [
                                    ('name', '=', from_name),
                                ],
                                limit=1)[0])
            to_uom = self.uom.browse(
                cursor, USER,
                self.uom.search(cursor,
                                USER, [
                                    ('name', '=', to_name),
                                ],
                                limit=1)[0])
            self.assert_(result == self.uom.compute_qty(
                cursor, USER, from_uom, qty, to_uom, False))
            self.assert_(rounded_result == self.uom.compute_qty(
                cursor, USER, from_uom, qty, to_uom, True))

        self.assert_(
            10 == self.uom.compute_qty(cursor, USER, None, 10, to_uom))
        self.assert_(
            10 == self.uom.compute_qty(cursor, USER, None, 10, to_uom, True))
        self.assert_(
            0 == self.uom.compute_qty(cursor, USER, from_uom, 0, to_uom))
        self.assert_(
            0 == self.uom.compute_qty(cursor, USER, from_uom, 0, to_uom, True))
        self.assert_(
            10 == self.uom.compute_qty(cursor, USER, from_uom, 10, None))
        self.assert_(
            10 == self.uom.compute_qty(cursor, USER, from_uom, 10, None, True))

        cursor.close()
Ejemplo n.º 12
0
    def test0010uom_non_zero_rate_factor(self):
        '''
        Test uom non_zero_rate_factor constraint.
        '''
        cursor = DB.cursor()

        category_id = self.uom_category.create(cursor, USER, {
            'name': 'Test',
            })
        cursor.commit()

        self.failUnlessRaises(Exception, self.uom.create, cursor, USER, {
            'name': 'Test',
            'symbol': 'T',
            'category': category_id,
            'rate': 0,
            'factor': 0,
            })
        cursor.rollback()

        uom_id = self.uom.create(cursor, USER, {
            'name': 'Test',
            'symbol': 'T',
            'category': category_id,
            'rate': 1.0,
            'factor': 1.0,
            })
        cursor.commit()

        self.failUnlessRaises(Exception, self.uom.write, cursor, USER, {
            'rate': 0.0,
            })
        cursor.rollback()

        self.failUnlessRaises(Exception, self.uom.write, cursor, USER, {
            'factor': 0.0,
            })
        cursor.rollback()

        self.failUnlessRaises(Exception, self.uom.write, cursor, USER, {
            'rate': 0.0,
            'factor': 0.0,
            })
        cursor.rollback()

        cursor.close()
Ejemplo n.º 13
0
    def test0030uom_select_accurate_field(self):
        '''
        Test uom select_accurate_field function.
        '''
        tests = [
            ('Meter', 'factor'),
            ('Kilometer', 'factor'),
            ('centimeter', 'rate'),
            ('Foot', 'factor'),
        ]
        cursor = DB.cursor()
        for name, result in tests:
            uom_id = self.uom.search(cursor, USER, [
                ('name', '=', name),
                ], limit=1)[0]
            uom = self.uom.browse(cursor, USER, uom_id)
            self.assert_(result == self.uom.select_accurate_field(uom))

        cursor.close()
Ejemplo n.º 14
0
    def test0020mon_grouping(self):
        '''
        Check grouping
        '''
        cursor = DB.cursor()
        cu1_id = self.get_currency(cursor, 'cu1')

        self.assertRaises(Exception, self.currency.write, cursor, USER,
                cu1_id, {'mon_grouping': ''}, CONTEXT)

        self.assertRaises(Exception, self.currency.write, cursor, USER,
                cu1_id, {'mon_grouping': '[a]'}, CONTEXT)

        self.assertRaises(Exception, self.currency.write, cursor, USER,
                cu1_id, {'mon_grouping': '[1,"a"]'}, CONTEXT)

        self.assertRaises(Exception, self.currency.write, cursor, USER,
                cu1_id, {'mon_grouping': '[1,"1"]'}, CONTEXT)

        cursor.close()
Ejemplo n.º 15
0
    def test0110compute_missingrate(self):
        '''
        Conversion with missing rate
        '''
        cursor = DB.cursor()
        cu1_id = self.get_currency(cursor, 'cu1')
        cu3_id = self.currency.create(cursor, USER, {
            'name': 'cu3',
            'symbol': 'cu3',
            'code': 'cu3'
            }, CONTEXT)

        amount = Decimal("10")
        self.assertRaises(Exception, self.currency.compute, cursor, USER,
                cu3_id, amount, cu1_id, True, CONTEXT)
        self.assertRaises(Exception, self.currency.compute, cursor, USER,
                cu1_id, amount, cu3_id, True, CONTEXT)

        cursor.rollback()
        cursor.close()
Ejemplo n.º 16
0
    def test0020uom_check_factor_and_rate(self):
        '''
        Test uom check_factor_and_rate constraint.
        '''
        cursor = DB.cursor()

        category_id = self.uom_category.search(cursor,
                                               USER, [
                                                   ('name', '=', 'Test'),
                                               ],
                                               limit=1)[0]

        self.failUnlessRaises(
            Exception, self.uom.create, cursor, USER, {
                'name': 'Test',
                'symbol': 'T',
                'category': category_id,
                'rate': 2,
                'factor': 2,
            })
        cursor.rollback()

        uom_id = self.uom.search(cursor,
                                 USER, [
                                     ('name', '=', 'Test'),
                                 ],
                                 limit=1)[0]

        self.failUnlessRaises(Exception, self.uom.write, cursor, USER, uom_id,
                              {
                                  'rate': 2.0,
                              })
        cursor.rollback()

        self.failUnlessRaises(Exception, self.uom.write, cursor, USER, uom_id,
                              {
                                  'factor': 2.0,
                              })
        cursor.rollback()

        cursor.close()
Ejemplo n.º 17
0
    def test0030uom_select_accurate_field(self):
        '''
        Test uom select_accurate_field function.
        '''
        tests = [
            ('Meter', 'factor'),
            ('Kilometer', 'factor'),
            ('centimeter', 'rate'),
            ('Foot', 'factor'),
        ]
        cursor = DB.cursor()
        for name, result in tests:
            uom_id = self.uom.search(cursor,
                                     USER, [
                                         ('name', '=', name),
                                     ],
                                     limit=1)[0]
            uom = self.uom.browse(cursor, USER, uom_id)
            self.assert_(result == self.uom.select_accurate_field(uom))

        cursor.close()
Ejemplo n.º 18
0
    def test0040uom_compute_qty(self):
        '''
        Test uom compute_qty function.
        '''
        tests = [
            ('Kilogram', 100, 'Gram', 100000, 100000),
            ('Gram', 1, 'Pound', 0.0022046226218487759, 0.0),
            ('Second', 5, 'Minute', 0.083333333333333343, 0.08),
            ('Second', 25, 'Hour', 0.0069444444444444441, 0.01),
            ('Millimeter', 3, 'Inch', 0.11811023622047245, 0.12),
        ]
        cursor = DB.cursor()
        for from_name, qty, to_name, result, rounded_result in tests:
            from_uom = self.uom.browse(cursor, USER, self.uom.search(cursor,
                USER, [
                    ('name', '=', from_name),
                ], limit=1)[0])
            to_uom = self.uom.browse(cursor, USER, self.uom.search(cursor,
                USER, [
                    ('name', '=', to_name),
                ], limit=1)[0])
            self.assert_(result == self.uom.compute_qty(cursor, USER, from_uom,
                qty, to_uom, False))
            self.assert_(rounded_result == self.uom.compute_qty(cursor, USER,
                from_uom, qty, to_uom, True))

        self.assert_(10 == self.uom.compute_qty(cursor, USER,
            None, 10, to_uom))
        self.assert_(10 == self.uom.compute_qty(cursor, USER,
            None, 10, to_uom, True))
        self.assert_(0 == self.uom.compute_qty(cursor, USER,
            from_uom, 0, to_uom))
        self.assert_(0 == self.uom.compute_qty(cursor, USER,
            from_uom, 0, to_uom, True))
        self.assert_(10 == self.uom.compute_qty(cursor, USER,
            from_uom, 10, None))
        self.assert_(10 == self.uom.compute_qty(cursor, USER,
            from_uom, 10, None, True))

        cursor.close()
Ejemplo n.º 19
0
    def test0010currencies(self):
        '''
        Create currencies
        '''
        cursor = DB.cursor()

        cu1_id = self.currency.create(cursor, USER, {
            'name': 'cu1',
            'symbol': 'cu1',
            'code': 'cu1'
            }, CONTEXT)
        self.assert_(cu1_id)

        cu2_id = self.currency.create(cursor, USER, {
            'name': 'cu2',
            'symbol': 'cu2',
            'code': 'cu2'
            }, CONTEXT)
        self.assert_(cu2_id)

        cursor.commit()
        cursor.close()
Ejemplo n.º 20
0
    def test0100compute_zerorate(self):
        '''
        Conversion with zero rate
        '''
        cursor = DB.cursor()
        cu1_id = self.get_currency(cursor, 'cu1')
        cu2_id = self.get_currency(cursor, 'cu2')

        rate_ids = self.rate.search(cursor, USER, [
                ('currency', '=', cu1_id),
                ], 0, 1, None, CONTEXT)
        self.rate.write(cursor, USER, rate_ids, {
                'rate': Decimal("0"),
                }, CONTEXT)
        amount = Decimal("10")
        self.assertRaises(Exception, self.currency.compute,
                cu1_id, amount, cu2_id, True, CONTEXT)
        self.assertRaises(Exception, self.currency.compute,
                cu2_id, amount, cu1_id, True, CONTEXT)

        cursor.rollback()
        cursor.close()
Ejemplo n.º 21
0
 def test0050uom_compute_price(self):
     '''
     Test uom compute_price function.
     '''
     tests = [
         ('Kilogram', Decimal('100'), 'Gram', Decimal('0.1')),
         ('Gram', Decimal('1'), 'Pound', Decimal('453.59237')),
         ('Second', Decimal('5'), 'Minute', Decimal('300')),
         ('Second', Decimal('25'), 'Hour', Decimal('90000')),
         ('Millimeter', Decimal('3'), 'Inch', Decimal('76.2')),
     ]
     cursor = DB.cursor()
     for from_name, price, to_name, result in tests:
         from_uom = self.uom.browse(cursor, USER, self.uom.search(cursor,
             USER, [
                 ('name', '=', from_name),
             ], limit=1)[0])
         to_uom = self.uom.browse(cursor, USER, self.uom.search(cursor,
             USER, [
                 ('name', '=', to_name),
             ], limit=1)[0])
         self.assert_(result == self.uom.compute_price(cursor, USER,
             from_uom, price, to_uom))
     cursor.close()
Ejemplo n.º 22
0
    def test0020uom_check_factor_and_rate(self):
        '''
        Test uom check_factor_and_rate constraint.
        '''
        cursor = DB.cursor()

        category_id = self.uom_category.search(cursor, USER, [
            ('name', '=', 'Test'),
            ], limit=1)[0]

        self.failUnlessRaises(Exception, self.uom.create, cursor, USER, {
            'name': 'Test',
            'symbol': 'T',
            'category': category_id,
            'rate': 2,
            'factor': 2,
            })
        cursor.rollback()

        uom_id = self.uom.search(cursor, USER, [
            ('name', '=', 'Test'),
            ], limit=1)[0]

        self.failUnlessRaises(Exception, self.uom.write, cursor, USER, uom_id,
                {
                    'rate': 2.0,
                    })
        cursor.rollback()

        self.failUnlessRaises(Exception, self.uom.write, cursor, USER, uom_id,
                {
                    'factor': 2.0,
                    })
        cursor.rollback()

        cursor.close()