line/splitline: optimize value-update on create/write

This commit is contained in:
Frederik Jaeckel 2023-01-15 23:05:43 +01:00
parent 82ae7d7bca
commit 3b289b7944
4 changed files with 97 additions and 34 deletions

View file

@ -16,6 +16,57 @@ class SplitLineTestCase(ModuleTestCase):
'Test split line module'
module = 'cashbook'
@with_transaction()
def test_splitline_in_category(self):
""" add book, check splitbooking - incoming
"""
pool = Pool()
Book = pool.get('cashbook.book')
Line = pool.get('cashbook.line')
types = self.prep_type()
category1 = self.prep_category(cattype='in')
company = self.prep_company()
party = self.prep_party()
book, = Book.create([{
'name': 'Book 1',
'btype': types.id,
'company': company.id,
'currency': company.currency.id,
'number_sequ': self.prep_sequence().id,
'start_date': date(2022, 5, 1),
}])
self.assertEqual(book.rec_name, 'Book 1 | 0.00 usd | Open')
self.assertEqual(len(book.lines), 0)
Book.write(*[
[book],
{
'lines': [('create', [{
'bookingtype': 'spin',
'date': date(2022, 5, 1),
'splitlines': [('create', [{
'amount': Decimal('5.0'),
'splittype': 'cat',
'description': 'from category',
'category': category1.id,
}, {
'amount': Decimal('6.0'),
'splittype': 'cat',
'description': 'from cashbook',
'category': category1.id,
}])],
}])],
}])
self.assertEqual(len(book.lines), 1)
self.assertEqual(book.lines[0].rec_name, '05/01/2022|Rev/Sp|11.00 usd|- [-]')
self.assertEqual(book.lines[0].category, None)
self.assertEqual(len(book.lines[0].splitlines), 2)
self.assertEqual(book.lines[0].splitlines[0].rec_name,
'Rev/Sp|5.00 usd|from category [Cat1]')
self.assertEqual(book.lines[0].splitlines[1].rec_name,
'Rev/Sp|6.00 usd|from cashbook [Cat1]')
@with_transaction()
def test_splitline_category_and_transfer(self):
""" add book, line, two split-lines,