formatting, line: test for delete of party
This commit is contained in:
parent
78f160bf0b
commit
619a17bcd6
16 changed files with 701 additions and 516 deletions
49
mixin.py
49
mixin.py
|
@ -17,13 +17,14 @@ STATES = {
|
|||
Eval('state_cashbook', '') != 'open',
|
||||
),
|
||||
}
|
||||
DEPENDS=['state', 'state_cashbook']
|
||||
DEPENDS = ['state', 'state_cashbook']
|
||||
|
||||
|
||||
class SecondCurrencyMixin:
|
||||
""" two fields for 2nd currency: amount + rate
|
||||
"""
|
||||
amount_2nd_currency = fields.Numeric(string='Amount Second Currency',
|
||||
amount_2nd_currency = fields.Numeric(
|
||||
string='Amount Second Currency',
|
||||
digits=(16, Eval('currency2nd_digits', 2)),
|
||||
states={
|
||||
'readonly': Or(
|
||||
|
@ -33,7 +34,8 @@ class SecondCurrencyMixin:
|
|||
'required': Bool(Eval('currency2nd')),
|
||||
'invisible': ~Bool(Eval('currency2nd')),
|
||||
}, depends=DEPENDS+['currency2nd_digits', 'currency2nd'])
|
||||
rate_2nd_currency = fields.Function(fields.Numeric(string='Rate',
|
||||
rate_2nd_currency = fields.Function(fields.Numeric(
|
||||
string='Rate',
|
||||
help='Exchange rate between the currencies of the participating cashbooks.',
|
||||
digits=(rate_decimal * 2, rate_decimal),
|
||||
states={
|
||||
|
@ -46,9 +48,11 @@ class SecondCurrencyMixin:
|
|||
}, depends=DEPENDS+['currency2nd_digits', 'currency2nd']),
|
||||
'on_change_with_rate_2nd_currency', setter='set_rate_2nd_currency')
|
||||
|
||||
currency2nd = fields.Function(fields.Many2One(model_name='currency.currency',
|
||||
currency2nd = fields.Function(fields.Many2One(
|
||||
model_name='currency.currency',
|
||||
string="2nd Currency", readonly=True), 'on_change_with_currency2nd')
|
||||
currency2nd_digits = fields.Function(fields.Integer(string='2nd Currency Digits',
|
||||
currency2nd_digits = fields.Function(fields.Integer(
|
||||
string='2nd Currency Digits',
|
||||
readonly=True), 'on_change_with_currency2nd_digits')
|
||||
|
||||
@classmethod
|
||||
|
@ -69,8 +73,7 @@ class SecondCurrencyMixin:
|
|||
booktransf = Cashbook(booktransf)
|
||||
if from_currency.id != booktransf.currency.id:
|
||||
with Transaction().set_context({
|
||||
'date': values.get('date', IrDate.today()),
|
||||
}):
|
||||
'date': values.get('date', IrDate.today())}):
|
||||
values['amount_2nd_currency'] = Currency.compute(
|
||||
from_currency,
|
||||
amount,
|
||||
|
@ -78,22 +81,28 @@ class SecondCurrencyMixin:
|
|||
)
|
||||
return values
|
||||
|
||||
@fields.depends('booktransf', '_parent_booktransf.currency', \
|
||||
'currency', 'amount', 'date', 'amount_2nd_currency', 'rate_2nd_currency')
|
||||
@fields.depends(
|
||||
'booktransf', '_parent_booktransf.currency',
|
||||
'currency', 'amount', 'date', 'amount_2nd_currency',
|
||||
'rate_2nd_currency')
|
||||
def on_change_booktransf(self):
|
||||
""" update amount_2nd_currency
|
||||
"""
|
||||
self.on_change_rate_2nd_currency()
|
||||
|
||||
@fields.depends('booktransf', '_parent_booktransf.currency', \
|
||||
'currency', 'amount', 'date', 'amount_2nd_currency', 'rate_2nd_currency')
|
||||
@fields.depends(
|
||||
'booktransf', '_parent_booktransf.currency',
|
||||
'currency', 'amount', 'date', 'amount_2nd_currency',
|
||||
'rate_2nd_currency')
|
||||
def on_change_amount(self):
|
||||
""" update amount_2nd_currency
|
||||
"""
|
||||
self.on_change_rate_2nd_currency()
|
||||
|
||||
@fields.depends('booktransf', '_parent_booktransf.currency', \
|
||||
'currency', 'amount', 'date', 'amount_2nd_currency', 'rate_2nd_currency')
|
||||
@fields.depends(
|
||||
'booktransf', '_parent_booktransf.currency',
|
||||
'currency', 'amount', 'date', 'amount_2nd_currency',
|
||||
'rate_2nd_currency')
|
||||
def on_change_rate_2nd_currency(self):
|
||||
""" update amount_2nd_currency + rate_2nd_currency
|
||||
"""
|
||||
|
@ -109,16 +118,16 @@ class SecondCurrencyMixin:
|
|||
if self.rate_2nd_currency is None:
|
||||
# no rate set, use current rate of target-currency
|
||||
with Transaction().set_context({
|
||||
'date': self.date or IrDate.today(),
|
||||
}):
|
||||
'date': self.date or IrDate.today()}):
|
||||
self.amount_2nd_currency = Currency.compute(
|
||||
self.currency,
|
||||
self.amount,
|
||||
self.booktransf.currency
|
||||
)
|
||||
if self.amount != Decimal('0.0'):
|
||||
self.rate_2nd_currency = self.amount_2nd_currency / self.amount
|
||||
else :
|
||||
self.rate_2nd_currency = \
|
||||
self.amount_2nd_currency / self.amount
|
||||
else:
|
||||
self.amount_2nd_currency = self.booktransf.currency.round(
|
||||
self.amount * self.rate_2nd_currency
|
||||
)
|
||||
|
@ -161,10 +170,10 @@ class SecondCurrencyMixin:
|
|||
def on_change_with_rate_2nd_currency(self, name=None):
|
||||
""" get current rate from amount
|
||||
"""
|
||||
Rate = Pool().get('currency.currency.rate')
|
||||
Rate = Pool().get('currency.currency.rate')
|
||||
|
||||
if (self.amount is not None) and \
|
||||
(self.amount_2nd_currency is not None):
|
||||
(self.amount_2nd_currency is not None):
|
||||
if self.amount != Decimal('0.0'):
|
||||
exp = Decimal(Decimal(1) / 10 ** Rate.rate.digits[1])
|
||||
return (self.amount_2nd_currency / self.amount).quantize(exp)
|
||||
|
@ -201,5 +210,3 @@ class MemCacheIndexMx:
|
|||
cls.create_date.select = True
|
||||
|
||||
# end MemCacheIndexMx
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue