Skip to content
This repository has been archived by the owner on Mar 21, 2021. It is now read-only.

10.0 17012018 #95

Open
wants to merge 18 commits into
base: 10.0
Choose a base branch
from
Open

10.0 17012018 #95

wants to merge 18 commits into from

Conversation

iledarn
Copy link

@iledarn iledarn commented Jan 29, 2018

No description provided.

@@ -466,9 +471,17 @@ def _em_add_record(self,

journal = self.env.ref(journal_ref)

currency_id = currency and self.env['res.currency'].search([('name', '=', currency)], limit=1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a way to use different currency names, e.g.

RUB
РУБ
рублей
рубля
рубль
руб
руб.
р.

currency_ids = all_currencies_line_ids.mapped('currency_id')
for currency_id in currency_ids:
balance += sum(all_currencies_line_ids.filtered(lambda r: r.currency_id == currency_id).mapped('balance')) * currency_id.rate
balance += self.get_currency_balance(currency=base_currency)
Copy link
Collaborator

@yelizariev yelizariev Jan 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

base_currency might not have rate 1, so you need to dived after computing sum,
e.g
base_currency = RUB, rate = 0.017
EUR = 1.2
USD = 1

Then without dividing you will get sum in USD rather than in base_currency

@iledarn
Copy link
Author

iledarn commented Jan 30, 2018

@yelizariev , done

@@ -85,7 +85,8 @@ def get_currency_balance(self, currency=None):
all_currencies_line_ids = AccountMoveLine.search(domain)
currency_ids = all_currencies_line_ids.mapped('currency_id')
for currency_id in currency_ids:
balance += sum(all_currencies_line_ids.filtered(lambda r: r.currency_id == currency_id).mapped('balance')) * currency_id.rate
rate = self.env['res.currency']._get_conversion_rate(base_currency, currency_id)
balance += sum(all_currencies_line_ids.filtered(lambda r: r.currency_id == currency_id).mapped('balance')) * rate
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

class Currency(models.Model):
_inherit = "res.currency"

alias_ids = fields.One2many('res.currency.alias', 'currency_id', string='Aliases')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -472,6 +472,8 @@ def _em_add_record(self,
journal = self.env.ref(journal_ref)

currency_id = currency and self.env['res.currency'].search([('name', '=', currency)], limit=1)
currency_alias = currency and self.env['res.currency.alias'].sudo().search([('name', '=', currency)], limit=1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should not make search if currency_id is already known

@iledarn
Copy link
Author

iledarn commented Jan 31, 2018

@yelizariev , done

currency_alias = currency and self.env['res.currency.alias'].sudo().search([('name', '=', currency)], limit=1)
currency_id = currency_id or currency_alias and currency_alias.currency_id
currency_id = currency and (self.env['res.currency'].search([('name', '=', currency)], limit=1) \
or self.env['res.currency.alias'].sudo().search([('name', '=', currency)], limit=1))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currency_id is res.currency or res.currency.alias?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants