line: quantity für transferbuchung + test
This commit is contained in:
parent
d04ba0c385
commit
e0895f3e4c
2 changed files with 104 additions and 3 deletions
21
line.py
21
line.py
|
@ -16,13 +16,20 @@ class Line(metaclass=PoolMeta):
|
||||||
quantity = fields.Numeric(string='Quantity',
|
quantity = fields.Numeric(string='Quantity',
|
||||||
digits=(16, Eval('quantity_digits', 4)),
|
digits=(16, Eval('quantity_digits', 4)),
|
||||||
states={
|
states={
|
||||||
'required': Eval('feature', '') == 'asset',
|
'required': Or(
|
||||||
'invisible': Eval('feature', '') != 'asset',
|
Eval('feature', '') == 'asset',
|
||||||
|
Eval('booktransf_feature', '') == 'asset',
|
||||||
|
),
|
||||||
|
'invisible': ~Or(
|
||||||
|
Eval('feature', '') == 'asset',
|
||||||
|
Eval('booktransf_feature', '') == 'asset',
|
||||||
|
),
|
||||||
'readonly': Or(
|
'readonly': Or(
|
||||||
STATES['readonly'],
|
STATES['readonly'],
|
||||||
Eval('bookingtype', '').in_(['spin', 'spout']),
|
Eval('bookingtype', '').in_(['spin', 'spout']),
|
||||||
),
|
),
|
||||||
}, depends=DEPENDS+['feature', 'quantity_digits', 'bookingtype'])
|
}, depends=DEPENDS+['feature', 'booktransf_feature',
|
||||||
|
'quantity_digits', 'bookingtype'])
|
||||||
quantity_digits = fields.Function(fields.Integer(string='Digits',
|
quantity_digits = fields.Function(fields.Integer(string='Digits',
|
||||||
readonly=True, states={'invisible': True}),
|
readonly=True, states={'invisible': True}),
|
||||||
'on_change_with_quantity_digits')
|
'on_change_with_quantity_digits')
|
||||||
|
@ -39,6 +46,14 @@ class Line(metaclass=PoolMeta):
|
||||||
}, depends=['currency_digits', 'quantity_digits', 'feature']),
|
}, depends=['currency_digits', 'quantity_digits', 'feature']),
|
||||||
'on_change_with_asset_rate')
|
'on_change_with_asset_rate')
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_counterpart_values(cls, line, values={}):
|
||||||
|
""" add quantity to counterpart
|
||||||
|
"""
|
||||||
|
result = super(Line, cls).get_counterpart_values(line, values)
|
||||||
|
result['quantity'] = line.quantity
|
||||||
|
return result
|
||||||
|
|
||||||
@fields.depends('quantity', 'amount', 'currency_digits', 'quantity_digits')
|
@fields.depends('quantity', 'amount', 'currency_digits', 'quantity_digits')
|
||||||
def on_change_with_asset_rate(self, name=None):
|
def on_change_with_asset_rate(self, name=None):
|
||||||
""" get rate
|
""" get rate
|
||||||
|
|
|
@ -463,4 +463,90 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase):
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
|
|
||||||
|
@with_transaction()
|
||||||
|
def test_assetbook_check_bookingtype_mvout(self):
|
||||||
|
""" create cashbook + line, bookingtype 'mvout'
|
||||||
|
"""
|
||||||
|
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_in = self.prep_category(cattype='in')
|
||||||
|
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')
|
||||||
|
|
||||||
|
book2, = 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),
|
||||||
|
}])
|
||||||
|
|
||||||
|
book, = Book.create([{
|
||||||
|
'name': 'Book 1',
|
||||||
|
'btype': type_cash.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': 'Transfer Out',
|
||||||
|
'category': category_out.id,
|
||||||
|
'bookingtype': 'mvout',
|
||||||
|
'amount': Decimal('1.0'),
|
||||||
|
'booktransf': book2.id,
|
||||||
|
'quantity': Decimal('1.5'),
|
||||||
|
}])],
|
||||||
|
}])
|
||||||
|
self.assertEqual(book.rec_name, 'Book 1 | -1.00 usd | Open')
|
||||||
|
self.assertEqual(len(book.lines), 1)
|
||||||
|
self.assertEqual(book.lines[0].quantity, Decimal('1.5'))
|
||||||
|
self.assertEqual(len(book2.lines), 0)
|
||||||
|
self.assertEqual(book.lines[0].rec_name, '05/01/2022|to|-1.00 usd|Transfer Out [Asset-Book | 0.00 usd | Open]')
|
||||||
|
self.assertEqual(len(book.lines[0].references), 0)
|
||||||
|
|
||||||
|
# check counterpart
|
||||||
|
self.assertEqual(book.lines[0].booktransf.rec_name, 'Asset-Book | 0.00 usd | Open')
|
||||||
|
self.assertEqual(book.lines[0].booktransf.btype.feature, 'asset')
|
||||||
|
self.assertEqual(book.lines[0].booktransf_feature, 'asset')
|
||||||
|
|
||||||
|
# set line to 'checked', this creates the counterpart
|
||||||
|
Line.wfcheck(list(book.lines))
|
||||||
|
|
||||||
|
self.assertEqual(len(book.lines), 1)
|
||||||
|
self.assertEqual(book.lines[0].rec_name, '05/01/2022|to|-1.00 usd|Transfer Out [Asset-Book | 1.00 usd | Open]')
|
||||||
|
self.assertEqual(book.lines[0].state, 'check')
|
||||||
|
self.assertEqual(book.lines[0].quantity, Decimal('1.5'))
|
||||||
|
self.assertEqual(len(book.lines[0].references), 1)
|
||||||
|
self.assertEqual(book.lines[0].reference, None)
|
||||||
|
self.assertEqual(book.lines[0].references[0].id, book2.lines[0].id)
|
||||||
|
|
||||||
|
self.assertEqual(len(book2.lines), 1)
|
||||||
|
self.assertEqual(book2.lines[0].rec_name, '05/01/2022|from|1.00 usd|Transfer Out [Book 1 | -1.00 usd | Open]')
|
||||||
|
self.assertEqual(book2.lines[0].state, 'check')
|
||||||
|
self.assertEqual(book2.lines[0].quantity, Decimal('1.5'))
|
||||||
|
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)
|
||||||
|
|
||||||
# end CbInvTestCase
|
# end CbInvTestCase
|
||||||
|
|
Loading…
Reference in a new issue