Bug
This commit is contained in:
@@ -1126,7 +1126,8 @@ class Line(DescriptionOriginMixin, MoveLineMixin, ModelSQL, ModelView):
|
|||||||
@fields.depends(
|
@fields.depends(
|
||||||
'debit', 'credit',
|
'debit', 'credit',
|
||||||
'date','second_currency','amount_second_currency', 'rate',
|
'date','second_currency','amount_second_currency', 'rate',
|
||||||
'origin', 'move_origin', 'move', '_parent_move.origin')
|
'origin', 'move_origin', 'move', '_parent_move.origin',
|
||||||
|
'company', 'account')
|
||||||
def on_change_second_currency(self):
|
def on_change_second_currency(self):
|
||||||
if self._manual_rate_mode():
|
if self._manual_rate_mode():
|
||||||
self.rate = self._get_second_currency_rate()
|
self.rate = self._get_second_currency_rate()
|
||||||
@@ -1135,7 +1136,8 @@ class Line(DescriptionOriginMixin, MoveLineMixin, ModelSQL, ModelView):
|
|||||||
@fields.depends(
|
@fields.depends(
|
||||||
'debit', 'credit',
|
'debit', 'credit',
|
||||||
'date','second_currency','amount_second_currency', 'rate',
|
'date','second_currency','amount_second_currency', 'rate',
|
||||||
'origin', 'move_origin', 'move', '_parent_move.origin')
|
'origin', 'move_origin', 'move', '_parent_move.origin',
|
||||||
|
'company', 'account')
|
||||||
def on_change_rate(self):
|
def on_change_rate(self):
|
||||||
if self._manual_rate_mode() and not self.debit and not self.credit:
|
if self._manual_rate_mode() and not self.debit and not self.credit:
|
||||||
self._compute_amount_from_second_currency()
|
self._compute_amount_from_second_currency()
|
||||||
@@ -1159,15 +1161,23 @@ class Line(DescriptionOriginMixin, MoveLineMixin, ModelSQL, ModelView):
|
|||||||
rates = Currency._get_rate([self.second_currency], tdate)
|
rates = Currency._get_rate([self.second_currency], tdate)
|
||||||
return rates.get(self.second_currency.id) if rates else None
|
return rates.get(self.second_currency.id) if rates else None
|
||||||
|
|
||||||
|
def _get_company_currency(self):
|
||||||
|
Company = Pool().get('company.company')
|
||||||
|
for record in (self, getattr(self, 'move', None),
|
||||||
|
getattr(self, 'account', None)):
|
||||||
|
company = getattr(record, 'company', None)
|
||||||
|
if company:
|
||||||
|
return company.currency
|
||||||
|
company_id = Transaction().context.get('company')
|
||||||
|
if company_id:
|
||||||
|
return Company(company_id).currency
|
||||||
|
|
||||||
def _compute_amount_from_second_currency(self):
|
def _compute_amount_from_second_currency(self):
|
||||||
if self.second_currency is not None and self.amount_second_currency is not None:
|
if self.second_currency is not None and self.amount_second_currency is not None:
|
||||||
if not self.rate:
|
if not self.rate:
|
||||||
self.rate = self._get_second_currency_rate()
|
self.rate = self._get_second_currency_rate()
|
||||||
if self.rate:
|
if self.rate:
|
||||||
company_currency = (
|
company_currency = self._get_company_currency()
|
||||||
self.company.currency if getattr(self, 'company', None)
|
|
||||||
else self.account.company.currency
|
|
||||||
if getattr(self, 'account', None) else None)
|
|
||||||
if not company_currency:
|
if not company_currency:
|
||||||
return
|
return
|
||||||
amount = company_currency.round(
|
amount = company_currency.round(
|
||||||
@@ -1258,7 +1268,8 @@ class Line(DescriptionOriginMixin, MoveLineMixin, ModelSQL, ModelView):
|
|||||||
|
|
||||||
@fields.depends(
|
@fields.depends(
|
||||||
'amount_second_currency', 'debit', 'credit', 'date', 'second_currency',
|
'amount_second_currency', 'debit', 'credit', 'date', 'second_currency',
|
||||||
'rate', 'origin', 'move_origin', 'move', '_parent_move.origin')
|
'rate', 'origin', 'move_origin', 'move', '_parent_move.origin',
|
||||||
|
'company', 'account')
|
||||||
def on_change_amount_second_currency(self):
|
def on_change_amount_second_currency(self):
|
||||||
if self._manual_rate_mode():
|
if self._manual_rate_mode():
|
||||||
if not self.rate:
|
if not self.rate:
|
||||||
|
|||||||
Reference in New Issue
Block a user