Move line manual
This commit is contained in:
@@ -1013,7 +1013,9 @@ class Line(DescriptionOriginMixin, MoveLineMixin, ModelSQL, ModelView):
|
||||
|
||||
journal = fields.Function(fields.Many2One('account.journal',"Journal"),'get_journal')
|
||||
|
||||
rate = fields.Function(fields.Numeric("Rate",digits=(1,6)),'get_rate')
|
||||
rate = fields.Numeric("Rate", digits=(10, 6), states={
|
||||
'readonly': _states['readonly'],
|
||||
})
|
||||
|
||||
del _states
|
||||
|
||||
@@ -1119,44 +1121,58 @@ class Line(DescriptionOriginMixin, MoveLineMixin, ModelSQL, ModelView):
|
||||
def get_rate(self,name=None):
|
||||
if self.amount_second_currency:
|
||||
return round((self.credit if self.credit else self.debit) / abs(self.amount_second_currency),6)
|
||||
|
||||
@fields.depends(
|
||||
'debit', 'credit',
|
||||
'date','second_currency','amount_second_currency')
|
||||
def on_change_amount_second_currency(self):
|
||||
Currency = Pool().get('currency.currency')
|
||||
Date = Pool().get('ir.date')
|
||||
if self.second_currency != None and self.amount_second_currency != None and (not self.credit and not self.debit):
|
||||
tdate = Date.today()
|
||||
if self.date:
|
||||
tdate = self.date
|
||||
rate = Currency._get_rate([self.second_currency],tdate)
|
||||
if rate:
|
||||
rate = rate[self.second_currency.id]
|
||||
if self.amount_second_currency > 0:
|
||||
self.debit = round(rate * self.amount_second_currency,2)
|
||||
elif self.amount_second_currency > 0:
|
||||
self.credit = round(rate * abs(self.amount_second_currency),2)
|
||||
self.rate = self.get_rate()
|
||||
|
||||
@fields.depends(
|
||||
'debit', 'credit',
|
||||
'date','second_currency','amount_second_currency')
|
||||
'date','second_currency','amount_second_currency', 'rate',
|
||||
'origin', 'move_origin', 'move', '_parent_move.origin')
|
||||
def on_change_second_currency(self):
|
||||
if self._manual_rate_mode():
|
||||
self.rate = self._get_second_currency_rate()
|
||||
self._compute_amount_from_second_currency()
|
||||
|
||||
@fields.depends(
|
||||
'debit', 'credit',
|
||||
'date','second_currency','amount_second_currency', 'rate',
|
||||
'origin', 'move_origin', 'move', '_parent_move.origin')
|
||||
def on_change_rate(self):
|
||||
if self._manual_rate_mode() and not self.debit and not self.credit:
|
||||
self._compute_amount_from_second_currency()
|
||||
|
||||
def _manual_rate_mode(self):
|
||||
if getattr(self, 'origin', None) or getattr(self, 'move_origin', None):
|
||||
return False
|
||||
move = getattr(self, 'move', None)
|
||||
if move and getattr(move, 'origin', None):
|
||||
return False
|
||||
return True
|
||||
|
||||
def _get_second_currency_rate(self):
|
||||
Currency = Pool().get('currency.currency')
|
||||
Date = Pool().get('ir.date')
|
||||
if self.second_currency != None and self.amount_second_currency != None and (not self.credit and not self.debit):
|
||||
tdate = Date.today()
|
||||
if self.date:
|
||||
tdate = self.date
|
||||
rate = Currency._get_rate([self.second_currency],tdate)
|
||||
if rate:
|
||||
rate = rate[self.second_currency.id]
|
||||
if self.second_currency is None:
|
||||
return None
|
||||
tdate = Date.today()
|
||||
if self.date:
|
||||
tdate = self.date
|
||||
rates = Currency._get_rate([self.second_currency], tdate)
|
||||
return rates.get(self.second_currency.id) if rates else None
|
||||
|
||||
def _compute_amount_from_second_currency(self):
|
||||
if self.second_currency is not None and self.amount_second_currency is not None:
|
||||
if not self.rate:
|
||||
self.rate = self._get_second_currency_rate()
|
||||
if self.rate:
|
||||
amount = round(self.rate * abs(self.amount_second_currency), 2)
|
||||
if self.amount_second_currency > 0:
|
||||
self.debit = round(rate * self.amount_second_currency,2)
|
||||
elif self.amount_second_currency > 0:
|
||||
self.credit = round(rate * abs(self.amount_second_currency),2)
|
||||
self.rate = self.get_rate()
|
||||
self.debit = amount
|
||||
self.credit = Decimal(0)
|
||||
elif self.amount_second_currency < 0:
|
||||
self.debit = Decimal(0)
|
||||
self.credit = amount
|
||||
else:
|
||||
self.debit = Decimal(0)
|
||||
self.credit = Decimal(0)
|
||||
|
||||
@fields.depends(
|
||||
'move', 'debit', 'credit',
|
||||
@@ -1223,15 +1239,25 @@ class Line(DescriptionOriginMixin, MoveLineMixin, ModelSQL, ModelView):
|
||||
if self.debit:
|
||||
self.credit = Decimal(0)
|
||||
self._amount_second_currency_sign()
|
||||
self.rate = self.get_rate()
|
||||
|
||||
@fields.depends('debit', 'credit', 'amount_second_currency')
|
||||
def on_change_credit(self):
|
||||
if self.credit:
|
||||
self.debit = Decimal(0)
|
||||
self._amount_second_currency_sign()
|
||||
self.rate = self.get_rate()
|
||||
|
||||
@fields.depends('amount_second_currency', 'debit', 'credit')
|
||||
@fields.depends(
|
||||
'amount_second_currency', 'debit', 'credit', 'date', 'second_currency',
|
||||
'rate', 'origin', 'move_origin', 'move', '_parent_move.origin')
|
||||
def on_change_amount_second_currency(self):
|
||||
if self._manual_rate_mode():
|
||||
if not self.rate:
|
||||
self.rate = self._get_second_currency_rate()
|
||||
self._compute_amount_from_second_currency()
|
||||
elif not self.rate:
|
||||
self.rate = self.get_rate()
|
||||
self._amount_second_currency_sign()
|
||||
|
||||
def _amount_second_currency_sign(self):
|
||||
|
||||
Reference in New Issue
Block a user