line: formatting, fix - on_change_with_quantity_digits()
This commit is contained in:
parent
f7109b013f
commit
6c1fac8672
1 changed files with 73 additions and 49 deletions
102
line.py
102
line.py
|
@ -52,24 +52,29 @@ DEPENDSQ2 = ['feature', 'quantity_digits', 'bookingtype']
|
|||
class Line(SecondUomMixin, metaclass=PoolMeta):
|
||||
__name__ = 'cashbook.line'
|
||||
|
||||
quantity = fields.Numeric(string='Quantity',
|
||||
quantity = fields.Numeric(
|
||||
string='Quantity',
|
||||
digits=(16, Eval('quantity_digits', 4)),
|
||||
states=STATESQ1B, depends=DEPENDSQ1+['splitline_has_quantity'])
|
||||
quantity_credit = fields.Numeric(string='Quantity Credit',
|
||||
quantity_credit = fields.Numeric(
|
||||
string='Quantity Credit',
|
||||
digits=(16, Eval('quantity_digits', 4)), readonly=True,
|
||||
states=STATESQ2, depends=DEPENDSQ2)
|
||||
quantity_debit = fields.Numeric(string='Quantity Debit',
|
||||
quantity_debit = fields.Numeric(
|
||||
string='Quantity Debit',
|
||||
digits=(16, Eval('quantity_digits', 4)), readonly=True,
|
||||
states=STATESQ2, depends=DEPENDSQ2)
|
||||
|
||||
quantity_digits = fields.Function(fields.Integer(string='Digits',
|
||||
quantity_digits = fields.Function(fields.Integer(
|
||||
string='Digits',
|
||||
readonly=True, states={'invisible': True}),
|
||||
'on_change_with_quantity_digits')
|
||||
quantity_uom = fields.Function(fields.Many2One(string='Symbol',
|
||||
quantity_uom = fields.Function(fields.Many2One(
|
||||
string='Symbol',
|
||||
readonly=True, model_name='product.uom'),
|
||||
'on_change_with_quantity_uom')
|
||||
asset_rate = fields.Function(fields.Numeric(string='Rate',
|
||||
readonly=True,
|
||||
asset_rate = fields.Function(fields.Numeric(
|
||||
string='Rate', readonly=True,
|
||||
digits=(16, If(
|
||||
Eval('currency_digits', 2) > Eval('quantity_digits', 2),
|
||||
Eval('currency_digits', 2), Eval('quantity_digits', 2))),
|
||||
|
@ -77,7 +82,8 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
|
|||
'invisible': Eval('feature', '') != 'asset',
|
||||
}, depends=['currency_digits', 'quantity_digits', 'feature']),
|
||||
'on_change_with_asset_rate')
|
||||
quantity_balance = fields.Function(fields.Numeric(string='Quantity',
|
||||
quantity_balance = fields.Function(fields.Numeric(
|
||||
string='Quantity',
|
||||
digits=(16, Eval('quantity_digits', 4)), readonly=True,
|
||||
help='Number of shares in the cashbook up to the current row if the default sort applies.',
|
||||
states={
|
||||
|
@ -89,21 +95,24 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
|
|||
'on_change_with_splitline_has_quantity')
|
||||
|
||||
# performance
|
||||
current_value = fields.Function(fields.Numeric(string='Value',
|
||||
current_value = fields.Function(fields.Numeric(
|
||||
string='Value',
|
||||
help='Valuation of the investment based on the current stock market price.',
|
||||
readonly=True, digits=(16, Eval('currency_digits', 2)),
|
||||
states={
|
||||
'invisible': Eval('feature', '') != 'asset',
|
||||
}, depends=['currency_digits', 'feature']),
|
||||
'on_change_with_current_value')
|
||||
diff_amount = fields.Function(fields.Numeric(string='Difference',
|
||||
diff_amount = fields.Function(fields.Numeric(
|
||||
string='Difference',
|
||||
help='Difference between acquisition value and current value',
|
||||
readonly=True, digits=(16, Eval('currency_digits', 2)),
|
||||
states={
|
||||
'invisible': Eval('feature', '') != 'asset',
|
||||
}, depends=['currency_digits', 'feature']),
|
||||
'on_change_with_diff_amount')
|
||||
diff_percent = fields.Function(fields.Numeric(string='Percent',
|
||||
diff_percent = fields.Function(fields.Numeric(
|
||||
string='Percent',
|
||||
help='percentage performance since acquisition',
|
||||
readonly=True, digits=(16, Eval('currency_digits', 2)),
|
||||
states={
|
||||
|
@ -111,21 +120,24 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
|
|||
}, depends=['currency_digits', 'feature']),
|
||||
'on_change_with_diff_percent')
|
||||
|
||||
trade_fee = fields.Function(fields.Numeric(string='Fee',
|
||||
trade_fee = fields.Function(fields.Numeric(
|
||||
string='Fee',
|
||||
help='Trading fee for the current booking line.',
|
||||
readonly=True, digits=(16, Eval('currency_digits', 2)),
|
||||
states={
|
||||
'invisible': Eval('feature', '') != 'asset',
|
||||
}, depends=['currency_digits', 'feature']),
|
||||
'get_yield_data', searcher='search_trade_fee')
|
||||
asset_dividend = fields.Function(fields.Numeric(string='Dividend',
|
||||
asset_dividend = fields.Function(fields.Numeric(
|
||||
string='Dividend',
|
||||
help='Dividend received at the current booking line.',
|
||||
readonly=True, digits=(16, Eval('currency_digits', 2)),
|
||||
states={
|
||||
'invisible': Eval('feature', '') != 'asset',
|
||||
}, depends=['currency_digits', 'feature']),
|
||||
'get_yield_data', searcher='search_asset_dividend')
|
||||
asset_gainloss = fields.Function(fields.Numeric(string='Profit/Loss',
|
||||
asset_gainloss = fields.Function(fields.Numeric(
|
||||
string='Profit/Loss',
|
||||
help='Profit or loss on sale on the current booking line.',
|
||||
readonly=True, digits=(16, Eval('currency_digits', 2)),
|
||||
states={
|
||||
|
@ -490,11 +502,11 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
|
|||
(splitline.booktransf.quantity_uom is not None)
|
||||
|
||||
result.update({
|
||||
'quantity': splitline.quantity_2nd_uom \
|
||||
if (asset_books == 2) and (diff_uom == True) \
|
||||
'quantity': splitline.quantity_2nd_uom
|
||||
if (asset_books == 2) and (diff_uom is True)
|
||||
else splitline.quantity,
|
||||
'quantity_2nd_uom': splitline.quantity \
|
||||
if (asset_books == 2) and (diff_uom == True) else None,
|
||||
'quantity_2nd_uom': splitline.quantity
|
||||
if (asset_books == 2) and (diff_uom is True) else None,
|
||||
})
|
||||
elif sum([1 if booktransf_uom is not None else 0,
|
||||
1 if line_uom is not None else 0]) == 1:
|
||||
|
@ -522,12 +534,16 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
|
|||
""" update amount if splitlines change
|
||||
"""
|
||||
super(Line, self).on_change_splitlines()
|
||||
quantity = sum([x.quantity for x in self.splitlines if x.quantity is not None])
|
||||
quantity = sum([
|
||||
x.quantity for x in self.splitlines
|
||||
if x.quantity is not None])
|
||||
cnt1 = sum([1 for x in self.splitlines if x.quantity is not None])
|
||||
if cnt1 > 0:
|
||||
self.quantity = quantity
|
||||
|
||||
@fields.depends('quantity', 'cashbook', '_parent_cashbook.current_rate', 'currency_digits')
|
||||
@fields.depends(
|
||||
'quantity', 'cashbook', '_parent_cashbook.current_rate',
|
||||
'currency_digits')
|
||||
def on_change_with_current_value(self, name=None):
|
||||
""" get current value of line by current stock marked price
|
||||
and quantity
|
||||
|
@ -539,7 +555,9 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
|
|||
self.quantity * self.cashbook.current_rate
|
||||
).quantize(Decimal(str(1/10**self.currency_digits)))
|
||||
|
||||
@fields.depends('quantity', 'amount', 'cashbook', '_parent_cashbook.current_rate', 'currency_digits')
|
||||
@fields.depends(
|
||||
'quantity', 'amount', 'cashbook', '_parent_cashbook.current_rate',
|
||||
'currency_digits')
|
||||
def on_change_with_diff_amount(self, name=None):
|
||||
""" get delta between buy and current value
|
||||
"""
|
||||
|
@ -547,19 +565,21 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
|
|||
if (self.quantity is not None) and \
|
||||
(self.amount is not None) and \
|
||||
(self.cashbook.current_rate is not None):
|
||||
return (
|
||||
self.quantity * self.cashbook.current_rate - self.amount
|
||||
).quantize(Decimal(str(1/10**self.currency_digits)))
|
||||
return (self.quantity * self.cashbook.current_rate -
|
||||
self.amount).quantize(
|
||||
Decimal(str(1/10**self.currency_digits)))
|
||||
|
||||
@fields.depends('quantity', 'amount', 'cashbook', '_parent_cashbook.current_rate')
|
||||
@fields.depends(
|
||||
'quantity', 'amount', 'cashbook', '_parent_cashbook.current_rate')
|
||||
def on_change_with_diff_percent(self, name=None):
|
||||
""" get performane percent
|
||||
"""
|
||||
if self.cashbook:
|
||||
if (self.quantity is not None) and \
|
||||
(self.amount is not None) and (self.amount != Decimal('0.0')) and \
|
||||
(self.amount is not None) and \
|
||||
(self.amount != Decimal('0.0')) and \
|
||||
(self.cashbook.current_rate is not None):
|
||||
return (self.quantity * self.cashbook.current_rate * \
|
||||
return (self.quantity * self.cashbook.current_rate *
|
||||
Decimal('100.0') / self.amount - Decimal('100.0')
|
||||
).quantize(Decimal(str(1/10**self.currency_digits)))
|
||||
|
||||
|
@ -577,9 +597,10 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
|
|||
break
|
||||
return result
|
||||
|
||||
@fields.depends('id', 'date', 'cashbook', 'feature',\
|
||||
'_parent_cashbook.id', 'reconciliation', \
|
||||
'_parent_reconciliation.start_quantity',\
|
||||
@fields.depends(
|
||||
'id', 'date', 'cashbook', 'feature',
|
||||
'_parent_cashbook.id', 'reconciliation',
|
||||
'_parent_reconciliation.start_quantity',
|
||||
'_parent_reconciliation.state')
|
||||
def on_change_with_quantity_balance(self, name=None):
|
||||
""" get quantity-balance
|
||||
|
@ -587,8 +608,8 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
|
|||
Line2 = Pool().get('cashbook.line')
|
||||
|
||||
if self.feature == 'asset':
|
||||
return Line2.get_balance_of_line(self,
|
||||
field_name='quantity',
|
||||
return Line2.get_balance_of_line(
|
||||
self, field_name='quantity',
|
||||
credit_name='quantity_credit',
|
||||
debit_name='quantity_debit')
|
||||
|
||||
|
@ -606,8 +627,10 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
|
|||
self.amount / self.quantity
|
||||
).quantize(Decimal(Decimal(1) / 10**digit))
|
||||
|
||||
@fields.depends('feature', 'cashbook', '_parent_cashbook.quantity_uom', \
|
||||
'booktransf', '_parent_booktransf.quantity_uom', '_parent_booktransf.feature')
|
||||
@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
|
||||
"""
|
||||
|
@ -621,11 +644,12 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
|
|||
if self.booktransf.quantity_uom:
|
||||
return self.booktransf.quantity_uom.id
|
||||
|
||||
@fields.depends('feature', 'cashbook', '_parent_cashbook.quantity_digits', \
|
||||
'booktransf', '_parent_booktransf.quantity_digits',\
|
||||
'_parent_booktransf.feature', 'bookingtype')
|
||||
@fields.depends(
|
||||
'feature', 'cashbook', '_parent_cashbook.quantity_digits',
|
||||
'booktransf', '_parent_booktransf.quantity_digits',
|
||||
'_parent_booktransf.feature', 'bookingtype', 'splitlines')
|
||||
def on_change_with_quantity_digits(self, name=None):
|
||||
""" get digits from cashbook
|
||||
""" get digits from cashbook or related bookings
|
||||
"""
|
||||
digits = 0
|
||||
if self.feature == 'asset':
|
||||
|
@ -640,7 +664,7 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
|
|||
if self.booktransf.quantity_digits > digits \
|
||||
else digits
|
||||
elif self.bookingtype in ['spin', 'spout']:
|
||||
for spline in self.splitlines:
|
||||
for spline in (self.splitlines or []):
|
||||
if spline.booktransf:
|
||||
if spline.booktransf.feature == 'asset':
|
||||
digits = spline.booktransf.quantity_digits \
|
||||
|
|
Loading…
Reference in a new issue