-
Notifications
You must be signed in to change notification settings - Fork 108
10.0 17012018 #95
base: 10.0
Are you sure you want to change the base?
10.0 17012018 #95
Changes from 12 commits
b3fec20
c5c51f6
c6e537c
7ada112
18e08e6
9feee23
a7b4567
47c113d
ed9bec1
050d398
4ac68c0
87b2c0a
ca01be3
4874de3
e645bd0
e77fd45
b3262fd
ab00b11
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,3 +52,41 @@ 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: | ||
| 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 | ||
| balance += self.get_currency_balance(currency=base_currency) | ||
|
||
|
|
||
| return round(balance, 1) | ||
| 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 _ | ||
|
|
@@ -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: | ||
|
|
@@ -466,9 +471,19 @@ 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) | ||
|
||
| currency_id = currency_id or currency_alias and currency_alias.currency_id | ||
|
|
||
| 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(',', '.')) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # -*- coding: utf-8 -*- | ||
|
|
||
| from odoo import api, fields, models, tools, _ | ||
|
|
||
|
|
||
| class CurrencyAlias(models.Model): | ||
| _name = "res.currency.alias" | ||
|
|
||
| name = fields.Char(string='Currency Alias') | ||
| _sql_constraints = [ | ||
|
|
||
| ('unique_name', 'unique (name)', 'The currency alias must be unique!'), | ||
| ] | ||
|
|
||
| currency_id = fields.Many2one('res.currency', string='Currency', readonly=True) | ||
|
|
||
|
|
||
| class Currency(models.Model): | ||
| _inherit = "res.currency" | ||
|
|
||
| alias_ids = fields.One2many('res.currency.alias', 'currency_id', string='Aliases') | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # -*- coding: utf-8 -*- | ||
|
|
||
| from odoo import api, fields, models, _ | ||
|
|
||
|
|
||
| class Partner(models.Model): | ||
| _inherit = "res.partner" | ||
|
|
||
| def _default_em_currency(self): | ||
| return self.env.user.company_id.currency_id | ||
|
|
||
| em_currency_id = fields.Many2one('res.currency', | ||
| string="Base currency for personal expense management", | ||
| ondelete='restrict', | ||
| default=_default_em_currency) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <?xml version="1.0"?> | ||
| <odoo> | ||
| <record id="base.group_user" model="res.groups"> | ||
| <field name="implied_ids" eval="[(4, ref('base.group_multi_currency'))]"/> | ||
| </record> | ||
| </odoo> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <odoo> | ||
| <record id="view_currency_form_inherit_expense_manager" model="ir.ui.view"> | ||
| <field name="name">res.currency.form.inherit.expense_manager</field> | ||
| <field name="model">res.currency</field> | ||
| <field name="inherit_id" ref="base.view_currency_form"/> | ||
| <field name="arch" type="xml"> | ||
| <xpath expr="//sheet" position="inside"> | ||
| <notebook> | ||
| <page string="Aliases"> | ||
| <field name="alias_ids"> | ||
| <tree string="Currency Aliases" editable="bottom"> | ||
| <field name="name"/> | ||
| </tree> | ||
| </field> | ||
| </page> | ||
| </notebook> | ||
| </xpath> | ||
| </field> | ||
| </record> | ||
| </odoo> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <odoo> | ||
| <record id="view_partner_form_inherit_expense_manager" model="ir.ui.view"> | ||
| <field name="name">res.partner.form.inherit.expense_manager</field> | ||
| <field name="model">res.partner</field> | ||
| <field name="inherit_id" ref="base.view_partner_form"/> | ||
| <field name="arch" type="xml"> | ||
| <xpath expr="//notebook" position="inside"> | ||
| <page string="Personal Expenses"> | ||
| <group> | ||
| <field name="em_currency_id"/> | ||
| </group> | ||
| </page> | ||
| </xpath> | ||
| </field> | ||
| </record> | ||
| </odoo> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