line/splitline: fixed selection of quantity-uom/digits

This commit is contained in:
Frederik Jaeckel 2023-02-01 14:29:48 +01:00
parent e79c68e75b
commit e38d02ff9d
3 changed files with 126 additions and 14 deletions

17
line.py
View file

@ -314,20 +314,33 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
self.amount / self.quantity self.amount / self.quantity
).quantize(Decimal(Decimal(1) / 10**digit)) ).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): def on_change_with_quantity_uom(self, name=None):
""" get quantity-unit of asset """ get quantity-unit of asset
""" """
if self.feature == 'asset':
if self.cashbook: if self.cashbook:
if self.cashbook.quantity_uom: if self.cashbook.quantity_uom:
return self.cashbook.quantity_uom.id 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): def on_change_with_quantity_digits(self, name=None):
""" get digits from cashbook """ get digits from cashbook
""" """
if self.feature == 'asset':
if self.cashbook: if self.cashbook:
return self.cashbook.quantity_digits return self.cashbook.quantity_digits
else :
if self.booktransf:
if self.booktransf.feature == 'asset':
return self.booktransf.quantity_digits
return 4 return 4
@classmethod @classmethod

View file

@ -47,23 +47,32 @@ class SplitLine(SecondUomMixin, metaclass=PoolMeta):
} }
return recname 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): def on_change_with_quantity_uom(self, name=None):
""" get quantity-unit of asset """ get quantity-unit of asset
""" """
if self.line: if self.line:
if self.line.cashbook.feature == 'asset':
if self.line.cashbook.quantity_uom: if self.line.cashbook.quantity_uom:
return self.cashbook.quantity_uom.id return self.cashbook.quantity_uom.id
if self.booktransf: if self.booktransf:
if self.booktransf.feature == 'asset':
if self.booktransf.quantity_uom: if self.booktransf.quantity_uom:
return self.booktransf.quantity_uom.id 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): def on_change_with_quantity_digits(self, name=None):
""" get digits from cashbook """ get digits from cashbook
""" """
if self.line: if self.line:
if self.line.cashbook.feature == 'asset':
return self.line.cashbook.quantity_digits return self.line.cashbook.quantity_digits
if self.booktransf:
if self.booktransf.feature == 'asset':
return self.booktransf.quantity_digits
return 4 return 4
@classmethod @classmethod

View file

@ -585,6 +585,96 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase):
book.on_change_asset() book.on_change_asset()
self.assertEqual(book.quantity_uom.rec_name, 'Unit') 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() @with_transaction()
def test_assetbook_book_with_asset(self): def test_assetbook_book_with_asset(self):
""" create cashbook, set 'btype' to asset """ create cashbook, set 'btype' to asset