Skip to Content
Menu
This question has been flagged

Hi everyone, I'm new to odoo. For my accounting entries, I do a multiple conversion on the debit, credit and balance lines for an operation carried out in a currency other than the one selected. How can I solve this?


def _get_report_vals(self, dates, entry_type, journal_id, company_id, prev_period, last_period, currency_id, fold_account_ids):
move_lines = []
domain = []
compare_period = []
if not isinstance(fold_account_ids, list):
fold_account_ids = [int(x) for x in fold_account_ids.split(',')] if fold_account_ids else []
if journal_id and journal_id not in ['0', 'undefined']:
domain += [('move_id.journal_id', '=', int(journal_id))]
if company_id and company_id not in ['0', 'undefined']:
domain += [('move_id.company_id', '=', int(company_id))]
if entry_type == 'all':
domain += [('move_id.state', 'in', ['draft', 'posted'])]
elif entry_type == 'draft':
domain += [('move_id.state', '=', 'draft')]
elif entry_type == 'posted':
domain += [('move_id.state', '=', 'posted')]
date_from, date_to = date_utils.get_month(fields.Date.context_today(self))
string = format_date(self.env, fields.Date.to_string(date_to), date_format='MMM YYYY')
quarter_names = get_quarter_names('abbreviated', locale=get_lang(self.env).code)
if dates == 'this_month':
string = format_date(self.env, fields.Date.to_string(date_to), date_format='MMM YYYY')
domain += [('date', '>=', date_from), ('date', '<=', date_to)]
elif dates == 'this_quarter':
date_from, date_to = date_utils.get_quarter(fields.Date.context_today(self))
string = u'%s\N{NO-BREAK SPACE}%s' % (quarter_names[date_utils.get_quarter_number(date_to)], date_to.year)
domain += [('date', '>=', date_from), ('date', '<=', date_to)]
elif dates == 'this_fin_year':
company_fiscalyear_dates = self.env.company.compute_fiscalyear_dates(fields.Date.context_today(self))
date_from = company_fiscalyear_dates['date_from']
date_to = company_fiscalyear_dates['date_to']
string = date_to.strftime('%Y')
domain += [('date', '>=', date_from), ('date', '<=', date_to)]
elif dates == 'last_month':
date_from, date_to = date_utils.get_month(fields.Date.context_today(self))
date_from = date_from - relativedelta(months=1)
date_to = date_to - relativedelta(months=1)
string = format_date(self.env, fields.Date.to_string(date_to), date_format='MMM YYYY')
domain += [('date', '>=', date_from), ('date', '<=', date_to)]
elif dates == 'last_quarter':
date_from, date_to = date_utils.get_quarter(fields.Date.context_today(self))
date_from = date_from - relativedelta(months=1)
date_from, date_to = date_utils.get_quarter(date_from)
string = u'%s\N{NO-BREAK SPACE}%s' % (quarter_names[date_utils.get_quarter_number(date_to)], date_to.year)
domain += [('date', '>=', date_from), ('date', '<=', date_to)]
elif dates == 'last_fin_year':
company_fiscalyear_dates = self.env.company.compute_fiscalyear_dates(fields.Date.context_today(self))
date_from = company_fiscalyear_dates['date_from']
date_to = company_fiscalyear_dates['date_to']
date_from = date_from - relativedelta(years=1)
date_to = date_to - relativedelta(years=1)
string = date_to.strftime('%Y')
domain += [('date', '>=', date_from), ('date', '<=', date_to)]
line_data = {}
selected_currency = currency_id or self.env.company.currency_id
if selected_currency and selected_currency not in ['0', 'undefined']:
selected_currency = self.env['res.currency'].browse(int(selected_currency))
else:
selected_currency = self.env.company.currency_id
rates_conversion = self.env['ir.config_parameter'].sudo().get_param('account_report_with_multi_currency.rates_conversion_date_selection')
if rates_conversion == 'transaction_date':
for mo_line in self.env['account.move.line'].search(domain, order='account_code asc'):
if mo_line.account_id not in line_data:
line_data[mo_line.account_id] = {}
line_data[mo_line.account_id]['debit'] = mo_line.currency_id._convert(mo_line.debit, selected_currency, self.env.company, mo_line.date or fields.Date.context_today(self))
line_data[mo_line.account_id]['credit'] = mo_line.currency_id._convert(mo_line.credit, selected_currency, self.env.company, mo_line.date or fields.Date.context_today(self))
line_data[mo_line.account_id]['amount_currency'] = mo_line.currency_id._convert(mo_line.amount_currency, selected_currency, self.env.company, mo_line.date or fields.Date.context_today(self))
line_data[mo_line.account_id]['date'] = mo_line.date
line_data[mo_line.account_id]['partner'] = ''
line_data[mo_line.account_id]['name'] = ''
line_data[mo_line.account_id]['account_id'] = mo_line.account_id.id

