asset: produkt, einheit + test
This commit is contained in:
parent
0d8ef5081e
commit
13007f30c8
9 changed files with 253 additions and 1 deletions
24
tests/__init__.py
Normal file
24
tests/__init__.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
|
||||
import trytond.tests.test_tryton
|
||||
import unittest
|
||||
|
||||
from trytond.modules.investment.tests.test_asset import AssetTestCase
|
||||
|
||||
|
||||
__all__ = ['suite']
|
||||
|
||||
|
||||
class InvestmentTestCase(\
|
||||
AssetTestCase,\
|
||||
):
|
||||
'Test investment module'
|
||||
module = 'investment'
|
||||
|
||||
# end InvestmentTestCase
|
||||
|
||||
def suite():
|
||||
suite = trytond.tests.test_tryton.suite()
|
||||
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(InvestmentTestCase))
|
||||
return suite
|
117
tests/test_asset.py
Normal file
117
tests/test_asset.py
Normal file
|
@ -0,0 +1,117 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# This file is part of the cashbook-module from m-ds for Tryton.
|
||||
# The COPYRIGHT file at the top level of this repository contains the
|
||||
# full copyright notices and license terms.
|
||||
|
||||
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
|
||||
from trytond.pool import Pool
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.exceptions import UserError
|
||||
from trytond.modules.company.tests import create_company
|
||||
from datetime import date
|
||||
from decimal import Decimal
|
||||
|
||||
|
||||
class AssetTestCase(ModuleTestCase):
|
||||
'Test asset module'
|
||||
module = 'investment'
|
||||
|
||||
def prep_asset_company(self):
|
||||
""" get/create company
|
||||
"""
|
||||
Company = Pool().get('company.company')
|
||||
|
||||
company = Company.search([])
|
||||
if len(company) > 0:
|
||||
company = company[0]
|
||||
else :
|
||||
company = create_company(name='m-ds')
|
||||
return company
|
||||
|
||||
def prep_asset_product(self, name='Product 1', description=None, unit='u', unit_name='Units'):
|
||||
""" create product
|
||||
"""
|
||||
pool = Pool()
|
||||
Product = pool.get('product.template')
|
||||
Uom = pool.get('product.uom')
|
||||
|
||||
uom, = Uom.search([('symbol', '=', unit)])
|
||||
prod_templ, = Product.create([{
|
||||
'name': name,
|
||||
'type': 'assets',
|
||||
'list_price': Decimal('1.0'),
|
||||
'default_uom': uom.id,
|
||||
'products': [('create', [{
|
||||
'description': description,
|
||||
}])],
|
||||
}])
|
||||
self.assertEqual(prod_templ.default_uom.symbol, unit)
|
||||
self.assertEqual(prod_templ.products[0].description, description)
|
||||
return prod_templ.products[0]
|
||||
|
||||
def prep_asset_item(self, company, product):
|
||||
""" create asset
|
||||
"""
|
||||
pool = Pool()
|
||||
Asset = pool.get('investment.asset')
|
||||
|
||||
asset, = Asset.create([{
|
||||
'company': company.id,
|
||||
'product': product.id,
|
||||
'currency': company.currency.id,
|
||||
'currency_digits': 4,
|
||||
'uom': product.default_uom.id,
|
||||
}])
|
||||
self.assertEqual(asset.rec_name, product.name)
|
||||
self.assertEqual(asset.currency.rec_name, 'usd')
|
||||
self.assertEqual(asset.currency_digits, 4)
|
||||
self.assertEqual(asset.product.rec_name, product.name)
|
||||
self.assertEqual(asset.uom.symbol, product.default_uom.symbol)
|
||||
return asset
|
||||
|
||||
@with_transaction()
|
||||
def test_asset_create(self):
|
||||
""" create asset
|
||||
"""
|
||||
company = self.prep_asset_company()
|
||||
product = self.prep_asset_product(
|
||||
name='Product 1',
|
||||
description='some asset')
|
||||
|
||||
asset = self.prep_asset_item(
|
||||
company=company,
|
||||
product = product)
|
||||
|
||||
@with_transaction()
|
||||
def test_asset_check_product_update(self):
|
||||
""" create asset
|
||||
"""
|
||||
company = self.prep_asset_company()
|
||||
product1 = self.prep_asset_product(
|
||||
name='Product unit', unit='u')
|
||||
product2 = self.prep_asset_product(
|
||||
name='Product gram', unit='g')
|
||||
self.assertEqual(product2.default_uom.digits, 2)
|
||||
|
||||
asset = self.prep_asset_item(
|
||||
company=company,
|
||||
product = product1)
|
||||
|
||||
self.assertEqual(asset.product.rec_name, 'Product unit')
|
||||
self.assertEqual(asset.product.default_uom.rec_name, 'Unit')
|
||||
self.assertEqual(asset.uom.rec_name, 'Unit')
|
||||
self.assertEqual(asset.currency_digits, 4)
|
||||
|
||||
asset.product = product2
|
||||
asset.on_change_product()
|
||||
asset.save()
|
||||
|
||||
self.assertEqual(asset.product.rec_name, 'Product gram')
|
||||
self.assertEqual(asset.product.default_uom.rec_name, 'Gram')
|
||||
self.assertEqual(asset.uom.rec_name, 'Gram')
|
||||
|
||||
asset.on_change_currency()
|
||||
asset.save()
|
||||
self.assertEqual(asset.currency_digits, 2)
|
||||
|
||||
# end AssetTestCase
|
Loading…
Add table
Add a link
Reference in a new issue