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
122
line.py
122
line.py
|
@ -52,24 +52,29 @@ DEPENDSQ2 = ['feature', 'quantity_digits', 'bookingtype']
|
||||||
class Line(SecondUomMixin, metaclass=PoolMeta):
|
class Line(SecondUomMixin, metaclass=PoolMeta):
|
||||||
__name__ = 'cashbook.line'
|
__name__ = 'cashbook.line'
|
||||||
|
|
||||||
quantity = fields.Numeric(string='Quantity',
|
quantity = fields.Numeric(
|
||||||
|
string='Quantity',
|
||||||
digits=(16, Eval('quantity_digits', 4)),
|
digits=(16, Eval('quantity_digits', 4)),
|
||||||
states=STATESQ1B, depends=DEPENDSQ1+['splitline_has_quantity'])
|
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,
|
digits=(16, Eval('quantity_digits', 4)), readonly=True,
|
||||||
states=STATESQ2, depends=DEPENDSQ2)
|
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,
|
digits=(16, Eval('quantity_digits', 4)), readonly=True,
|
||||||
states=STATESQ2, depends=DEPENDSQ2)
|
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}),
|
readonly=True, states={'invisible': True}),
|
||||||
'on_change_with_quantity_digits')
|
'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'),
|
readonly=True, model_name='product.uom'),
|
||||||
'on_change_with_quantity_uom')
|
'on_change_with_quantity_uom')
|
||||||
asset_rate = fields.Function(fields.Numeric(string='Rate',
|
asset_rate = fields.Function(fields.Numeric(
|
||||||
readonly=True,
|
string='Rate', readonly=True,
|
||||||
digits=(16, If(
|
digits=(16, If(
|
||||||
Eval('currency_digits', 2) > Eval('quantity_digits', 2),
|
Eval('currency_digits', 2) > Eval('quantity_digits', 2),
|
||||||
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',
|
'invisible': Eval('feature', '') != 'asset',
|
||||||
}, depends=['currency_digits', 'quantity_digits', 'feature']),
|
}, depends=['currency_digits', 'quantity_digits', 'feature']),
|
||||||
'on_change_with_asset_rate')
|
'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,
|
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.',
|
help='Number of shares in the cashbook up to the current row if the default sort applies.',
|
||||||
states={
|
states={
|
||||||
|
@ -89,46 +95,52 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
|
||||||
'on_change_with_splitline_has_quantity')
|
'on_change_with_splitline_has_quantity')
|
||||||
|
|
||||||
# performance
|
# 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.',
|
help='Valuation of the investment based on the current stock market price.',
|
||||||
readonly=True, digits=(16, Eval('currency_digits', 2)),
|
readonly=True, digits=(16, Eval('currency_digits', 2)),
|
||||||
states={
|
states={
|
||||||
'invisible': Eval('feature', '') != 'asset',
|
'invisible': Eval('feature', '') != 'asset',
|
||||||
}, depends=['currency_digits', 'feature']),
|
}, depends=['currency_digits', 'feature']),
|
||||||
'on_change_with_current_value')
|
'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',
|
help='Difference between acquisition value and current value',
|
||||||
readonly=True, digits=(16, Eval('currency_digits', 2)),
|
readonly=True, digits=(16, Eval('currency_digits', 2)),
|
||||||
states={
|
states={
|
||||||
'invisible': Eval('feature', '') != 'asset',
|
'invisible': Eval('feature', '') != 'asset',
|
||||||
}, depends=['currency_digits', 'feature']),
|
}, depends=['currency_digits', 'feature']),
|
||||||
'on_change_with_diff_amount')
|
'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',
|
help='percentage performance since acquisition',
|
||||||
readonly=True, digits=(16, Eval('currency_digits', 2)),
|
readonly=True, digits=(16, Eval('currency_digits', 2)),
|
||||||
states = {
|
states={
|
||||||
'invisible': Eval('feature', '') != 'asset',
|
'invisible': Eval('feature', '') != 'asset',
|
||||||
}, depends=['currency_digits', 'feature']),
|
}, depends=['currency_digits', 'feature']),
|
||||||
'on_change_with_diff_percent')
|
'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.',
|
help='Trading fee for the current booking line.',
|
||||||
readonly=True, digits=(16, Eval('currency_digits', 2)),
|
readonly=True, digits=(16, Eval('currency_digits', 2)),
|
||||||
states = {
|
states={
|
||||||
'invisible': Eval('feature', '') != 'asset',
|
'invisible': Eval('feature', '') != 'asset',
|
||||||
}, depends=['currency_digits', 'feature']),
|
}, depends=['currency_digits', 'feature']),
|
||||||
'get_yield_data', searcher='search_trade_fee')
|
'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.',
|
help='Dividend received at the current booking line.',
|
||||||
readonly=True, digits=(16, Eval('currency_digits', 2)),
|
readonly=True, digits=(16, Eval('currency_digits', 2)),
|
||||||
states = {
|
states={
|
||||||
'invisible': Eval('feature', '') != 'asset',
|
'invisible': Eval('feature', '') != 'asset',
|
||||||
}, depends=['currency_digits', 'feature']),
|
}, depends=['currency_digits', 'feature']),
|
||||||
'get_yield_data', searcher='search_asset_dividend')
|
'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.',
|
help='Profit or loss on sale on the current booking line.',
|
||||||
readonly=True, digits=(16, Eval('currency_digits', 2)),
|
readonly=True, digits=(16, Eval('currency_digits', 2)),
|
||||||
states = {
|
states={
|
||||||
'invisible': Eval('feature', '') != 'asset',
|
'invisible': Eval('feature', '') != 'asset',
|
||||||
}, depends=['currency_digits', 'feature']),
|
}, depends=['currency_digits', 'feature']),
|
||||||
'get_yield_data', searcher='search_asset_gainloss')
|
'get_yield_data', searcher='search_asset_gainloss')
|
||||||
|
@ -490,11 +502,11 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
|
||||||
(splitline.booktransf.quantity_uom is not None)
|
(splitline.booktransf.quantity_uom is not None)
|
||||||
|
|
||||||
result.update({
|
result.update({
|
||||||
'quantity': splitline.quantity_2nd_uom \
|
'quantity': splitline.quantity_2nd_uom
|
||||||
if (asset_books == 2) and (diff_uom == True) \
|
if (asset_books == 2) and (diff_uom is True)
|
||||||
else splitline.quantity,
|
else splitline.quantity,
|
||||||
'quantity_2nd_uom': splitline.quantity \
|
'quantity_2nd_uom': splitline.quantity
|
||||||
if (asset_books == 2) and (diff_uom == True) else None,
|
if (asset_books == 2) and (diff_uom is True) else None,
|
||||||
})
|
})
|
||||||
elif sum([1 if booktransf_uom is not None else 0,
|
elif sum([1 if booktransf_uom is not None else 0,
|
||||||
1 if line_uom is not None else 0]) == 1:
|
1 if line_uom is not None else 0]) == 1:
|
||||||
|
@ -510,7 +522,7 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
|
||||||
'quantity': line.quantity,
|
'quantity': line.quantity,
|
||||||
'quantity_2nd_uom': None,
|
'quantity_2nd_uom': None,
|
||||||
})
|
})
|
||||||
else :
|
else:
|
||||||
result.update({
|
result.update({
|
||||||
'quantity': line.quantity_2nd_uom,
|
'quantity': line.quantity_2nd_uom,
|
||||||
'quantity_2nd_uom': line.quantity,
|
'quantity_2nd_uom': line.quantity,
|
||||||
|
@ -522,44 +534,52 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
|
||||||
""" update amount if splitlines change
|
""" update amount if splitlines change
|
||||||
"""
|
"""
|
||||||
super(Line, self).on_change_splitlines()
|
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])
|
cnt1 = sum([1 for x in self.splitlines if x.quantity is not None])
|
||||||
if cnt1 > 0:
|
if cnt1 > 0:
|
||||||
self.quantity = quantity
|
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):
|
def on_change_with_current_value(self, name=None):
|
||||||
""" get current value of line by current stock marked price
|
""" get current value of line by current stock marked price
|
||||||
and quantity
|
and quantity
|
||||||
"""
|
"""
|
||||||
if self.cashbook:
|
if self.cashbook:
|
||||||
if (self.quantity is not None) and \
|
if (self.quantity is not None) and \
|
||||||
(self.cashbook.current_rate is not None):
|
(self.cashbook.current_rate is not None):
|
||||||
return (
|
return (
|
||||||
self.quantity * self.cashbook.current_rate
|
self.quantity * self.cashbook.current_rate
|
||||||
).quantize(Decimal(str(1/10**self.currency_digits)))
|
).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):
|
def on_change_with_diff_amount(self, name=None):
|
||||||
""" get delta between buy and current value
|
""" get delta between buy and current value
|
||||||
"""
|
"""
|
||||||
if self.cashbook:
|
if self.cashbook:
|
||||||
if (self.quantity is not None) and \
|
if (self.quantity is not None) and \
|
||||||
(self.amount is not None) and \
|
(self.amount is not None) and \
|
||||||
(self.cashbook.current_rate is not None):
|
(self.cashbook.current_rate is not None):
|
||||||
return (
|
return (self.quantity * self.cashbook.current_rate -
|
||||||
self.quantity * self.cashbook.current_rate - self.amount
|
self.amount).quantize(
|
||||||
).quantize(Decimal(str(1/10**self.currency_digits)))
|
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):
|
def on_change_with_diff_percent(self, name=None):
|
||||||
""" get performane percent
|
""" get performane percent
|
||||||
"""
|
"""
|
||||||
if self.cashbook:
|
if self.cashbook:
|
||||||
if (self.quantity is not None) and \
|
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.cashbook.current_rate is not None):
|
(self.amount != Decimal('0.0')) and \
|
||||||
return (self.quantity * self.cashbook.current_rate * \
|
(self.cashbook.current_rate is not None):
|
||||||
|
return (self.quantity * self.cashbook.current_rate *
|
||||||
Decimal('100.0') / self.amount - Decimal('100.0')
|
Decimal('100.0') / self.amount - Decimal('100.0')
|
||||||
).quantize(Decimal(str(1/10**self.currency_digits)))
|
).quantize(Decimal(str(1/10**self.currency_digits)))
|
||||||
|
|
||||||
|
@ -577,9 +597,10 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
|
||||||
break
|
break
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@fields.depends('id', 'date', 'cashbook', 'feature',\
|
@fields.depends(
|
||||||
'_parent_cashbook.id', 'reconciliation', \
|
'id', 'date', 'cashbook', 'feature',
|
||||||
'_parent_reconciliation.start_quantity',\
|
'_parent_cashbook.id', 'reconciliation',
|
||||||
|
'_parent_reconciliation.start_quantity',
|
||||||
'_parent_reconciliation.state')
|
'_parent_reconciliation.state')
|
||||||
def on_change_with_quantity_balance(self, name=None):
|
def on_change_with_quantity_balance(self, name=None):
|
||||||
""" get quantity-balance
|
""" get quantity-balance
|
||||||
|
@ -587,8 +608,8 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
|
||||||
Line2 = Pool().get('cashbook.line')
|
Line2 = Pool().get('cashbook.line')
|
||||||
|
|
||||||
if self.feature == 'asset':
|
if self.feature == 'asset':
|
||||||
return Line2.get_balance_of_line(self,
|
return Line2.get_balance_of_line(
|
||||||
field_name='quantity',
|
self, field_name='quantity',
|
||||||
credit_name='quantity_credit',
|
credit_name='quantity_credit',
|
||||||
debit_name='quantity_debit')
|
debit_name='quantity_debit')
|
||||||
|
|
||||||
|
@ -606,8 +627,10 @@ 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('feature', 'cashbook', '_parent_cashbook.quantity_uom', \
|
@fields.depends(
|
||||||
'booktransf', '_parent_booktransf.quantity_uom', '_parent_booktransf.feature')
|
'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
|
||||||
"""
|
"""
|
||||||
|
@ -615,17 +638,18 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
|
||||||
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 :
|
else:
|
||||||
if self.booktransf:
|
if self.booktransf:
|
||||||
if self.booktransf.feature == 'asset':
|
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('feature', 'cashbook', '_parent_cashbook.quantity_digits', \
|
@fields.depends(
|
||||||
'booktransf', '_parent_booktransf.quantity_digits',\
|
'feature', 'cashbook', '_parent_cashbook.quantity_digits',
|
||||||
'_parent_booktransf.feature', 'bookingtype')
|
'booktransf', '_parent_booktransf.quantity_digits',
|
||||||
|
'_parent_booktransf.feature', 'bookingtype', 'splitlines')
|
||||||
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 or related bookings
|
||||||
"""
|
"""
|
||||||
digits = 0
|
digits = 0
|
||||||
if self.feature == 'asset':
|
if self.feature == 'asset':
|
||||||
|
@ -640,7 +664,7 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
|
||||||
if self.booktransf.quantity_digits > digits \
|
if self.booktransf.quantity_digits > digits \
|
||||||
else digits
|
else digits
|
||||||
elif self.bookingtype in ['spin', 'spout']:
|
elif self.bookingtype in ['spin', 'spout']:
|
||||||
for spline in self.splitlines:
|
for spline in (self.splitlines or []):
|
||||||
if spline.booktransf:
|
if spline.booktransf:
|
||||||
if spline.booktransf.feature == 'asset':
|
if spline.booktransf.feature == 'asset':
|
||||||
digits = spline.booktransf.quantity_digits \
|
digits = spline.booktransf.quantity_digits \
|
||||||
|
|
Loading…
Reference in a new issue