diff --git a/tests/test_book.py b/tests/test_book.py index 80377ad..b4441e3 100644 --- a/tests/test_book.py +++ b/tests/test_book.py @@ -471,6 +471,72 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): } ]) + @with_transaction() + def test_assetbook_check_sign_mismatch(self): + """ create cashbook + line, bookingtype 'in', + check detection of sign mismatch between quantity and amount + """ + pool = Pool() + Book = pool.get('cashbook.book') + Line = pool.get('cashbook.line') + Category = pool.get('cashbook.category') + BType = pool.get('cashbook.type') + + type_depot = self.prep_type('Depot', 'D') + BType.write(*[ + [type_depot], + { + 'feature': 'asset', + }]) + + category_in = 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') + + book, = 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), + 'lines': [('create', [{ + 'date': date(2022, 5, 1), + 'description': 'buy some', + 'category': category_in.id, + 'bookingtype': 'in', + 'amount': Decimal('1.0'), + 'quantity': Decimal('1.5'), + }])], + }]) + + self.assertEqual(book.rec_name, 'Asset-Book | 1.00 usd | Open') + self.assertEqual(len(book.lines), 1) + self.assertEqual(book.lines[0].amount, Decimal('1.0')) + self.assertEqual(book.lines[0].credit, Decimal('1.0')) + self.assertEqual(book.lines[0].debit, Decimal('0.0')) + self.assertEqual(book.lines[0].quantity, Decimal('1.5')) + self.assertEqual(book.lines[0].quantity_credit, Decimal('1.5')) + self.assertEqual(book.lines[0].quantity_debit, Decimal('0.0')) + + self.assertRaisesRegex(UserError, + "Quantity and Amount must with same sign for line 05/01/2022|Rev|1.00 usd|buy some [Cat1].", + Book.write, + *[ + [book], + { + 'lines': [('write', [book.lines[0]], { + 'quantity': Decimal('-1.5'), + })], + }]) + @with_transaction() def test_assetbook_check_bookingtype_mvout(self): """ create cashbook + line, bookingtype 'mvout' @@ -577,70 +643,4 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): self.assertEqual(book2.lines[0].reference.rec_name, '05/01/2022|to|-1.00 usd|Transfer Out [Asset-Book | 1.00 usd | Open]') self.assertEqual(len(book2.lines[0].references), 0) - @with_transaction() - def test_assetbook_check_sign_mismatch(self): - """ create cashbook + line, bookingtype 'in', - check detection of sign mismatch between quantity and amount - """ - pool = Pool() - Book = pool.get('cashbook.book') - Line = pool.get('cashbook.line') - Category = pool.get('cashbook.category') - BType = pool.get('cashbook.type') - - type_depot = self.prep_type('Depot', 'D') - BType.write(*[ - [type_depot], - { - 'feature': 'asset', - }]) - - category_in = 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') - - book, = 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), - 'lines': [('create', [{ - 'date': date(2022, 5, 1), - 'description': 'buy some', - 'category': category_in.id, - 'bookingtype': 'in', - 'amount': Decimal('1.0'), - 'quantity': Decimal('1.5'), - }])], - }]) - - self.assertEqual(book.rec_name, 'Asset-Book | 1.00 usd | Open') - self.assertEqual(len(book.lines), 1) - self.assertEqual(book.lines[0].amount, Decimal('1.0')) - self.assertEqual(book.lines[0].credit, Decimal('1.0')) - self.assertEqual(book.lines[0].debit, Decimal('0.0')) - self.assertEqual(book.lines[0].quantity, Decimal('1.5')) - self.assertEqual(book.lines[0].quantity_credit, Decimal('1.5')) - self.assertEqual(book.lines[0].quantity_debit, Decimal('0.0')) - - self.assertRaisesRegex(UserError, - "Quantity and Amount must with same sign for line 05/01/2022|Rev|1.00 usd|buy some [Cat1].", - Book.write, - *[ - [book], - { - 'lines': [('write', [book.lines[0]], { - 'quantity': Decimal('-1.5'), - })], - }]) - # end CbInvTestCase diff --git a/view/book_list.xml b/view/book_list.xml index 5250b1f..9d04bfd 100644 --- a/view/book_list.xml +++ b/view/book_list.xml @@ -5,10 +5,10 @@ full copyright notices and license terms. --> - - + + - + diff --git a/view/book_tree.xml b/view/book_tree.xml index cb3b367..c9ee764 100644 --- a/view/book_tree.xml +++ b/view/book_tree.xml @@ -5,7 +5,7 @@ full copyright notices and license terms. --> - + diff --git a/view/recon_form.xml b/view/recon_form.xml index 4aadfe5..f2fd252 100644 --- a/view/recon_form.xml +++ b/view/recon_form.xml @@ -4,8 +4,7 @@ The COPYRIGHT file at the top level of this repository contains the full copyright notices and license terms. --> - - +