line: rec_name with quantity, optimize get_counterpart_values(),
splitline: rec_name with quantity, optimize list/form, add tests
This commit is contained in:
parent
a397fe22a2
commit
03c552a29c
6 changed files with 927 additions and 22 deletions
|
@ -779,7 +779,7 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase):
|
|||
self.assertEqual(book2.rec_name, 'Asset-Book | -1.00 usd | Open | -1.5000 u')
|
||||
self.assertEqual(len(book2.lines), 1)
|
||||
self.assertEqual(book2.lines[0].rec_name,
|
||||
'05/01/2022|to|-1.00 usd|Transfer In [Book 1 | 1.00 usd | Open]|1.5000 u')
|
||||
'05/01/2022|to|-1.00 usd|Transfer In [Book 1 | 1.00 usd | Open]|-1.5000 u')
|
||||
self.assertEqual(book2.lines[0].state, 'check')
|
||||
self.assertEqual(book2.lines[0].bookingtype, 'mvout')
|
||||
self.assertEqual(book2.lines[0].feature, 'asset')
|
||||
|
@ -904,7 +904,7 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase):
|
|||
self.assertEqual(book2.rec_name, 'Asset-Book 1 | -1.00 usd | Open | -1.5000 u')
|
||||
self.assertEqual(len(book2.lines), 1)
|
||||
self.assertEqual(book2.lines[0].rec_name,
|
||||
'05/01/2022|to|-1.00 usd|Transfer In [Asset-Book 2 | 1.00 usd | Open | 1.5000 u]|1.5000 u')
|
||||
'05/01/2022|to|-1.00 usd|Transfer In [Asset-Book 2 | 1.00 usd | Open | 1.5000 u]|-1.5000 u')
|
||||
self.assertEqual(book2.lines[0].state, 'check')
|
||||
self.assertEqual(book2.lines[0].bookingtype, 'mvout')
|
||||
self.assertEqual(book2.lines[0].feature, 'asset')
|
||||
|
@ -1068,7 +1068,7 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase):
|
|||
self.assertEqual(book2.rec_name, 'Asset-Book 1 | -1.00 usd | Open | -42.5243 g')
|
||||
self.assertEqual(len(book2.lines), 1)
|
||||
self.assertEqual(book2.lines[0].rec_name,
|
||||
'05/01/2022|to|-1.00 usd|Transfer In [Asset-Book 2 | 1.00 usd | Open | 1.5000 oz]|42.5243 g')
|
||||
'05/01/2022|to|-1.00 usd|Transfer In [Asset-Book 2 | 1.00 usd | Open | 1.5000 oz]|-42.5243 g')
|
||||
self.assertEqual(book2.lines[0].state, 'check')
|
||||
self.assertEqual(book2.lines[0].bookingtype, 'mvout')
|
||||
self.assertEqual(book2.lines[0].feature, 'asset')
|
||||
|
@ -1392,18 +1392,887 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase):
|
|||
'Book 2 | -6.00 usd | Open | -2.50 u')
|
||||
self.assertEqual(len(books[0].lines[0].references), 1)
|
||||
self.assertEqual(books[0].lines[0].references[0].rec_name,
|
||||
'05/01/2022|to|-6.00 usd|from cashbook [Book 1 | 11.00 usd | Open | 4.00 u]|2.50 u')
|
||||
'05/01/2022|to|-6.00 usd|from cashbook [Book 1 | 11.00 usd | Open | 4.00 u]|-2.50 u')
|
||||
self.assertEqual(books[0].lines[0].reference, None)
|
||||
|
||||
self.assertEqual(books[1].rec_name, 'Book 2 | -6.00 usd | Open | -2.50 u')
|
||||
self.assertEqual(books[1].balance_all, Decimal('-6.0'))
|
||||
self.assertEqual(len(books[1].lines), 1)
|
||||
self.assertEqual(books[1].lines[0].rec_name,
|
||||
'05/01/2022|to|-6.00 usd|from cashbook [Book 1 | 11.00 usd | Open | 4.00 u]|2.50 u')
|
||||
'05/01/2022|to|-6.00 usd|from cashbook [Book 1 | 11.00 usd | Open | 4.00 u]|-2.50 u')
|
||||
|
||||
@with_transaction()
|
||||
def test_assetbook_split_in_catergory_asset_diff_unit(self):
|
||||
""" splitbooking incoming to asset-cahbook,
|
||||
from category and asset-cashbook with different
|
||||
unit
|
||||
"""
|
||||
pool = Pool()
|
||||
Book = pool.get('cashbook.book')
|
||||
Line = pool.get('cashbook.line')
|
||||
BType = pool.get('cashbook.type')
|
||||
Asset = pool.get('investment.asset')
|
||||
ProdTempl = pool.get('product.template')
|
||||
Uom = pool.get('product.uom')
|
||||
|
||||
types = self.prep_type()
|
||||
BType.write(*[
|
||||
[types],
|
||||
{
|
||||
'feature': 'asset',
|
||||
}])
|
||||
category = self.prep_category(cattype='in')
|
||||
|
||||
company = self.prep_company()
|
||||
party = self.prep_party()
|
||||
asset = self.prep_asset_item(
|
||||
company=company,
|
||||
product = self.prep_asset_product(name='Product 1'))
|
||||
|
||||
# set product to ounce
|
||||
ounce, = Uom.search([('symbol', '=', 'oz')])
|
||||
gram, = Uom.search([('symbol', '=', 'g')])
|
||||
|
||||
ProdTempl.write(*[
|
||||
[asset.product.template],
|
||||
{
|
||||
'default_uom': ounce.id,
|
||||
'name': 'Aurum',
|
||||
}])
|
||||
|
||||
Asset.write(*[
|
||||
[asset],
|
||||
{
|
||||
'uom': ounce.id,
|
||||
'rates': [('create', [{
|
||||
'date': date(2022, 5, 1),
|
||||
'rate': Decimal('1750.0'),
|
||||
}, ])],
|
||||
}])
|
||||
self.assertEqual(asset.rec_name, 'Aurum | 1,750.0000 usd/oz | 05/01/2022')
|
||||
|
||||
(usd, euro) = self.prep_2nd_currency(company)
|
||||
self.assertEqual(company.currency.rec_name, 'Euro')
|
||||
self.assertEqual(asset.symbol, 'usd/oz')
|
||||
|
||||
books = Book.create([{
|
||||
'start_date': date(2022, 4, 1),
|
||||
'name': 'Book ounce|usd',
|
||||
'btype': types.id,
|
||||
'company': company.id,
|
||||
'currency': usd.id,
|
||||
'number_sequ': self.prep_sequence().id,
|
||||
'asset': asset.id,
|
||||
'quantity_uom': ounce.id,
|
||||
'quantity_digits': 3,
|
||||
}, {
|
||||
'start_date': date(2022, 4, 1),
|
||||
'name': 'Book gram|euro',
|
||||
'btype': types.id,
|
||||
'company': company.id,
|
||||
'currency': euro.id,
|
||||
'number_sequ': self.prep_sequence().id,
|
||||
'asset': asset.id,
|
||||
'quantity_uom': gram.id,
|
||||
'quantity_digits': 3,
|
||||
}])
|
||||
self.assertEqual(books[0].rec_name, 'Book ounce|usd | 0.00 usd | Open | 0.000 oz')
|
||||
self.assertEqual(books[0].balance_all, Decimal('0.0'))
|
||||
self.assertEqual(len(books[0].lines), 0)
|
||||
self.assertEqual(books[1].rec_name, 'Book gram|euro | 0.00 € | Open | 0.000 g')
|
||||
self.assertEqual(books[1].balance_all, Decimal('0.0'))
|
||||
self.assertEqual(len(books[1].lines), 0)
|
||||
|
||||
Book.write(*[
|
||||
[books[0]],
|
||||
{
|
||||
'lines': [('create', [{
|
||||
'bookingtype': 'spin',
|
||||
'date': date(2022, 5, 1),
|
||||
'splitlines': [('create', [{
|
||||
'amount': Decimal('5.0'),
|
||||
'splittype': 'cat',
|
||||
'description': 'from category',
|
||||
'category': category.id,
|
||||
'quantity': Decimal('1.5'),
|
||||
}, {
|
||||
'amount': Decimal('6.0'),
|
||||
'splittype': 'tr',
|
||||
'description': 'from cashbook',
|
||||
'booktransf': books[1].id,
|
||||
'quantity': Decimal('2.5'),
|
||||
}])],
|
||||
}])],
|
||||
}])
|
||||
|
||||
self.assertEqual(books[0].rec_name, 'Book ounce|usd | 11.00 usd | Open | 4.000 oz')
|
||||
self.assertEqual(books[0].balance_all, Decimal('11.0'))
|
||||
self.assertEqual(len(books[0].lines), 1)
|
||||
self.assertEqual(books[0].lines[0].rec_name,
|
||||
'05/01/2022|Rev/Sp|11.00 usd|- [-]|4.000 oz')
|
||||
self.assertEqual(len(books[0].lines[0].splitlines), 2)
|
||||
self.assertEqual(books[0].lines[0].splitlines[0].rec_name,
|
||||
'Rev/Sp|5.00 usd|from category [Cat1]|1.500 oz')
|
||||
self.assertEqual(books[0].lines[0].splitlines[1].rec_name,
|
||||
'Rev/Sp|6.00 usd|from cashbook [Book gram|euro | 0.00 € | Open | 0.000 g]|2.500 oz')
|
||||
self.assertEqual(books[0].lines[0].splitlines[1].quantity, Decimal('2.5'))
|
||||
self.assertEqual(books[0].lines[0].splitlines[1].quantity_2nd_uom, Decimal('70.874'))
|
||||
|
||||
self.assertEqual(books[1].rec_name, 'Book gram|euro | 0.00 € | Open | 0.000 g')
|
||||
self.assertEqual(books[1].balance_all, Decimal('0.0'))
|
||||
self.assertEqual(len(books[1].lines), 0)
|
||||
|
||||
Line.wfcheck([books[0].lines[0]])
|
||||
|
||||
self.assertEqual(books[0].rec_name, 'Book ounce|usd | 11.00 usd | Open | 4.000 oz')
|
||||
self.assertEqual(books[0].balance_all, Decimal('11.0'))
|
||||
self.assertEqual(len(books[0].lines), 1)
|
||||
self.assertEqual(books[0].lines[0].rec_name,
|
||||
'05/01/2022|Rev/Sp|11.00 usd|- [-]|4.000 oz')
|
||||
self.assertEqual(len(books[0].lines[0].splitlines), 2)
|
||||
self.assertEqual(books[0].lines[0].splitlines[0].rec_name,
|
||||
'Rev/Sp|5.00 usd|from category [Cat1]|1.500 oz')
|
||||
self.assertEqual(books[0].lines[0].splitlines[1].rec_name,
|
||||
'Rev/Sp|6.00 usd|from cashbook [Book gram|euro | -5.71 € | Open | -70.874 g]|2.500 oz')
|
||||
|
||||
self.assertEqual(books[1].rec_name, 'Book gram|euro | -5.71 € | Open | -70.874 g')
|
||||
self.assertEqual(books[1].balance_all, Decimal('-5.71'))
|
||||
self.assertEqual(len(books[1].lines), 1)
|
||||
self.assertEqual(books[1].lines[0].rec_name,
|
||||
'05/01/2022|to|-5.71 €|from cashbook [Book ounce|usd | 11.00 usd | Open | 4.000 oz]|-70.874 g')
|
||||
|
||||
@with_transaction()
|
||||
def test_assetbook_split_in_catergory_asset_diff_unit_diff_cat(self):
|
||||
""" splitbooking incoming to asset-cahbook,
|
||||
from category and asset-cashbook with different
|
||||
unit and different uom-category
|
||||
"""
|
||||
pool = Pool()
|
||||
Book = pool.get('cashbook.book')
|
||||
Line = pool.get('cashbook.line')
|
||||
BType = pool.get('cashbook.type')
|
||||
Asset = pool.get('investment.asset')
|
||||
ProdTempl = pool.get('product.template')
|
||||
Uom = pool.get('product.uom')
|
||||
|
||||
types = self.prep_type()
|
||||
BType.write(*[
|
||||
[types],
|
||||
{
|
||||
'feature': 'asset',
|
||||
}])
|
||||
category = self.prep_category(cattype='in')
|
||||
|
||||
company = self.prep_company()
|
||||
party = self.prep_party()
|
||||
asset1 = self.prep_asset_item(
|
||||
company=company,
|
||||
product = self.prep_asset_product(name='Product 1'))
|
||||
asset2 = self.prep_asset_item(
|
||||
company=company,
|
||||
product = self.prep_asset_product(name='Product Liter'))
|
||||
|
||||
# set product to ounce
|
||||
ounce, = Uom.search([('symbol', '=', 'oz')])
|
||||
liter, = Uom.search([('symbol', '=', 'l')])
|
||||
|
||||
ProdTempl.write(*[
|
||||
[asset1.product.template],
|
||||
{
|
||||
'default_uom': ounce.id,
|
||||
'name': 'Aurum',
|
||||
},
|
||||
[asset2.product.template],
|
||||
{
|
||||
'default_uom': liter.id,
|
||||
'name': 'Liquid',
|
||||
},
|
||||
])
|
||||
|
||||
Asset.write(*[
|
||||
[asset1],
|
||||
{
|
||||
'uom': ounce.id,
|
||||
'rates': [('create', [{
|
||||
'date': date(2022, 5, 1),
|
||||
'rate': Decimal('1750.0'),
|
||||
}, ])],
|
||||
},
|
||||
[asset2],
|
||||
{
|
||||
'uom': liter.id,
|
||||
'rates': [('create', [{
|
||||
'date': date(2022, 5, 1),
|
||||
'rate': Decimal('10.0'),
|
||||
}, ])],
|
||||
},
|
||||
])
|
||||
self.assertEqual(asset1.rec_name, 'Aurum | 1,750.0000 usd/oz | 05/01/2022')
|
||||
self.assertEqual(asset2.rec_name, 'Liquid | 10.0000 usd/l | 05/01/2022')
|
||||
|
||||
(usd, euro) = self.prep_2nd_currency(company)
|
||||
self.assertEqual(company.currency.rec_name, 'Euro')
|
||||
self.assertEqual(asset1.symbol, 'usd/oz')
|
||||
self.assertEqual(asset2.symbol, 'usd/l')
|
||||
|
||||
books = Book.create([{
|
||||
'start_date': date(2022, 4, 1),
|
||||
'name': 'Book ounce|usd',
|
||||
'btype': types.id,
|
||||
'company': company.id,
|
||||
'currency': usd.id,
|
||||
'number_sequ': self.prep_sequence().id,
|
||||
'asset': asset1.id,
|
||||
'quantity_uom': ounce.id,
|
||||
'quantity_digits': 3,
|
||||
}, {
|
||||
'start_date': date(2022, 4, 1),
|
||||
'name': 'Book liter|euro',
|
||||
'btype': types.id,
|
||||
'company': company.id,
|
||||
'currency': euro.id,
|
||||
'number_sequ': self.prep_sequence().id,
|
||||
'asset': asset2.id,
|
||||
'quantity_uom': liter.id,
|
||||
'quantity_digits': 3,
|
||||
}])
|
||||
self.assertEqual(books[0].rec_name, 'Book ounce|usd | 0.00 usd | Open | 0.000 oz')
|
||||
self.assertEqual(books[0].balance_all, Decimal('0.0'))
|
||||
self.assertEqual(len(books[0].lines), 0)
|
||||
self.assertEqual(books[1].rec_name, 'Book liter|euro | 0.00 € | Open | 0.000 l')
|
||||
self.assertEqual(books[1].balance_all, Decimal('0.0'))
|
||||
self.assertEqual(len(books[1].lines), 0)
|
||||
|
||||
self.assertRaisesRegex(UserError,
|
||||
r"Cannot transfer quantities between cashbooks with different unit-categories \(Weight != Volume\).",
|
||||
Book.write,
|
||||
*[
|
||||
[books[0]],
|
||||
{
|
||||
'lines': [('create', [{
|
||||
'bookingtype': 'spin',
|
||||
'date': date(2022, 5, 1),
|
||||
'splitlines': [('create', [{
|
||||
'amount': Decimal('5.0'),
|
||||
'splittype': 'cat',
|
||||
'description': 'from category',
|
||||
'category': category.id,
|
||||
'quantity': Decimal('1.5'),
|
||||
}, {
|
||||
'amount': Decimal('6.0'),
|
||||
'splittype': 'tr',
|
||||
'description': 'from cashbook',
|
||||
'booktransf': books[1].id,
|
||||
'quantity': Decimal('2.5'),
|
||||
}])],
|
||||
}])],
|
||||
},
|
||||
])
|
||||
|
||||
@with_transaction()
|
||||
def test_assetbook_split_out_category(self):
|
||||
""" splitbooking outgoing with asset
|
||||
"""
|
||||
pool = Pool()
|
||||
Book = pool.get('cashbook.book')
|
||||
BType = pool.get('cashbook.type')
|
||||
Asset = pool.get('investment.asset')
|
||||
ProdTempl = pool.get('product.template')
|
||||
Uom = pool.get('product.uom')
|
||||
|
||||
types = self.prep_type()
|
||||
BType.write(*[
|
||||
[types],
|
||||
{
|
||||
'feature': 'asset',
|
||||
}])
|
||||
category = self.prep_category(cattype='out')
|
||||
|
||||
company = self.prep_company()
|
||||
party = self.prep_party()
|
||||
asset = self.prep_asset_item(
|
||||
company=company,
|
||||
product = self.prep_asset_product(name='Product 1'))
|
||||
self.assertEqual(asset.symbol, 'usd/u')
|
||||
|
||||
book, = Book.create([{
|
||||
'start_date': date(2022, 4, 1),
|
||||
'name': 'Book 1',
|
||||
'btype': types.id,
|
||||
'company': company.id,
|
||||
'currency': company.currency.id,
|
||||
'number_sequ': self.prep_sequence().id,
|
||||
'asset': asset.id,
|
||||
'quantity_uom': asset.uom.id,
|
||||
'quantity_digits': 2,
|
||||
}])
|
||||
|
||||
Book.write(*[
|
||||
[book],
|
||||
{
|
||||
'lines': [('create', [{
|
||||
'bookingtype': 'spout',
|
||||
'date': date(2022, 5, 1),
|
||||
'splitlines': [('create', [{
|
||||
'amount': Decimal('5.0'),
|
||||
'splittype': 'cat',
|
||||
'description': 'to category',
|
||||
'category': category.id,
|
||||
'quantity': Decimal('1.5'),
|
||||
}, {
|
||||
'amount': Decimal('6.0'),
|
||||
'splittype': 'cat',
|
||||
'description': 'to category',
|
||||
'category': category.id,
|
||||
'quantity': Decimal('2.5'),
|
||||
}])],
|
||||
}])],
|
||||
}])
|
||||
|
||||
self.assertEqual(book.rec_name, 'Book 1 | -11.00 usd | Open | -4.00 u')
|
||||
self.assertEqual(book.balance_all, Decimal('-11.0'))
|
||||
self.assertEqual(len(book.lines), 1)
|
||||
self.assertEqual(book.lines[0].splitline_has_quantity, False)
|
||||
self.assertEqual(book.lines[0].rec_name, '05/01/2022|Exp/Sp|-11.00 usd|- [-]|-4.00 u')
|
||||
|
||||
self.assertEqual(len(book.lines[0].splitlines), 2)
|
||||
self.assertEqual(book.lines[0].splitlines[0].rec_name,
|
||||
'Exp/Sp|5.00 usd|to category [Cat1]|1.50 u')
|
||||
self.assertEqual(book.lines[0].splitlines[1].rec_name,
|
||||
'Exp/Sp|6.00 usd|to category [Cat1]|2.50 u')
|
||||
|
||||
@with_transaction()
|
||||
def test_assetbook_split_out_category_and_assetbook(self):
|
||||
""" splitbooking outgoing,
|
||||
from asset-cashbook to asset-cahbook and to category
|
||||
"""
|
||||
pool = Pool()
|
||||
Book = pool.get('cashbook.book')
|
||||
Line = pool.get('cashbook.line')
|
||||
BType = pool.get('cashbook.type')
|
||||
Asset = pool.get('investment.asset')
|
||||
ProdTempl = pool.get('product.template')
|
||||
Uom = pool.get('product.uom')
|
||||
|
||||
types = self.prep_type()
|
||||
BType.write(*[
|
||||
[types],
|
||||
{
|
||||
'feature': 'asset',
|
||||
}])
|
||||
category = self.prep_category(cattype='out')
|
||||
|
||||
company = self.prep_company()
|
||||
party = self.prep_party()
|
||||
asset = self.prep_asset_item(
|
||||
company=company,
|
||||
product = self.prep_asset_product(name='Product 1'))
|
||||
self.assertEqual(asset.symbol, 'usd/u')
|
||||
|
||||
books = Book.create([{
|
||||
'start_date': date(2022, 4, 1),
|
||||
'name': 'Book 1',
|
||||
'btype': types.id,
|
||||
'company': company.id,
|
||||
'currency': company.currency.id,
|
||||
'number_sequ': self.prep_sequence().id,
|
||||
'asset': asset.id,
|
||||
'quantity_uom': asset.uom.id,
|
||||
'quantity_digits': 2,
|
||||
}, {
|
||||
'start_date': date(2022, 4, 1),
|
||||
'name': 'Book 2',
|
||||
'btype': types.id,
|
||||
'company': company.id,
|
||||
'currency': company.currency.id,
|
||||
'number_sequ': self.prep_sequence().id,
|
||||
'asset': asset.id,
|
||||
'quantity_uom': asset.uom.id,
|
||||
'quantity_digits': 2,
|
||||
}])
|
||||
|
||||
Book.write(*[
|
||||
[books[0]],
|
||||
{
|
||||
'lines': [('create', [{
|
||||
'bookingtype': 'spout',
|
||||
'date': date(2022, 5, 1),
|
||||
'splitlines': [('create', [{
|
||||
'amount': Decimal('5.0'),
|
||||
'splittype': 'cat',
|
||||
'description': 'to category',
|
||||
'category': category.id,
|
||||
'quantity': Decimal('1.5'),
|
||||
}, {
|
||||
'amount': Decimal('6.0'),
|
||||
'splittype': 'tr',
|
||||
'description': 'to cashbook',
|
||||
'booktransf': books[1].id,
|
||||
'quantity': Decimal('2.5'),
|
||||
}])],
|
||||
}])],
|
||||
}])
|
||||
|
||||
self.assertEqual(books[0].rec_name, 'Book 1 | -11.00 usd | Open | -4.00 u')
|
||||
self.assertEqual(books[0].balance_all, Decimal('-11.0'))
|
||||
|
||||
self.assertEqual(len(books[0].lines), 1)
|
||||
self.assertEqual(books[0].lines[0].rec_name,
|
||||
'05/01/2022|Exp/Sp|-11.00 usd|- [-]|-4.00 u')
|
||||
self.assertEqual(books[0].lines[0].splitline_has_quantity, True)
|
||||
|
||||
self.assertEqual(len(books[0].lines[0].splitlines), 2)
|
||||
self.assertEqual(books[0].lines[0].splitlines[0].rec_name,
|
||||
'Exp/Sp|5.00 usd|to category [Cat1]|1.50 u')
|
||||
self.assertEqual(books[0].lines[0].splitlines[1].rec_name,
|
||||
'Exp/Sp|6.00 usd|to cashbook [Book 2 | 0.00 usd | Open | 0.00 u]|2.50 u')
|
||||
|
||||
self.assertEqual(len(books[0].lines[0].references), 0)
|
||||
self.assertEqual(books[0].lines[0].reference, None)
|
||||
|
||||
self.assertEqual(books[1].rec_name, 'Book 2 | 0.00 usd | Open | 0.00 u')
|
||||
self.assertEqual(books[1].balance_all, Decimal('0.0'))
|
||||
self.assertEqual(len(books[1].lines), 0)
|
||||
|
||||
Line.wfcheck([books[0].lines[0]])
|
||||
|
||||
self.assertEqual(books[0].rec_name, 'Book 1 | -11.00 usd | Open | -4.00 u')
|
||||
self.assertEqual(books[0].balance_all, Decimal('-11.0'))
|
||||
self.assertEqual(len(books[0].lines), 1)
|
||||
|
||||
self.assertEqual(books[0].lines[0].rec_name,
|
||||
'05/01/2022|Exp/Sp|-11.00 usd|- [-]|-4.00 u')
|
||||
self.assertEqual(books[0].lines[0].splitline_has_quantity, True)
|
||||
|
||||
self.assertEqual(len(books[0].lines[0].splitlines), 2)
|
||||
self.assertEqual(books[0].lines[0].splitlines[0].rec_name,
|
||||
'Exp/Sp|5.00 usd|to category [Cat1]|1.50 u')
|
||||
self.assertEqual(books[0].lines[0].splitlines[1].rec_name,
|
||||
'Exp/Sp|6.00 usd|to cashbook [Book 2 | 6.00 usd | Open | 2.50 u]|2.50 u')
|
||||
self.assertEqual(books[0].lines[0].splitlines[1].amount, Decimal('6.0'))
|
||||
self.assertEqual(books[0].lines[0].splitlines[1].amount_2nd_currency, None)
|
||||
self.assertEqual(books[0].lines[0].splitlines[1].quantity, Decimal('2.5'))
|
||||
self.assertEqual(books[0].lines[0].splitlines[1].quantity2nd, None)
|
||||
self.assertEqual(books[0].lines[0].splitlines[1].booktransf.rec_name,
|
||||
'Book 2 | 6.00 usd | Open | 2.50 u')
|
||||
self.assertEqual(len(books[0].lines[0].references), 1)
|
||||
self.assertEqual(books[0].lines[0].references[0].rec_name,
|
||||
'05/01/2022|from|6.00 usd|to cashbook [Book 1 | -11.00 usd | Open | -4.00 u]|2.50 u')
|
||||
self.assertEqual(books[0].lines[0].reference, None)
|
||||
|
||||
self.assertEqual(books[1].rec_name, 'Book 2 | 6.00 usd | Open | 2.50 u')
|
||||
self.assertEqual(books[1].balance_all, Decimal('6.0'))
|
||||
self.assertEqual(len(books[1].lines), 1)
|
||||
self.assertEqual(books[1].lines[0].rec_name,
|
||||
'05/01/2022|from|6.00 usd|to cashbook [Book 1 | -11.00 usd | Open | -4.00 u]|2.50 u')
|
||||
|
||||
@with_transaction()
|
||||
def test_assetbook_split_out_category_and_assetbook2(self):
|
||||
""" splitbooking outgoing,
|
||||
from cashbook to asset-cahbook and to category
|
||||
"""
|
||||
pool = Pool()
|
||||
Book = pool.get('cashbook.book')
|
||||
Line = pool.get('cashbook.line')
|
||||
BType = pool.get('cashbook.type')
|
||||
Asset = pool.get('investment.asset')
|
||||
ProdTempl = pool.get('product.template')
|
||||
Uom = pool.get('product.uom')
|
||||
|
||||
types_asset = self.prep_type()
|
||||
BType.write(*[
|
||||
[types_asset],
|
||||
{
|
||||
'feature': 'asset',
|
||||
'name': 'Asset',
|
||||
'short': 'as',
|
||||
}])
|
||||
types_cash = self.prep_type()
|
||||
self.assertEqual(types_cash.rec_name, 'CAS - Cash')
|
||||
self.assertEqual(types_asset.rec_name, 'as - Asset')
|
||||
category = self.prep_category(cattype='out')
|
||||
|
||||
company = self.prep_company()
|
||||
party = self.prep_party()
|
||||
asset = self.prep_asset_item(
|
||||
company=company,
|
||||
product = self.prep_asset_product(name='Product 1'))
|
||||
self.assertEqual(asset.symbol, 'usd/u')
|
||||
|
||||
books = Book.create([{
|
||||
'start_date': date(2022, 4, 1),
|
||||
'name': 'Book Cash',
|
||||
'btype': types_cash.id,
|
||||
'company': company.id,
|
||||
'currency': company.currency.id,
|
||||
'number_sequ': self.prep_sequence().id,
|
||||
}, {
|
||||
'start_date': date(2022, 4, 1),
|
||||
'name': 'Book Asset',
|
||||
'btype': types_asset.id,
|
||||
'company': company.id,
|
||||
'currency': company.currency.id,
|
||||
'number_sequ': self.prep_sequence().id,
|
||||
'asset': asset.id,
|
||||
'quantity_uom': asset.uom.id,
|
||||
'quantity_digits': 2,
|
||||
}])
|
||||
|
||||
Book.write(*[
|
||||
[books[0]],
|
||||
{
|
||||
'lines': [('create', [{
|
||||
'bookingtype': 'spout',
|
||||
'date': date(2022, 5, 1),
|
||||
'splitlines': [('create', [{
|
||||
'amount': Decimal('5.0'),
|
||||
'splittype': 'cat',
|
||||
'description': 'to category',
|
||||
'category': category.id,
|
||||
}, {
|
||||
'amount': Decimal('6.0'),
|
||||
'splittype': 'tr',
|
||||
'description': 'to cashbook',
|
||||
'booktransf': books[1].id,
|
||||
'quantity': Decimal('2.5'),
|
||||
}])],
|
||||
}])],
|
||||
}])
|
||||
|
||||
self.assertEqual(books[0].rec_name, 'Book Cash | -11.00 usd | Open')
|
||||
self.assertEqual(books[0].balance_all, Decimal('-11.0'))
|
||||
|
||||
self.assertEqual(len(books[0].lines), 1)
|
||||
self.assertEqual(books[0].lines[0].rec_name,
|
||||
'05/01/2022|Exp/Sp|-11.00 usd|- [-]')
|
||||
self.assertEqual(books[0].lines[0].quantity, Decimal('2.5'))
|
||||
self.assertEqual(books[0].lines[0].quantity_credit, None)
|
||||
self.assertEqual(books[0].lines[0].quantity_debit, None)
|
||||
self.assertEqual(books[0].lines[0].quantity_2nd_uom, None)
|
||||
self.assertEqual(books[0].lines[0].splitline_has_quantity, True)
|
||||
|
||||
self.assertEqual(len(books[0].lines[0].splitlines), 2)
|
||||
self.assertEqual(books[0].lines[0].splitlines[0].rec_name,
|
||||
'Exp/Sp|5.00 usd|to category [Cat1]')
|
||||
self.assertEqual(books[0].lines[0].splitlines[0].quantity, None)
|
||||
self.assertEqual(books[0].lines[0].splitlines[0].quantity_2nd_uom, None)
|
||||
self.assertEqual(books[0].lines[0].splitlines[1].rec_name,
|
||||
'Exp/Sp|6.00 usd|to cashbook [Book Asset | 0.00 usd | Open | 0.00 u]')
|
||||
self.assertEqual(books[0].lines[0].splitlines[1].quantity, Decimal('2.5'))
|
||||
self.assertEqual(books[0].lines[0].splitlines[1].quantity_2nd_uom, None)
|
||||
|
||||
self.assertEqual(len(books[0].lines[0].references), 0)
|
||||
self.assertEqual(books[0].lines[0].reference, None)
|
||||
|
||||
self.assertEqual(books[1].rec_name, 'Book Asset | 0.00 usd | Open | 0.00 u')
|
||||
self.assertEqual(books[1].balance_all, Decimal('0.0'))
|
||||
self.assertEqual(len(books[1].lines), 0)
|
||||
|
||||
Line.wfcheck([books[0].lines[0]])
|
||||
|
||||
self.assertEqual(books[0].rec_name, 'Book Cash | -11.00 usd | Open')
|
||||
self.assertEqual(books[0].balance_all, Decimal('-11.0'))
|
||||
self.assertEqual(len(books[0].lines), 1)
|
||||
|
||||
self.assertEqual(books[0].lines[0].rec_name,
|
||||
'05/01/2022|Exp/Sp|-11.00 usd|- [-]')
|
||||
self.assertEqual(books[0].lines[0].splitline_has_quantity, True)
|
||||
self.assertEqual(books[0].lines[0].quantity, Decimal('2.5'))
|
||||
self.assertEqual(books[0].lines[0].quantity_credit, None)
|
||||
self.assertEqual(books[0].lines[0].quantity_debit, None)
|
||||
self.assertEqual(books[0].lines[0].quantity_2nd_uom, None)
|
||||
|
||||
self.assertEqual(len(books[0].lines[0].splitlines), 2)
|
||||
self.assertEqual(books[0].lines[0].splitlines[0].rec_name,
|
||||
'Exp/Sp|5.00 usd|to category [Cat1]')
|
||||
self.assertEqual(books[0].lines[0].splitlines[1].rec_name,
|
||||
'Exp/Sp|6.00 usd|to cashbook [Book Asset | 6.00 usd | Open | 2.50 u]')
|
||||
self.assertEqual(books[0].lines[0].splitlines[1].amount, Decimal('6.0'))
|
||||
self.assertEqual(books[0].lines[0].splitlines[1].amount_2nd_currency, None)
|
||||
self.assertEqual(books[0].lines[0].splitlines[1].quantity, Decimal('2.5'))
|
||||
self.assertEqual(books[0].lines[0].splitlines[1].quantity2nd, None)
|
||||
self.assertEqual(books[0].lines[0].splitlines[1].booktransf.rec_name,
|
||||
'Book Asset | 6.00 usd | Open | 2.50 u')
|
||||
self.assertEqual(len(books[0].lines[0].references), 1)
|
||||
self.assertEqual(books[0].lines[0].references[0].rec_name,
|
||||
'05/01/2022|from|6.00 usd|to cashbook [Book Cash | -11.00 usd | Open]|2.50 u')
|
||||
self.assertEqual(books[0].lines[0].reference, None)
|
||||
|
||||
self.assertEqual(books[1].rec_name, 'Book Asset | 6.00 usd | Open | 2.50 u')
|
||||
self.assertEqual(books[1].balance_all, Decimal('6.0'))
|
||||
self.assertEqual(len(books[1].lines), 1)
|
||||
self.assertEqual(books[1].lines[0].rec_name,
|
||||
'05/01/2022|from|6.00 usd|to cashbook [Book Cash | -11.00 usd | Open]|2.50 u')
|
||||
|
||||
@with_transaction()
|
||||
def test_assetbook_split_out_catergory_asset_diff_unit(self):
|
||||
""" splitbooking outgoing to asset-cahbook,
|
||||
to category and asset-cashbook with different
|
||||
unit
|
||||
"""
|
||||
pool = Pool()
|
||||
Book = pool.get('cashbook.book')
|
||||
Line = pool.get('cashbook.line')
|
||||
BType = pool.get('cashbook.type')
|
||||
Asset = pool.get('investment.asset')
|
||||
ProdTempl = pool.get('product.template')
|
||||
Uom = pool.get('product.uom')
|
||||
|
||||
types = self.prep_type()
|
||||
BType.write(*[
|
||||
[types],
|
||||
{
|
||||
'feature': 'asset',
|
||||
}])
|
||||
category = self.prep_category(cattype='out')
|
||||
|
||||
company = self.prep_company()
|
||||
party = self.prep_party()
|
||||
asset = self.prep_asset_item(
|
||||
company=company,
|
||||
product = self.prep_asset_product(name='Product 1'))
|
||||
|
||||
# set product to ounce
|
||||
ounce, = Uom.search([('symbol', '=', 'oz')])
|
||||
gram, = Uom.search([('symbol', '=', 'g')])
|
||||
|
||||
ProdTempl.write(*[
|
||||
[asset.product.template],
|
||||
{
|
||||
'default_uom': ounce.id,
|
||||
'name': 'Aurum',
|
||||
}])
|
||||
|
||||
Asset.write(*[
|
||||
[asset],
|
||||
{
|
||||
'uom': ounce.id,
|
||||
'rates': [('create', [{
|
||||
'date': date(2022, 5, 1),
|
||||
'rate': Decimal('1750.0'),
|
||||
}, ])],
|
||||
}])
|
||||
self.assertEqual(asset.rec_name, 'Aurum | 1,750.0000 usd/oz | 05/01/2022')
|
||||
|
||||
(usd, euro) = self.prep_2nd_currency(company)
|
||||
self.assertEqual(company.currency.rec_name, 'Euro')
|
||||
self.assertEqual(asset.symbol, 'usd/oz')
|
||||
|
||||
books = Book.create([{
|
||||
'start_date': date(2022, 4, 1),
|
||||
'name': 'Book ounce|usd',
|
||||
'btype': types.id,
|
||||
'company': company.id,
|
||||
'currency': usd.id,
|
||||
'number_sequ': self.prep_sequence().id,
|
||||
'asset': asset.id,
|
||||
'quantity_uom': ounce.id,
|
||||
'quantity_digits': 3,
|
||||
}, {
|
||||
'start_date': date(2022, 4, 1),
|
||||
'name': 'Book gram|euro',
|
||||
'btype': types.id,
|
||||
'company': company.id,
|
||||
'currency': euro.id,
|
||||
'number_sequ': self.prep_sequence().id,
|
||||
'asset': asset.id,
|
||||
'quantity_uom': gram.id,
|
||||
'quantity_digits': 3,
|
||||
}])
|
||||
self.assertEqual(books[0].rec_name, 'Book ounce|usd | 0.00 usd | Open | 0.000 oz')
|
||||
self.assertEqual(books[0].balance_all, Decimal('0.0'))
|
||||
self.assertEqual(len(books[0].lines), 0)
|
||||
self.assertEqual(books[1].rec_name, 'Book gram|euro | 0.00 € | Open | 0.000 g')
|
||||
self.assertEqual(books[1].balance_all, Decimal('0.0'))
|
||||
self.assertEqual(len(books[1].lines), 0)
|
||||
|
||||
Book.write(*[
|
||||
[books[0]],
|
||||
{
|
||||
'lines': [('create', [{
|
||||
'bookingtype': 'spout',
|
||||
'date': date(2022, 5, 1),
|
||||
'splitlines': [('create', [{
|
||||
'amount': Decimal('5.0'),
|
||||
'splittype': 'cat',
|
||||
'description': 'to category',
|
||||
'category': category.id,
|
||||
'quantity': Decimal('1.5'),
|
||||
}, {
|
||||
'amount': Decimal('6.0'),
|
||||
'splittype': 'tr',
|
||||
'description': 'to cashbook',
|
||||
'booktransf': books[1].id,
|
||||
'quantity': Decimal('2.5'),
|
||||
}])],
|
||||
}])],
|
||||
}])
|
||||
|
||||
self.assertEqual(books[0].rec_name, 'Book ounce|usd | -11.00 usd | Open | -4.000 oz')
|
||||
self.assertEqual(books[0].balance_all, Decimal('-11.0'))
|
||||
self.assertEqual(len(books[0].lines), 1)
|
||||
self.assertEqual(books[0].lines[0].rec_name,
|
||||
'05/01/2022|Exp/Sp|-11.00 usd|- [-]|-4.000 oz')
|
||||
self.assertEqual(len(books[0].lines[0].splitlines), 2)
|
||||
self.assertEqual(books[0].lines[0].splitlines[0].rec_name,
|
||||
'Exp/Sp|5.00 usd|to category [Cat1]|1.500 oz')
|
||||
self.assertEqual(books[0].lines[0].splitlines[1].rec_name,
|
||||
'Exp/Sp|6.00 usd|to cashbook [Book gram|euro | 0.00 € | Open | 0.000 g]|2.500 oz')
|
||||
self.assertEqual(books[0].lines[0].splitlines[1].quantity, Decimal('2.5'))
|
||||
self.assertEqual(books[0].lines[0].splitlines[1].quantity_2nd_uom, Decimal('70.874'))
|
||||
|
||||
self.assertEqual(books[1].rec_name, 'Book gram|euro | 0.00 € | Open | 0.000 g')
|
||||
self.assertEqual(books[1].balance_all, Decimal('0.0'))
|
||||
self.assertEqual(len(books[1].lines), 0)
|
||||
|
||||
Line.wfcheck([books[0].lines[0]])
|
||||
|
||||
self.assertEqual(books[0].rec_name, 'Book ounce|usd | -11.00 usd | Open | -4.000 oz')
|
||||
self.assertEqual(books[0].balance_all, Decimal('-11.0'))
|
||||
self.assertEqual(len(books[0].lines), 1)
|
||||
self.assertEqual(books[0].lines[0].rec_name,
|
||||
'05/01/2022|Exp/Sp|-11.00 usd|- [-]|-4.000 oz')
|
||||
self.assertEqual(len(books[0].lines[0].splitlines), 2)
|
||||
self.assertEqual(books[0].lines[0].splitlines[0].rec_name,
|
||||
'Exp/Sp|5.00 usd|to category [Cat1]|1.500 oz')
|
||||
self.assertEqual(books[0].lines[0].splitlines[1].rec_name,
|
||||
'Exp/Sp|6.00 usd|to cashbook [Book gram|euro | 5.71 € | Open | 70.874 g]|2.500 oz')
|
||||
|
||||
self.assertEqual(books[1].rec_name, 'Book gram|euro | 5.71 € | Open | 70.874 g')
|
||||
self.assertEqual(books[1].balance_all, Decimal('5.71'))
|
||||
self.assertEqual(len(books[1].lines), 1)
|
||||
self.assertEqual(books[1].lines[0].rec_name,
|
||||
'05/01/2022|from|5.71 €|to cashbook [Book ounce|usd | -11.00 usd | Open | -4.000 oz]|70.874 g')
|
||||
|
||||
@with_transaction()
|
||||
def test_assetbook_split_out_catergory_asset_diff_unit_diff_cat(self):
|
||||
""" splitbooking outgoing to asset-cahbook,
|
||||
to category and asset-cashbook with different
|
||||
unit and different uom-category
|
||||
"""
|
||||
pool = Pool()
|
||||
Book = pool.get('cashbook.book')
|
||||
Line = pool.get('cashbook.line')
|
||||
BType = pool.get('cashbook.type')
|
||||
Asset = pool.get('investment.asset')
|
||||
ProdTempl = pool.get('product.template')
|
||||
Uom = pool.get('product.uom')
|
||||
|
||||
types = self.prep_type()
|
||||
BType.write(*[
|
||||
[types],
|
||||
{
|
||||
'feature': 'asset',
|
||||
}])
|
||||
category = self.prep_category(cattype='out')
|
||||
|
||||
company = self.prep_company()
|
||||
party = self.prep_party()
|
||||
asset1 = self.prep_asset_item(
|
||||
company=company,
|
||||
product = self.prep_asset_product(name='Product 1'))
|
||||
asset2 = self.prep_asset_item(
|
||||
company=company,
|
||||
product = self.prep_asset_product(name='Product Liter'))
|
||||
|
||||
# set product to ounce
|
||||
ounce, = Uom.search([('symbol', '=', 'oz')])
|
||||
liter, = Uom.search([('symbol', '=', 'l')])
|
||||
|
||||
ProdTempl.write(*[
|
||||
[asset1.product.template],
|
||||
{
|
||||
'default_uom': ounce.id,
|
||||
'name': 'Aurum',
|
||||
},
|
||||
[asset2.product.template],
|
||||
{
|
||||
'default_uom': liter.id,
|
||||
'name': 'Liquid',
|
||||
},
|
||||
])
|
||||
|
||||
Asset.write(*[
|
||||
[asset1],
|
||||
{
|
||||
'uom': ounce.id,
|
||||
'rates': [('create', [{
|
||||
'date': date(2022, 5, 1),
|
||||
'rate': Decimal('1750.0'),
|
||||
}, ])],
|
||||
},
|
||||
[asset2],
|
||||
{
|
||||
'uom': liter.id,
|
||||
'rates': [('create', [{
|
||||
'date': date(2022, 5, 1),
|
||||
'rate': Decimal('10.0'),
|
||||
}, ])],
|
||||
},
|
||||
])
|
||||
self.assertEqual(asset1.rec_name, 'Aurum | 1,750.0000 usd/oz | 05/01/2022')
|
||||
self.assertEqual(asset2.rec_name, 'Liquid | 10.0000 usd/l | 05/01/2022')
|
||||
|
||||
(usd, euro) = self.prep_2nd_currency(company)
|
||||
self.assertEqual(company.currency.rec_name, 'Euro')
|
||||
self.assertEqual(asset1.symbol, 'usd/oz')
|
||||
self.assertEqual(asset2.symbol, 'usd/l')
|
||||
|
||||
books = Book.create([{
|
||||
'start_date': date(2022, 4, 1),
|
||||
'name': 'Book ounce|usd',
|
||||
'btype': types.id,
|
||||
'company': company.id,
|
||||
'currency': usd.id,
|
||||
'number_sequ': self.prep_sequence().id,
|
||||
'asset': asset1.id,
|
||||
'quantity_uom': ounce.id,
|
||||
'quantity_digits': 3,
|
||||
}, {
|
||||
'start_date': date(2022, 4, 1),
|
||||
'name': 'Book liter|euro',
|
||||
'btype': types.id,
|
||||
'company': company.id,
|
||||
'currency': euro.id,
|
||||
'number_sequ': self.prep_sequence().id,
|
||||
'asset': asset2.id,
|
||||
'quantity_uom': liter.id,
|
||||
'quantity_digits': 3,
|
||||
}])
|
||||
self.assertEqual(books[0].rec_name, 'Book ounce|usd | 0.00 usd | Open | 0.000 oz')
|
||||
self.assertEqual(books[0].balance_all, Decimal('0.0'))
|
||||
self.assertEqual(len(books[0].lines), 0)
|
||||
self.assertEqual(books[1].rec_name, 'Book liter|euro | 0.00 € | Open | 0.000 l')
|
||||
self.assertEqual(books[1].balance_all, Decimal('0.0'))
|
||||
self.assertEqual(len(books[1].lines), 0)
|
||||
|
||||
self.assertRaisesRegex(UserError,
|
||||
r"Cannot transfer quantities between cashbooks with different unit-categories \(Weight != Volume\).",
|
||||
Book.write,
|
||||
*[
|
||||
[books[0]],
|
||||
{
|
||||
'lines': [('create', [{
|
||||
'bookingtype': 'spout',
|
||||
'date': date(2022, 5, 1),
|
||||
'splitlines': [('create', [{
|
||||
'amount': Decimal('5.0'),
|
||||
'splittype': 'cat',
|
||||
'description': 'from category',
|
||||
'category': category.id,
|
||||
'quantity': Decimal('1.5'),
|
||||
}, {
|
||||
'amount': Decimal('6.0'),
|
||||
'splittype': 'tr',
|
||||
'description': 'from cashbook',
|
||||
'booktransf': books[1].id,
|
||||
'quantity': Decimal('2.5'),
|
||||
}])],
|
||||
}])],
|
||||
},
|
||||
])
|
||||
|
||||
# TODO:
|
||||
# - splitbuchung mit unterschiedlichen einheiten einer kategorie
|
||||
# - splitbuchung mit unterschiedlichen einheiten verschiedener kategorien
|
||||
# in/out-splitbuchung
|
||||
|
||||
# end CbInvTestCase
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue