line: fix transfer between cash-/asset-book with zero quantity
This commit is contained in:
parent
ae8091bbdf
commit
8232f8042d
2 changed files with 212 additions and 11 deletions
17
line.py
17
line.py
|
@ -181,19 +181,16 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
|
|||
'quantity_2nd_uom': splitline.quantity \
|
||||
if (asset_books == 2) and (diff_uom == True) else None,
|
||||
})
|
||||
elif booktransf_uom is None:
|
||||
# counterpart-cashbook has no uom -> no quantity
|
||||
elif sum([1 if booktransf_uom is not None else 0,
|
||||
1 if line_uom is not None else 0]) == 1:
|
||||
# one of the related cashbooks only is asset-type
|
||||
result.update({
|
||||
'quantity': None,
|
||||
'quantity': line.quantity,
|
||||
'quantity_2nd_uom': None,
|
||||
})
|
||||
else :
|
||||
if line_uom is None:
|
||||
result.update({
|
||||
'quantity': line.quantity,
|
||||
'quantity_2nd_uom': None,
|
||||
})
|
||||
elif line_uom == booktransf_uom:
|
||||
elif sum([1 if booktransf_uom is not None else 0,
|
||||
1 if line_uom is not None else 0]) == 2:
|
||||
if line_uom == booktransf_uom:
|
||||
result.update({
|
||||
'quantity': line.quantity,
|
||||
'quantity_2nd_uom': None,
|
||||
|
|
|
@ -677,6 +677,87 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase):
|
|||
book.lines = l1
|
||||
book.lines[-1].on_change_quantity()
|
||||
|
||||
@with_transaction()
|
||||
def test_assetbook_check_mvout_zero_quantity(self):
|
||||
""" create cashbook + line, bookingtype 'mvout'
|
||||
transfer from asset-book to cash-book - zero quantity,
|
||||
to book gain/loss
|
||||
"""
|
||||
pool = Pool()
|
||||
Book = pool.get('cashbook.book')
|
||||
Line = pool.get('cashbook.line')
|
||||
Category = pool.get('cashbook.category')
|
||||
BType = pool.get('cashbook.type')
|
||||
|
||||
type_cash = self.prep_type()
|
||||
type_depot = self.prep_type('Depot', 'D')
|
||||
BType.write(*[
|
||||
[type_depot],
|
||||
{
|
||||
'feature': 'asset',
|
||||
}])
|
||||
|
||||
category_out = self.prep_category(name='Out 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')
|
||||
|
||||
book1, = Book.create([{
|
||||
'name': 'Asset-Book',
|
||||
'btype': type_depot.id,
|
||||
'asset': asset.id,
|
||||
'quantity_uom': asset.uom.id,
|
||||
'company': company.id,
|
||||
'currency': company.currency.id,
|
||||
'number_sequ': self.prep_sequence().id,
|
||||
'start_date': date(2022, 5, 1),
|
||||
}])
|
||||
|
||||
book2, = Book.create([{
|
||||
'name': 'Cash-Book',
|
||||
'btype': type_cash.id,
|
||||
'company': company.id,
|
||||
'currency': company.currency.id,
|
||||
'number_sequ': self.prep_sequence().id,
|
||||
'start_date': date(2022, 5, 1),
|
||||
}])
|
||||
|
||||
Book.write(*[
|
||||
[book1],
|
||||
{
|
||||
'lines': [('create', [{
|
||||
'date': date(2022, 5, 1),
|
||||
'description': 'loss at sell',
|
||||
'category': category_out.id,
|
||||
'bookingtype': 'mvout',
|
||||
'amount': Decimal('10.0'),
|
||||
'booktransf': book2.id,
|
||||
'quantity': Decimal('0.0'),
|
||||
}])],
|
||||
},
|
||||
])
|
||||
self.assertEqual(book1.rec_name, 'Asset-Book | -10.00 usd | Open | 0.0000 u')
|
||||
self.assertEqual(len(book1.lines), 1)
|
||||
self.assertEqual(book1.lines[0].rec_name,
|
||||
'05/01/2022|to|-10.00 usd|loss at sell [Cash-Book | 0.00 usd | Open]|0.0000 u')
|
||||
self.assertEqual(book2.rec_name, 'Cash-Book | 0.00 usd | Open')
|
||||
self.assertEqual(len(book2.lines), 0)
|
||||
|
||||
Line.wfcheck(list(book1.lines))
|
||||
|
||||
self.assertEqual(book1.rec_name, 'Asset-Book | -10.00 usd | Open | 0.0000 u')
|
||||
self.assertEqual(len(book1.lines), 1)
|
||||
self.assertEqual(book1.lines[0].rec_name,
|
||||
'05/01/2022|to|-10.00 usd|loss at sell [Cash-Book | 10.00 usd | Open]|0.0000 u')
|
||||
self.assertEqual(book2.rec_name, 'Cash-Book | 10.00 usd | Open')
|
||||
self.assertEqual(len(book2.lines), 1)
|
||||
self.assertEqual(book2.lines[0].rec_name,
|
||||
'05/01/2022|from|10.00 usd|loss at sell [Asset-Book | -10.00 usd | Open | 0.0000 u]')
|
||||
|
||||
@with_transaction()
|
||||
def test_assetbook_check_mvin(self):
|
||||
""" create cashbook + line, bookingtype 'mvin'
|
||||
|
@ -1401,6 +1482,129 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase):
|
|||
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')
|
||||
|
||||
@with_transaction()
|
||||
def test_assetbook_split_in_category_and_assetbook_zero_quantity(self):
|
||||
""" splitbooking incoming to asset-cahbook,
|
||||
from category and asset-cashbook, zero qunatity to book
|
||||
gain/loss of a sell from asset-cashbook
|
||||
"""
|
||||
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'))
|
||||
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': 'spin',
|
||||
'date': date(2022, 5, 1),
|
||||
'splitlines': [('create', [{
|
||||
'amount': Decimal('5.0'),
|
||||
'splittype': 'cat',
|
||||
'description': 'gain on sell',
|
||||
'category': category.id,
|
||||
'quantity': Decimal('0.0'),
|
||||
}, {
|
||||
'amount': Decimal('6.0'),
|
||||
'splittype': 'tr',
|
||||
'description': 'transfer zero quantity',
|
||||
'booktransf': books[1].id,
|
||||
'quantity': Decimal('0.0'),
|
||||
}])],
|
||||
}])],
|
||||
}])
|
||||
|
||||
self.assertEqual(books[0].rec_name, 'Book 1 | 11.00 usd | Open | 0.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|Rev/Sp|11.00 usd|- [-]|0.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,
|
||||
'Rev/Sp|5.00 usd|gain on sell [Cat1]|0.00 u')
|
||||
self.assertEqual(books[0].lines[0].splitlines[0].booktransf, None)
|
||||
self.assertEqual(books[0].lines[0].splitlines[1].rec_name,
|
||||
'Rev/Sp|6.00 usd|transfer zero quantity [Book 2 | 0.00 usd | Open | 0.00 u]|0.00 u')
|
||||
self.assertEqual(books[0].lines[0].splitlines[1].booktransf.rec_name,
|
||||
'Book 2 | 0.00 usd | Open | 0.00 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 | 0.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|Rev/Sp|11.00 usd|- [-]|0.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,
|
||||
'Rev/Sp|5.00 usd|gain on sell [Cat1]|0.00 u')
|
||||
self.assertEqual(books[0].lines[0].splitlines[0].booktransf, None)
|
||||
self.assertEqual(books[0].lines[0].splitlines[1].rec_name,
|
||||
'Rev/Sp|6.00 usd|transfer zero quantity [Book 2 | -6.00 usd | Open | 0.00 u]|0.00 u')
|
||||
self.assertEqual(books[0].lines[0].splitlines[1].booktransf.rec_name,
|
||||
'Book 2 | -6.00 usd | Open | 0.00 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|transfer zero quantity [Book 1 | 11.00 usd | Open | 0.00 u]|0.00 u')
|
||||
self.assertEqual(books[0].lines[0].reference, None)
|
||||
|
||||
self.assertEqual(books[1].rec_name, 'Book 2 | -6.00 usd | Open | 0.00 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|transfer zero quantity [Book 1 | 11.00 usd | Open | 0.00 u]|0.00 u')
|
||||
|
||||
@with_transaction()
|
||||
def test_assetbook_split_in_catergory_asset_diff_unit(self):
|
||||
""" splitbooking incoming to asset-cahbook,
|
||||
|
@ -1744,7 +1948,7 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase):
|
|||
@with_transaction()
|
||||
def test_assetbook_split_out_category_and_assetbook(self):
|
||||
""" splitbooking outgoing,
|
||||
from asset-cashbook to asset-cahbook and to category
|
||||
from asset-cashbook to asset-cashbook and to category
|
||||
"""
|
||||
pool = Pool()
|
||||
Book = pool.get('cashbook.book')
|
||||
|
|
Loading…
Reference in a new issue