diff --git a/line.py b/line.py index adfc1bd..517bea2 100644 --- a/line.py +++ b/line.py @@ -314,20 +314,33 @@ class Line(SecondUomMixin, metaclass=PoolMeta): self.amount / self.quantity ).quantize(Decimal(Decimal(1) / 10**digit)) - @fields.depends('cashbook', '_parent_cashbook.quantity_uom') + @fields.depends('feature', 'cashbook', '_parent_cashbook.quantity_uom', \ + 'booktransf', '_parent_booktransf.quantity_uom', '_parent_booktransf.feature') def on_change_with_quantity_uom(self, name=None): """ get quantity-unit of asset """ - if self.cashbook: - if self.cashbook.quantity_uom: - return self.cashbook.quantity_uom.id + if self.feature == 'asset': + if self.cashbook: + if self.cashbook.quantity_uom: + return self.cashbook.quantity_uom.id + else : + if self.booktransf: + if self.booktransf.feature == 'asset': + if self.booktransf.quantity_uom: + return self.booktransf.quantity_uom.id - @fields.depends('cashbook', '_parent_cashbook.quantity_digits') + @fields.depends('feature', 'cashbook', '_parent_cashbook.quantity_digits', \ + 'booktransf', '_parent_booktransf.quantity_digits', '_parent_booktransf.feature') def on_change_with_quantity_digits(self, name=None): """ get digits from cashbook """ - if self.cashbook: - return self.cashbook.quantity_digits + if self.feature == 'asset': + if self.cashbook: + return self.cashbook.quantity_digits + else : + if self.booktransf: + if self.booktransf.feature == 'asset': + return self.booktransf.quantity_digits return 4 @classmethod diff --git a/splitline.py b/splitline.py index efeca8b..539124d 100644 --- a/splitline.py +++ b/splitline.py @@ -47,23 +47,32 @@ class SplitLine(SecondUomMixin, metaclass=PoolMeta): } return recname - @fields.depends('line', '_parent_line.cashbook', 'booktransf', '_parent_booktransf.quantity_uom') + @fields.depends('line', '_parent_line.cashbook', 'booktransf', \ + '_parent_booktransf.feature', '_parent_booktransf.quantity_uom') def on_change_with_quantity_uom(self, name=None): """ get quantity-unit of asset """ if self.line: - if self.line.cashbook.quantity_uom: - return self.cashbook.quantity_uom.id + if self.line.cashbook.feature == 'asset': + if self.line.cashbook.quantity_uom: + return self.cashbook.quantity_uom.id if self.booktransf: - if self.booktransf.quantity_uom: - return self.booktransf.quantity_uom.id + if self.booktransf.feature == 'asset': + if self.booktransf.quantity_uom: + return self.booktransf.quantity_uom.id - @fields.depends('line', '_parent_line.cashbook') + @fields.depends('line', '_parent_line.cashbook', 'booktransf', \ + '_parent_booktransf.feature', '_parent_booktransf.quantity_digits') def on_change_with_quantity_digits(self, name=None): """ get digits from cashbook """ if self.line: - return self.line.cashbook.quantity_digits + if self.line.cashbook.feature == 'asset': + return self.line.cashbook.quantity_digits + if self.booktransf: + if self.booktransf.feature == 'asset': + return self.booktransf.quantity_digits + return 4 @classmethod diff --git a/tests/test_book.py b/tests/test_book.py index 08e8f80..01df667 100644 --- a/tests/test_book.py +++ b/tests/test_book.py @@ -585,6 +585,96 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): book.on_change_asset() self.assertEqual(book.quantity_uom.rec_name, 'Unit') + @with_transaction() + def test_assetbook_quantity_digits(self): + """ check selection of quantity-digits + """ + pool = Pool() + Book = pool.get('cashbook.book') + BType = pool.get('cashbook.type') + + company = self.prep_company() + category = self.prep_category(cattype='in') + type_depot = self.prep_type('Depot', 'D') + type_cash = self.prep_type('Cash', 'C') + BType.write(*[ + [type_depot], + { + 'feature': 'asset', + 'name': 'Asset', + 'short': 'A', + }]) + + asset = self.prep_asset_item( + company=company, + product = self.prep_asset_product(name='Product 1')) + self.assertEqual(asset.symbol, 'usd/u') + + books = Book.create([{ + 'name': 'Book 1', + 'btype': type_depot.id, + 'company': company.id, + 'currency': company.currency.id, + 'number_sequ': self.prep_sequence().id, + 'asset': asset.id, + 'quantity_uom': asset.uom.id, + 'quantity_digits': 3, + 'start_date': date(2022, 5, 1), + }, { + 'name': 'Book 2', + 'btype': type_cash.id, + 'company': company.id, + 'currency': company.currency.id, + 'number_sequ': self.prep_sequence().id, + 'start_date': date(2022, 5, 1), + }]) + self.assertEqual(books[0].rec_name, 'Book 1 | 0.00 usd | Open | 0.000 u') + self.assertEqual(books[1].rec_name, 'Book 2 | 0.00 usd | Open') + + Book.write(*[ + [books[0]], + { + 'lines': [('create', [{ + 'bookingtype': 'in', + 'date': date(2022, 5, 1), + 'category': category.id, + 'amount': Decimal('1.0'), + 'quantity': Decimal('1.0'), + }])], + }]) + self.assertEqual(books[0].lines[0].rec_name, + '05/01/2022|Rev|1.00 usd|- [Cat1]|1.000 u') + self.assertEqual(books[0].lines[0].quantity_digits, 3) + + Book.write(*[ + [books[1]], + { + 'lines': [('create', [{ + 'bookingtype': 'in', + 'date': date(2022, 5, 1), + 'category': category.id, + 'amount': Decimal('1.0'), + }])], + }]) + self.assertEqual(books[1].lines[0].rec_name, + '05/01/2022|Rev|1.00 usd|- [Cat1]') + self.assertEqual(books[1].lines[0].quantity_digits, 4) + + Book.write(*[ + [books[1]], + { + 'lines': [('create', [{ + 'bookingtype': 'mvin', + 'date': date(2022, 5, 1), + 'amount': Decimal('1.0'), + 'quantity': Decimal('1.0'), + 'booktransf': books[0].id, + }])], + }]) + self.assertEqual(books[1].lines[1].rec_name, + '05/01/2022|from|1.00 usd|- [Book 1 | 1.00 usd | Open | 1.000 u]') + self.assertEqual(books[1].lines[1].quantity_digits, 3) + @with_transaction() def test_assetbook_book_with_asset(self): """ create cashbook, set 'btype' to asset