else:
line_data[mo_line.account_id]['debit'] += mo_line.currency_id._convert(mo_line.debit, selected_currency, self.env.company, mo_line.date or fields.Date.context_today(self))
line_data[mo_line.account_id]['credit'] += mo_line.currency_id._convert(mo_line.credit, selected_currency, self.env.company, mo_line.date or fields.Date.context_today(self))
line_data[mo_line.account_id]['amount_currency'] += mo_line.currency_id._convert(mo_line.amount_currency, selected_currency, self.env.company, mo_line.date or fields.Date.context_today(self))
else:
for mo_line in self.env['account.move.line'].search(domain, order='account_code asc'):
if mo_line.account_id not in line_data:
line_data[mo_line.account_id] = {}
line_data[mo_line.account_id]['debit'] = mo_line.currency_id._convert(mo_line.debit, selected_currency, self.env.company, date_from or fields.Date.context_today(self))
line_data[mo_line.account_id]['credit'] = mo_line.currency_id._convert(mo_line.credit, selected_currency, self.env.company, date_from or fields.Date.context_today(self))
line_data[mo_line.account_id]['amount_currency'] = mo_line.currency_id._convert(mo_line.amount_currency, selected_currency, self.env.company, date_from or fields.Date.context_today(self))
line_data[mo_line.account_id]['date'] = mo_line.date
line_data[mo_line.account_id]['partner'] = ''
line_data[mo_line.account_id]['name'] = ''
line_data[mo_line.account_id]['account_id'] = mo_line.account_id.id
else:
line_data[mo_line.account_id]['debit'] += mo_line.currency_id._convert(mo_line.debit, selected_currency, self.env.company, date_from or fields.Date.context_today(self))
line_data[mo_line.account_id]['credit'] += mo_line.currency_id._convert(mo_line.credit, selected_currency, self.env.company, date_from or fields.Date.context_today(self))
line_data[mo_line.account_id]['amount_currency'] += mo_line.currency_id._convert(mo_line.amount_currency, selected_currency, self.env.company, date_from or fields.Date.context_today(self))
# line_data = self.env['account.move.line'].read_group(domain, ['account_id', 'debit', 'credit', 'date', 'partner_id', 'amount_currency', 'move_name'], ['account_id'])
for account in line_data:
lines = self.env['account.move.line'].search(domain + [('account_id', '=', account.id)])
move_line_list = []
for line in lines:
move_line_data = {}
move_line_data['id'] = line.id
move_line_data['move_name'] = line.move_id.name
move_line_data['move_id'] = line.move_id.id
move_line_data['model'] = line.move_id._name
move_line_data['date'] = line.date
move_line_data['name'] = line.name
move_line_data['partner_id'] = line.partner_id.name
# move_line_data['is_foldernle'] = True if line.account_id.id in fold_account_ids else False
if rates_conversion == 'transaction_date':
move_line_data['debit'] = line.currency_id._convert(line.debit, selected_currency, self.env.company, line.date or fields.Date.context_today(self))
move_line_data['credit'] = line.currency_id._convert(line.credit, selected_currency, self.env.company, line.date or fields.Date.context_today(self))
move_line_data['amount_currency'] = line.currency_id._convert(line.amount_currency, selected_currency, self.env.company, line.date or fields.Date.context_today(self))
move_line_data['total'] = line.currency_id._convert(line.debit - line.credit, selected_currency, self.env.company, line.date or fields.Date.context_today(self))
else:
move_line_data['debit'] = line.currency_id._convert(line.debit, selected_currency, self.env.company, date_from or fields.Date.context_today(self))
move_line_data['credit'] = line.currency_id._convert(line.credit, selected_currency, self.env.company, date_from or fields.Date.context_today(self))
move_line_data['amount_currency'] = line.currency_id._convert(line.amount_currency, selected_currency, self.env.company, date_from or fields.Date.context_today(self))
move_line_data['total'] = line.currency_id._convert(line.debit - line.credit, selected_currency, self.env.company, date_from or fields.Date.context_today(self))

move_line_list.append(move_line_data)

partner = self.env['res.partner']
if 'partner_id' in line_data[account]:
partner = self.env['res.partner'].browse(line_data[account]['partner_id'][0])
vals = {
'name': line_data[account]['name'],
'account': account.display_name,
'debit': line_data[account]['debit'],
'credit': line_data[account]['credit'],
'amount_currency': line_data[account]['amount_currency'],
'date': line_data[account]['date'],
'partner': partner.display_name,
'lines': move_line_list,
'account_id': account.id,
'model': "account.move.line"
}
move_lines.append(vals)
# currency_id = self.env.company.currency_id
return {
'move_lines': move_lines,
'string': string,
'report_currency_id': selected_currency,
'currency_id': selected_currency.id,
'compare_period': compare_period,
'fold_account_ids': fold_account_ids if fold_account_ids else []
}
Avatar
Discard

I don't know why you struggle with this. Odoo manage foreign currency very efficient in accounting.

Related Posts Replies Views Activity
1
May 23
5405
2
Jan 23
3631
1
Aug 15
7385
3
Mar 15
6660
4
May 24
3034