Skip to content
This repository was 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
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
b3fec20
[ADD] telegram_expense_manager: currency_id in expenses account.move.…
Jan 26, 2018
c5c51f6
[FIX] telegram_expense_manager: typo
Jan 26, 2018
c6e537c
[ADD] telegram_expense_manager: multicurrency expenses
Jan 29, 2018
7ada112
[ADD] telegram_expense_manager: multicurrency /income
Jan 29, 2018
18e08e6
[ADD] telegram_expense_manager: multicurrency in total row for /accou…
Jan 29, 2018
9feee23
[ADD] telegram_expense_manager: multicurrency /account_all report
Jan 29, 2018
a7b4567
[ADD] telegram_expense_manager: res.currency.alias
Jan 30, 2018
47c113d
[ADD] telegram_expense_manager: use currency aliases to get an expens…
Jan 30, 2018
ed9bec1
[FIX] telegram_expense_manager: base_currency might not have rate 1
Jan 30, 2018
050d398
[ADD] telegram_expense_manager: add em_currency_id on partner's form
Jan 30, 2018
4ac68c0
[ADD] telegram_expense_manager: allow multicurrency by default
Jan 30, 2018
87b2c0a
[FIX] telegram_expense_manager: search currency by name first, if fai…
Jan 30, 2018
ca01be3
[FIX] telegram_expense_manager: fix multicurrency /account_all report
Jan 31, 2018
4874de3
[ADD] telegram_expense_manager: multicurrency expense record report
Jan 31, 2018
e645bd0
[FIX] telegram_expense_manager: take currency from alias if there is …
Feb 6, 2018
e77fd45
[ADD] telegram_expense_manager: case-insensitive currency search
Feb 9, 2018
b3262fd
[FIX] telegram_expense_manager: don't specify base currency in accoun…
Feb 9, 2018
ab00b11
[ADD] telegram_expense_manager: data file for currency aliases
Feb 12, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions telegram_expense_manager/data/telegram_command.xml
Original file line number Diff line number Diff line change
Expand Up @@ -341,12 +341,14 @@ accounts = env["account.analytic.account"].sudo().search(
order='id ASC',
)
data['accounts'] = accounts
data['base_currency'] = partner.company_id.currency_id
data['currency_ids'] = env["account.move.line"].sudo().search([('analytic_account_id', 'in', accounts.ids)]).mapped('currency_id').sorted(key=lambda r: r.id)
data['total'] = sum((acc.move_balance for acc in accounts))
</field>
<field name="response_template" type="xml">
<t><t t-foreach="data['accounts']" t-as="acc">
/account_<t t-esc="acc.id"/> — <t t-esc="acc.move_balance"/> — <t t-esc="acc.name"/></t>
<b>Total</b>: <t t-esc="data['total']"/></t>
/account_<t t-esc="acc.id"/> — <t t-esc="acc.get_currency_balance()"/> (<t t-esc="acc.get_currency_balance(data['base_currency'])"/> <t t-esc="data['base_currency'].name"/><t t-foreach="acc.currency_ids" t-as="currency"> <t t-esc="acc.get_currency_balance(currency)"/> <t t-esc="currency.name"/></t>) — <t t-esc="acc.name"/></t>
<b>Total</b>: <t t-esc="data['accounts'].get_currency_balance()"/> (<t t-esc="data['accounts'].get_currency_balance(data['base_currency'])"/> <t t-esc="data['base_currency'].name"/> <t t-foreach="data['currency_ids']" t-as="currency_all"> <t t-esc="data['accounts'].get_currency_balance(currency_all)"/> <t t-esc="currency_all.name"/></t>)</t>
</field>
</record>

Expand Down
37 changes: 37 additions & 0 deletions telegram_expense_manager/models/account_analytic_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,40 @@ def _compute_move_debit_credit_balance(self):
move_balance = fields.Monetary(compute='_compute_move_debit_credit_balance', string='Balance')
move_debit = fields.Monetary(compute='_compute_move_debit_credit_balance', string='Debit')
move_credit = fields.Monetary(compute='_compute_move_debit_credit_balance', string='Credit')
currency_ids = fields.Many2many("res.currency", "analytic_account_currency_rel")

@api.multi
def _attach_new_currency(self, currency):
for record in self:
if currency not in record.currency_ids:
record.currency_ids = [(4, currency.id)]

@api.multi
def get_currency_balance(self, currency=None):
balance = 0.0
AccountMoveLine = self.env['account.move.line']
domain = [('analytic_account_id', 'in', self.mapped('id'))]

if self._context.get('from_date', False):
domain.append(('date', '>=', self._context['from_date']))
if self._context.get('to_date', False):
domain.append(('date', '<=', self._context['to_date']))

base_currency = self.env.user.partner_id.company_id.currency_id
if currency and currency != base_currency:
domain.append(('currency_id', '=', currency.id))
balance = sum(AccountMoveLine.search(domain).mapped('balance'))
elif currency and currency == base_currency:
base_currency_sum = 0.0
domain.append(('currency_id', '=', False))
line_ids = AccountMoveLine.search(domain)
balance += sum(line_ids.mapped('balance'))
else:
domain.append(('currency_id', '!=', False))
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
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


return round(balance, 1)
17 changes: 15 additions & 2 deletions telegram_expense_manager/models/api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
import re

from odoo import models, api, fields
from odoo.exceptions import AccessError
from odoo.tools.translate import _
Expand Down Expand Up @@ -233,10 +235,13 @@ def em_handle_callback_data(self, callback_data, raw_text, add_record=None):
error = None

if callback_data.get('action') == ASK_AMOUNT:
m = re.match(r'([0-9][ +\-\/0-9.,]*) ?([^0-9]*)', raw_text)
amount = m.group(1)
currency = m.group(2)
if not record:
record = add_record('', raw_text)
record = add_record('', amount, currency=currency)
else:
record.em_update_amount(raw_text)
record.em_update_amount(amount, currency=currency)
elif callback_data.get('action') == ASK_NOTE:
record.em_update_note(raw_text)
elif callback_data.get('action') == ASK_ANALYTIC:
Expand Down Expand Up @@ -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
РУБ
рублей
рубля
рубль
руб
руб.
р.


if currency_id:
analytic_account_lst = [from_data.get('analytic_account_id'), to_data.get('analytic_account_id')]
analytic_account_ids = self.env['account.analytic.account'].browse(analytic_account_lst)
analytic_account_ids._attach_new_currency(currency_id)

common = {
'partner_id': self.id,
'name': text or 'unknown',
'currency_id': currency_id and currency_id.id or None,
}
if isinstance(amount, basestring):
amount = float(amount.replace(',', '.'))
Expand Down