line: quantity_credit/debit + test
book: berechnet 'quantity' aus quantity_credit/debit
This commit is contained in:
parent
e0895f3e4c
commit
e94a869166
6 changed files with 210 additions and 133 deletions
5
book.py
5
book.py
|
@ -180,10 +180,11 @@ class Book(SymbolMixin, metaclass=PoolMeta):
|
|||
).select(
|
||||
tab_book.id, # 0
|
||||
Coalesce(Sum(Case(
|
||||
(tab_line.date <= query_date, tab_line.quantity),
|
||||
(tab_line.date <= query_date,
|
||||
tab_line.quantity_credit - tab_line.quantity_debit),
|
||||
else_ = Decimal('0.0'),
|
||||
)), Decimal('0.0')).as_('quantity'), # 1
|
||||
Sum(tab_line.quantity).as_('quantity_all'), # 2
|
||||
Sum(tab_line.quantity_credit - tab_line.quantity_debit).as_('quantity_all'), # 2
|
||||
Coalesce(tab_rate.rate, Decimal('0.0')).as_('rate'), # 3
|
||||
tab_book.currency, # 4
|
||||
tab_cur.digits.as_('currency_digits'), # 5
|
||||
|
|
69
line.py
69
line.py
|
@ -9,27 +9,37 @@ from trytond.pool import PoolMeta
|
|||
from trytond.pyson import Eval, Or, If
|
||||
from trytond.modules.cashbook.line import STATES, DEPENDS
|
||||
|
||||
STATESQ = {
|
||||
'required': Or(
|
||||
Eval('feature', '') == 'asset',
|
||||
Eval('booktransf_feature', '') == 'asset',
|
||||
),
|
||||
'invisible': ~Or(
|
||||
Eval('feature', '') == 'asset',
|
||||
Eval('booktransf_feature', '') == 'asset',
|
||||
),
|
||||
'readonly': Or(
|
||||
STATES['readonly'],
|
||||
Eval('bookingtype', '').in_(['spin', 'spout']),
|
||||
),
|
||||
}
|
||||
DEPENDSQ = DEPENDS+['feature', 'booktransf_feature',
|
||||
'quantity_digits', 'bookingtype']
|
||||
|
||||
|
||||
class Line(metaclass=PoolMeta):
|
||||
__name__ = 'cashbook.line'
|
||||
|
||||
quantity = fields.Numeric(string='Quantity',
|
||||
digits=(16, Eval('quantity_digits', 4)),
|
||||
states={
|
||||
'required': Or(
|
||||
Eval('feature', '') == 'asset',
|
||||
Eval('booktransf_feature', '') == 'asset',
|
||||
),
|
||||
'invisible': ~Or(
|
||||
Eval('feature', '') == 'asset',
|
||||
Eval('booktransf_feature', '') == 'asset',
|
||||
),
|
||||
'readonly': Or(
|
||||
STATES['readonly'],
|
||||
Eval('bookingtype', '').in_(['spin', 'spout']),
|
||||
),
|
||||
}, depends=DEPENDS+['feature', 'booktransf_feature',
|
||||
'quantity_digits', 'bookingtype'])
|
||||
states=STATESQ, depends=DEPENDSQ)
|
||||
quantity_credit = fields.Numeric(string='Quantity Credit',
|
||||
digits=(16, Eval('quantity_digits', 4)),
|
||||
states=STATESQ, depends=DEPENDSQ)
|
||||
quantity_debit = fields.Numeric(string='Quantity Debit',
|
||||
digits=(16, Eval('quantity_digits', 4)),
|
||||
states=STATESQ, depends=DEPENDSQ)
|
||||
|
||||
quantity_digits = fields.Function(fields.Integer(string='Digits',
|
||||
readonly=True, states={'invisible': True}),
|
||||
'on_change_with_quantity_digits')
|
||||
|
@ -46,6 +56,35 @@ class Line(metaclass=PoolMeta):
|
|||
}, depends=['currency_digits', 'quantity_digits', 'feature']),
|
||||
'on_change_with_asset_rate')
|
||||
|
||||
@classmethod
|
||||
def get_debit_credit(cls, values):
|
||||
""" compute quantity_debit/quantity_credit from quantity
|
||||
"""
|
||||
values2 = super(Line, cls).get_debit_credit(values)
|
||||
|
||||
if isinstance(values, dict):
|
||||
type_ = values.get('bookingtype', None)
|
||||
quantity = values.get('quantity', None)
|
||||
else :
|
||||
type_ = getattr(values, 'bookingtype', None)
|
||||
quantity = getattr(values, 'quantity', None)
|
||||
|
||||
if type_:
|
||||
if quantity is not None:
|
||||
if type_ in ['in', 'mvin', 'spin']:
|
||||
values2.update({
|
||||
'quantity_debit': Decimal('0.0'),
|
||||
'quantity_credit': quantity,
|
||||
})
|
||||
elif type_ in ['out', 'mvout', 'spout']:
|
||||
values2.update({
|
||||
'quantity_debit': quantity,
|
||||
'quantity_credit': Decimal('0.0'),
|
||||
})
|
||||
else :
|
||||
raise ValueError('invalid "bookingtype"')
|
||||
return values2
|
||||
|
||||
@classmethod
|
||||
def get_counterpart_values(cls, line, values={}):
|
||||
""" add quantity to counterpart
|
||||
|
|
|
@ -122,6 +122,14 @@ msgctxt "field:cashbook.line,quantity:"
|
|||
msgid "Quantity"
|
||||
msgstr "Anzahl"
|
||||
|
||||
msgctxt "field:cashbook.line,quantity_credit:"
|
||||
msgid "Quantity Credit"
|
||||
msgstr "Anzahlgutschrift"
|
||||
|
||||
msgctxt "field:cashbook.line,quantity_debit:"
|
||||
msgid "Quantity Debit"
|
||||
msgstr "Anzahllastschrift"
|
||||
|
||||
msgctxt "field:cashbook.line,quantity_symbol:"
|
||||
msgid "Symbol"
|
||||
msgstr "Symbol"
|
||||
|
|
240
locale/en.po
240
locale/en.po
|
@ -1,116 +1,124 @@
|
|||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "model:ir.message,text:msg_btype_asset"
|
||||
msgid "Asset"
|
||||
msgstr "Asset"
|
||||
|
||||
msgctxt "view:cashbook.book:"
|
||||
msgid "Asset"
|
||||
msgstr "Asset"
|
||||
|
||||
msgctxt "view:cashbook.book:"
|
||||
msgid "Quantity"
|
||||
msgstr "Quantity"
|
||||
|
||||
msgctxt "view:cashbook.book:"
|
||||
msgid "Current valuation of the investment"
|
||||
msgstr "Current valuation of the investment"
|
||||
|
||||
msgctxt "field:cashbook.book,asset:"
|
||||
msgid "Asset"
|
||||
msgstr "Asset"
|
||||
|
||||
msgctxt "field:cashbook.book,quantity_digits:"
|
||||
msgid "Digits"
|
||||
msgstr "Digits"
|
||||
|
||||
msgctxt "help:cashbook.book,quantity_digits:"
|
||||
msgid "Quantity Digits"
|
||||
msgstr "Quantity Digits"
|
||||
|
||||
msgctxt "help:cashbook.book,asset_uomcat:"
|
||||
msgid "UOM Category"
|
||||
msgstr "UOM Category"
|
||||
|
||||
msgctxt "field:cashbook.book,quantity_uom:"
|
||||
msgid "UOM"
|
||||
msgstr "UOM"
|
||||
|
||||
msgctxt "field:cashbook.book,symbol:"
|
||||
msgid "Symbol"
|
||||
msgstr "Symbol"
|
||||
|
||||
msgctxt "field:cashbook.book,asset_symbol:"
|
||||
msgid "Symbol"
|
||||
msgstr "Symbol"
|
||||
|
||||
msgctxt "field:cashbook.book,quantity:"
|
||||
msgid "Quantity"
|
||||
msgstr "Quantity"
|
||||
|
||||
msgctxt "help:cashbook.book,quantity:"
|
||||
msgid "Quantity of assets until to date"
|
||||
msgstr "Quantity of assets until to date"
|
||||
|
||||
msgctxt "field:cashbook.book,quantity_all:"
|
||||
msgid "Total Quantity"
|
||||
msgstr "Total Quantity"
|
||||
|
||||
msgctxt "help:cashbook.book,quantity_all:"
|
||||
msgid "Total quantity of all assets"
|
||||
msgstr "Total quantity of all assets"
|
||||
|
||||
msgctxt "field:cashbook.book,current_value:"
|
||||
msgid "Value"
|
||||
msgstr "Value"
|
||||
|
||||
msgctxt "help:cashbook.book,current_value:"
|
||||
msgid "Valuation of the investment based on the current stock market price."
|
||||
msgstr "Valuation of the investment based on the current stock market price."
|
||||
|
||||
msgctxt "field:cashbook.book,current_value_ref:"
|
||||
msgid "Value (Ref.)"
|
||||
msgstr "Value (Ref.)"
|
||||
|
||||
msgctxt "help:cashbook.book,current_value_ref:"
|
||||
msgid "Valuation of the investment based on the current stock exchange price, converted into the company currency."
|
||||
msgstr "Valuation of the investment based on the current stock exchange price, converted into the company currency."
|
||||
|
||||
msgctxt "field:cashbook.book,diff_amount:"
|
||||
msgid "Difference"
|
||||
msgstr "Difference"
|
||||
|
||||
msgctxt "help:cashbook.book,diff_amount:"
|
||||
msgid "Difference between acquisition value and current value"
|
||||
msgstr "Difference between acquisition value and current value"
|
||||
|
||||
msgctxt "field:cashbook.book,diff_percent:"
|
||||
msgid "Percent"
|
||||
msgstr "Percent"
|
||||
|
||||
msgctxt "help:cashbook.book,diff_percent:"
|
||||
msgid "percentage performance since acquisition"
|
||||
msgstr "percentage performance since acquisition"
|
||||
|
||||
msgctxt "field:cashbook.book,current_rate:"
|
||||
msgid "Rate"
|
||||
msgstr "Rate"
|
||||
|
||||
msgctxt "help:cashbook.book,current_rate:"
|
||||
msgid "Rate per unit of investment based on current stock exchange price."
|
||||
msgstr "Rate per unit of investment based on current stock exchange price."
|
||||
|
||||
msgctxt "field:cashbook.line,quantity_digits:"
|
||||
msgid "Digits"
|
||||
msgstr "Digits"
|
||||
|
||||
msgctxt "field:cashbook.line,quantity:"
|
||||
msgid "Quantity"
|
||||
msgstr "Quantity"
|
||||
|
||||
msgctxt "field:cashbook.line,quantity_symbol:"
|
||||
msgid "Symbol"
|
||||
msgstr "Symbol"
|
||||
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "model:ir.message,text:msg_btype_asset"
|
||||
msgid "Asset"
|
||||
msgstr "Asset"
|
||||
|
||||
msgctxt "view:cashbook.book:"
|
||||
msgid "Asset"
|
||||
msgstr "Asset"
|
||||
|
||||
msgctxt "view:cashbook.book:"
|
||||
msgid "Quantity"
|
||||
msgstr "Quantity"
|
||||
|
||||
msgctxt "view:cashbook.book:"
|
||||
msgid "Current valuation of the investment"
|
||||
msgstr "Current valuation of the investment"
|
||||
|
||||
msgctxt "field:cashbook.book,asset:"
|
||||
msgid "Asset"
|
||||
msgstr "Asset"
|
||||
|
||||
msgctxt "field:cashbook.book,quantity_digits:"
|
||||
msgid "Digits"
|
||||
msgstr "Digits"
|
||||
|
||||
msgctxt "help:cashbook.book,quantity_digits:"
|
||||
msgid "Quantity Digits"
|
||||
msgstr "Quantity Digits"
|
||||
|
||||
msgctxt "help:cashbook.book,asset_uomcat:"
|
||||
msgid "UOM Category"
|
||||
msgstr "UOM Category"
|
||||
|
||||
msgctxt "field:cashbook.book,quantity_uom:"
|
||||
msgid "UOM"
|
||||
msgstr "UOM"
|
||||
|
||||
msgctxt "field:cashbook.book,symbol:"
|
||||
msgid "Symbol"
|
||||
msgstr "Symbol"
|
||||
|
||||
msgctxt "field:cashbook.book,asset_symbol:"
|
||||
msgid "Symbol"
|
||||
msgstr "Symbol"
|
||||
|
||||
msgctxt "field:cashbook.book,quantity:"
|
||||
msgid "Quantity"
|
||||
msgstr "Quantity"
|
||||
|
||||
msgctxt "help:cashbook.book,quantity:"
|
||||
msgid "Quantity of assets until to date"
|
||||
msgstr "Quantity of assets until to date"
|
||||
|
||||
msgctxt "field:cashbook.book,quantity_all:"
|
||||
msgid "Total Quantity"
|
||||
msgstr "Total Quantity"
|
||||
|
||||
msgctxt "help:cashbook.book,quantity_all:"
|
||||
msgid "Total quantity of all assets"
|
||||
msgstr "Total quantity of all assets"
|
||||
|
||||
msgctxt "field:cashbook.book,current_value:"
|
||||
msgid "Value"
|
||||
msgstr "Value"
|
||||
|
||||
msgctxt "help:cashbook.book,current_value:"
|
||||
msgid "Valuation of the investment based on the current stock market price."
|
||||
msgstr "Valuation of the investment based on the current stock market price."
|
||||
|
||||
msgctxt "field:cashbook.book,current_value_ref:"
|
||||
msgid "Value (Ref.)"
|
||||
msgstr "Value (Ref.)"
|
||||
|
||||
msgctxt "help:cashbook.book,current_value_ref:"
|
||||
msgid "Valuation of the investment based on the current stock exchange price, converted into the company currency."
|
||||
msgstr "Valuation of the investment based on the current stock exchange price, converted into the company currency."
|
||||
|
||||
msgctxt "field:cashbook.book,diff_amount:"
|
||||
msgid "Difference"
|
||||
msgstr "Difference"
|
||||
|
||||
msgctxt "help:cashbook.book,diff_amount:"
|
||||
msgid "Difference between acquisition value and current value"
|
||||
msgstr "Difference between acquisition value and current value"
|
||||
|
||||
msgctxt "field:cashbook.book,diff_percent:"
|
||||
msgid "Percent"
|
||||
msgstr "Percent"
|
||||
|
||||
msgctxt "help:cashbook.book,diff_percent:"
|
||||
msgid "percentage performance since acquisition"
|
||||
msgstr "percentage performance since acquisition"
|
||||
|
||||
msgctxt "field:cashbook.book,current_rate:"
|
||||
msgid "Rate"
|
||||
msgstr "Rate"
|
||||
|
||||
msgctxt "help:cashbook.book,current_rate:"
|
||||
msgid "Rate per unit of investment based on current stock exchange price."
|
||||
msgstr "Rate per unit of investment based on current stock exchange price."
|
||||
|
||||
msgctxt "field:cashbook.line,quantity_digits:"
|
||||
msgid "Digits"
|
||||
msgstr "Digits"
|
||||
|
||||
msgctxt "field:cashbook.line,quantity:"
|
||||
msgid "Quantity"
|
||||
msgstr "Quantity"
|
||||
|
||||
msgctxt "field:cashbook.line,quantity_credit:"
|
||||
msgid "Quantity Credit"
|
||||
msgstr "Quantity Credit"
|
||||
|
||||
msgctxt "field:cashbook.line,quantity_debit:"
|
||||
msgid "Quantity Debit"
|
||||
msgstr "Quantity Debit"
|
||||
|
||||
msgctxt "field:cashbook.line,quantity_symbol:"
|
||||
msgid "Symbol"
|
||||
msgstr "Symbol"
|
||||
|
||||
|
|
|
@ -55,6 +55,7 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase):
|
|||
"""
|
||||
pool = Pool()
|
||||
Book = pool.get('cashbook.book')
|
||||
Line = pool.get('cashbook.line')
|
||||
BType = pool.get('cashbook.type')
|
||||
Asset = pool.get('investment.asset')
|
||||
|
||||
|
@ -129,17 +130,24 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase):
|
|||
|
||||
self.assertEqual(book.lines[0].amount, Decimal('2.5'))
|
||||
self.assertEqual(book.lines[0].quantity, Decimal('1.453'))
|
||||
self.assertEqual(book.lines[0].quantity_credit, Decimal('1.453'))
|
||||
self.assertEqual(book.lines[0].quantity_debit, Decimal('0.0'))
|
||||
self.assertEqual(book.lines[0].quantity_digits, 3)
|
||||
self.assertEqual(book.lines[0].quantity_uom.symbol, 'u')
|
||||
|
||||
self.assertEqual(book.lines[1].amount, Decimal('4.0'))
|
||||
self.assertEqual(book.lines[1].quantity, Decimal('3.3'))
|
||||
self.assertEqual(book.lines[1].quantity_credit, Decimal('3.3'))
|
||||
self.assertEqual(book.lines[1].quantity_debit, Decimal('0.0'))
|
||||
self.assertEqual(book.lines[1].quantity_digits, 3)
|
||||
self.assertEqual(book.lines[1].quantity_uom.symbol, 'u')
|
||||
|
||||
self.assertEqual(book.symbol, '€/u')
|
||||
self.assertEqual(book.asset.rec_name, 'Product 1 | 2.8000 usd/u | 05/02/2022')
|
||||
|
||||
# wf --> check
|
||||
Line.wfcheck(book.lines)
|
||||
|
||||
# check quantities at cashbook
|
||||
with Transaction().set_context({
|
||||
'qdate': date(2022, 5, 5),
|
||||
|
@ -466,6 +474,7 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase):
|
|||
@with_transaction()
|
||||
def test_assetbook_check_bookingtype_mvout(self):
|
||||
""" create cashbook + line, bookingtype 'mvout'
|
||||
transfer from cash to depot (buy asset, pay from cash)
|
||||
"""
|
||||
pool = Pool()
|
||||
Book = pool.get('cashbook.book')
|
||||
|
@ -537,7 +546,10 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase):
|
|||
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].bookingtype, 'mvout')
|
||||
self.assertEqual(book.lines[0].quantity, Decimal('1.5'))
|
||||
self.assertEqual(book.lines[0].quantity_credit, Decimal('0.0'))
|
||||
self.assertEqual(book.lines[0].quantity_debit, 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)
|
||||
|
@ -546,6 +558,10 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase):
|
|||
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].quantity_credit, Decimal('1.5'))
|
||||
self.assertEqual(book2.lines[0].quantity_debit, Decimal('0.0'))
|
||||
self.assertEqual(book2.lines[0].bookingtype, 'mvin')
|
||||
self.assertEqual(book2.lines[0].asset_rate, Decimal('0.6667'))
|
||||
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)
|
||||
|
||||
|
|
|
@ -10,6 +10,11 @@ full copyright notices and license terms. -->
|
|||
<label name="asset_rate"/>
|
||||
<field name="asset_rate" symbol="cashbook"/>
|
||||
|
||||
<label name="quantity_credit" />
|
||||
<field name="quantity_credit" symbol="quantity_uom"/>
|
||||
<label name="quantity_debit"/>
|
||||
<field name="quantity_debit" symbol="quantity_uom"/>
|
||||
|
||||
<field name="quantity_digits"/>
|
||||
<newline/>
|
||||
</xpath>
|
||||
|
|
Loading…
Reference in a new issue