return False
def _get_payment_rate_currency(self, cr, uid, context=None):
- '''
+ """
Return the default value for field payment_rate_currency_id: the currency of the journal
if there is one, otherwise the currency of the user's company
- '''
+ """
if context is None: context = {}
journal_pool = self.pool.get('account.journal')
journal_id = context.get('journal_id', False)
def fields_view_get(self, cr, uid, view_id=None, view_type=False, context=None, toolbar=False, submenu=False):
mod_obj = self.pool.get('ir.model.data')
if context is None: context = {}
- if not view_id and context.get('invoice_type', False):
- if context.get('invoice_type', False) in ('out_invoice', 'out_refund'):
- result = mod_obj.get_object_reference(cr, uid, 'account_voucher', 'view_vendor_receipt_form')
- else:
- result = mod_obj.get_object_reference(cr, uid, 'account_voucher', 'view_vendor_payment_form')
- result = result and result[1] or False
- view_id = result
- if not view_id and view_type == 'form' and context.get('line_type', False):
- if context.get('line_type', False) == 'customer':
- result = mod_obj.get_object_reference(cr, uid, 'account_voucher', 'view_vendor_receipt_form')
- else:
- result = mod_obj.get_object_reference(cr, uid, 'account_voucher', 'view_vendor_payment_form')
- result = result and result[1] or False
- view_id = result
+
+ if view_type == 'form':
+ if not view_id and context.get('invoice_type'):
+ if context.get('invoice_type') in ('out_invoice', 'out_refund'):
+ result = mod_obj.get_object_reference(cr, uid, 'account_voucher', 'view_vendor_receipt_form')
+ else:
+ result = mod_obj.get_object_reference(cr, uid, 'account_voucher', 'view_vendor_payment_form')
+ result = result and result[1] or False
+ view_id = result
+ if not view_id and context.get('line_type'):
+ if context.get('line_type') == 'customer':
+ result = mod_obj.get_object_reference(cr, uid, 'account_voucher', 'view_vendor_receipt_form')
+ else:
+ result = mod_obj.get_object_reference(cr, uid, 'account_voucher', 'view_vendor_payment_form')
+ result = result and result[1] or False
+ view_id = result
res = super(account_voucher, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
doc = etree.XML(res['arch'])
line_ids = resolve_o2m_operations(cr, uid, line_pool, line_ids, ["amount"], context)
- total = 0.0
- total_tax = 0.0
for line in line_ids:
line_amount = 0.0
line_amount = line.get('amount',0.0)
tr_type = 'purchase'
else:
if not journal.default_credit_account_id or not journal.default_debit_account_id:
- raise osv.except_osv(_('Error !'), _('Please define default credit/debit account on the %s !') % (journal.name))
+ raise osv.except_osv(_('Error !'), _('Please define default credit/debit accounts on the journal "%s" !') % (journal.name))
account_id = journal.default_credit_account_id.id or journal.default_debit_account_id.id
tr_type = 'receipt'
default['value']['account_id'] = account_id
default['value']['type'] = ttype or tr_type
- vals = self.onchange_journal(cr, uid, ids, journal_id, line_ids, tax_id, partner_id, company_id, context)
+ vals = self.onchange_journal(cr, uid, ids, journal_id, line_ids, tax_id, partner_id, time.strftime('%Y-%m-%d'), price, ttype, company_id, context)
default['value'].update(vals.get('value'))
return default
def onchange_amount(self, cr, uid, ids, amount, rate, partner_id, journal_id, currency_id, ttype, date, payment_rate_currency_id, company_id, context=None):
if context is None:
context = {}
- res = self.onchange_partner_id(cr, uid, ids, partner_id, journal_id, amount, currency_id, ttype, date, context=context)
+ res = self.recompute_voucher_lines(cr, uid, ids, partner_id, journal_id, amount, currency_id, ttype, date, context=context)
ctx = context.copy()
ctx.update({'date': date})
vals = self.onchange_rate(cr, uid, ids, rate, amount, currency_id, payment_rate_currency_id, company_id, context=ctx)
res[key].update(vals[key])
return res
- def onchange_partner_id(self, cr, uid, ids, partner_id, journal_id, price, currency_id, ttype, date, context=None):
+ def recompute_payment_rate(self, cr, uid, ids, vals, currency_id, date, ttype, journal_id, amount, context=None):
+ if context is None:
+ context = {}
+ #on change of the journal, we need to set also the default value for payment_rate and payment_rate_currency_id
+ currency_obj = self.pool.get('res.currency')
+ journal = self.pool.get('account.journal').browse(cr, uid, journal_id, context=context)
+ company_id = journal.company_id.id
+ payment_rate = 1.0
+ payment_rate_currency_id = currency_id
+ ctx = context.copy()
+ ctx.update({'date': date})
+ o2m_to_loop = False
+ if ttype == 'receipt':
+ o2m_to_loop = 'line_cr_ids'
+ elif ttype == 'payment':
+ o2m_to_loop = 'line_dr_ids'
+ if o2m_to_loop and 'value' in vals and o2m_to_loop in vals['value']:
+ for voucher_line in vals['value'][o2m_to_loop]:
+ if voucher_line['currency_id'] != currency_id:
+ # we take as default value for the payment_rate_currency_id, the currency of the first invoice that
+ # is not in the voucher currency
+ payment_rate_currency_id = voucher_line['currency_id']
+ tmp = currency_obj.browse(cr, uid, payment_rate_currency_id, context=ctx).rate
+ voucher_currency_id = currency_id or journal.company_id.currency_id.id
+ payment_rate = tmp / currency_obj.browse(cr, uid, voucher_currency_id, context=ctx).rate
+ break
+ res = self.onchange_rate(cr, uid, ids, payment_rate, amount, currency_id, payment_rate_currency_id, company_id, context=ctx)
+ for key in res.keys():
+ vals[key].update(res[key])
+ vals['value'].update({'payment_rate': payment_rate})
+ if payment_rate_currency_id:
+ vals['value'].update({'payment_rate_currency_id': payment_rate_currency_id})
+ return vals
+
+ def onchange_partner_id(self, cr, uid, ids, partner_id, journal_id, amount, currency_id, ttype, date, context=None):
+ if not journal_id:
+ return {}
+ res = self.recompute_voucher_lines(cr, uid, ids, partner_id, journal_id, amount, currency_id, ttype, date, context=context)
+ vals = self.recompute_payment_rate(cr, uid, ids, res, currency_id, date, ttype, journal_id, amount, context=context)
+ for key in vals.keys():
+ res[key].update(vals[key])
+ return res
+
+ def recompute_voucher_lines(self, cr, uid, ids, partner_id, journal_id, price, currency_id, ttype, date, context=None):
"""
Returns a dict that contains new values and context
res = {'value': {}}
#set the period of the voucher
period_pool = self.pool.get('account.period')
+ currency_obj = self.pool.get('res.currency')
ctx = context.copy()
ctx.update({'company_id': company_id})
pids = period_pool.find(cr, uid, date, context=ctx)
ctx.update({'date': date})
payment_rate = 1.0
if payment_rate_currency_id != currency_id:
- payment_rate = self.pool.get('res.currency').browse(cr, uid, payment_rate_currency_id, context=ctx).rate
+ tmp = currency_obj.browse(cr, uid, payment_rate_currency_id, context=ctx).rate
+ voucher_currency_id = currency_id or self.pool.get('res.company').browse(cr, uid, company_id, context=ctx).currency_id.id
+ payment_rate = tmp / currency_obj.browse(cr, uid, voucher_currency_id, context=ctx).rate
vals = self.onchange_payment_rate_currency(cr, uid, ids, currency_id, payment_rate, payment_rate_currency_id, date, amount, company_id, context=context)
vals['value'].update({'payment_rate': payment_rate})
for key in vals.keys():
currency_id = False
if journal.currency:
currency_id = journal.currency.id
- ctx = context.copy()
- ctx.update({'date': date})
- #on change of the journal, we need to TODO coment me
- payment_rate = 1.0
-
- res = self.onchange_rate(cr, uid, ids, payment_rate, amount, currency_id, currency_id, company_id, context=ctx)
- for key in res.keys():
- vals[key].update(res[key])
- vals['value'].update({'payment_rate': payment_rate})
- vals['value'].update({'currency_id': currency_id})
- vals['value'].update({'payment_rate_currency_id': currency_id})
+ vals['value'].update({'currency_id': currency_id})
res = self.onchange_partner_id(cr, uid, ids, partner_id, journal_id, amount, currency_id, ttype, date, context)
for key in res.keys():
vals[key].update(res[key])
:return: mapping between fieldname and value of account move line to create
:rtype: dict
'''
- move_line_obj = self.pool.get('account.move.line')
- currency_obj = self.pool.get('res.currency')
voucher_brw = self.pool.get('account.voucher').browse(cr,uid,voucher_id,context)
debit = credit = 0.0
# TODO: is there any other alternative then the voucher type ??
:return: mapping between fieldname and value of account move to create
:rtype: dict
'''
- move_obj = self.pool.get('account.move')
seq_obj = self.pool.get('ir.sequence')
voucher_brw = self.pool.get('account.voucher').browse(cr,uid,voucher_id,context)
if voucher_brw.number:
def _get_exchange_lines(self, cr, uid, line, move_id, amount_residual, company_currency, current_currency, context=None):
'''
- Prepare the two lines due to currency rate difference.
+ Prepare the two lines in company currency due to currency rate difference.
- :param line: browse record of the voucher.line for which we want to create currency rate difference accounting entries
+ :param line: browse record of the voucher.line for which we want to create currency rate difference accounting
+ entries
:param move_id: Account move wher the move lines will be.
:param amount_residual: Amount to be posted.
:param company_currency: id of currency of the company to which the voucher belong
account_id = line.voucher_id.company_id.income_currency_exchange_account_id
if not account_id:
raise osv.except_osv(_('Warning'),_("Unable to create accounting entry for currency rate difference. You have to configure the field 'Expense Currency Rate' on the company! "))
-
+ # Even if the amount_currency is never filled, we need to pass the foreign currency because otherwise
+ # the receivable/payable account may have a secondary currency, which render this field mandatory
+ account_currency_id = company_currency <> current_currency and current_currency or False
move_line = {
'journal_id': line.voucher_id.journal_id.id,
'period_id': line.voucher_id.period_id.id,
'account_id': line.account_id.id,
'move_id': move_id,
'partner_id': line.voucher_id.partner_id.id,
- 'currency_id': company_currency <> current_currency and current_currency or False,
+ 'currency_id': account_currency_id,
'amount_currency': 0.0,
'quantity': 1,
'credit': amount_residual > 0 and amount_residual or 0.0,
'move_id': move_id,
'amount_currency': 0.0,
'partner_id': line.voucher_id.partner_id.id,
- 'currency_id': company_currency <> current_currency and current_currency or False,
+ 'currency_id': account_currency_id,
'quantity': 1,
'debit': amount_residual > 0 and amount_residual or 0.0,
'credit': amount_residual < 0 and -amount_residual or 0.0,
context = {}
move_line_obj = self.pool.get('account.move.line')
currency_obj = self.pool.get('res.currency')
+ tax_obj = self.pool.get('account.tax')
tot_line = line_total
rec_lst_ids = []
raise osv.except_osv(_('No Account Base Code and Account Tax Code!'),_("You have to configure account base code and account tax code on the '%s' tax!") % (tax_data.name))
# compute the amount in foreign currency
+ foreign_currency_diff = 0.0
amount_currency = False
if line.move_line_id:
+ voucher_currency = voucher_brw.currency_id and voucher_brw.currency_id.id or voucher_brw.journal_id.company_id.currency_id.id
# We want to set it on the account move line as soon as the original line had a foreign currency
if line.move_line_id.currency_id and line.move_line_id.currency_id.id != company_currency:
# we compute the amount in that foreign currency.
amount_currency = sign * (line.amount)
elif line.move_line_id.currency_id.id == voucher_brw.payment_rate_currency_id.id:
# if the rate is specified on the voucher, we must use it
- amount_currency = (move_line['debit'] - move_line['credit']) * voucher_brw.payment_rate
+ voucher_rate = currency_obj.browse(cr, uid, voucher_currency, context=ctx).rate
+ amount_currency = (move_line['debit'] - move_line['credit']) * voucher_brw.payment_rate * voucher_rate
else:
# otherwise we use the rates of the system (giving the voucher date in the context)
amount_currency = currency_obj.compute(cr, uid, company_currency, line.move_line_id.currency_id.id, move_line['debit']-move_line['credit'], context=ctx)
+ if line.amount == line.amount_unreconciled and line.move_line_id.currency_id.id == voucher_currency:
+ foreign_currency_diff = line.move_line_id.amount_residual_currency + amount_currency
move_line['amount_currency'] = amount_currency
voucher_line = move_line_obj.create(cr, uid, move_line)
rec_ids = [voucher_line, line.move_line_id.id]
if not currency_obj.is_zero(cr, uid, voucher_brw.company_id.currency_id, currency_rate_difference):
- # Change difference entry
+ # Change difference entry in company currency
exch_lines = self._get_exchange_lines(cr, uid, line, move_id, currency_rate_difference, company_currency, current_currency, context=context)
new_id = move_line_obj.create(cr, uid, exch_lines[0],context)
move_line_obj.create(cr, uid, exch_lines[1], context)
rec_ids.append(new_id)
+ if line.move_line_id and line.move_line_id.currency_id and not currency_obj.is_zero(cr, uid, line.move_line_id.currency_id, foreign_currency_diff):
+ # Change difference entry in voucher currency
+ move_line_foreign_currency = {
+ 'journal_id': line.voucher_id.journal_id.id,
+ 'period_id': line.voucher_id.period_id.id,
+ 'name': _('change')+': '+(line.name or '/'),
+ 'account_id': line.account_id.id,
+ 'move_id': move_id,
+ 'partner_id': line.voucher_id.partner_id.id,
+ 'currency_id': line.move_line_id.currency_id.id,
+ 'amount_currency': -1 * foreign_currency_diff,
+ 'quantity': 1,
+ 'credit': 0.0,
+ 'debit': 0.0,
+ 'date': line.voucher_id.date,
+ }
+ new_id = move_line_obj.create(cr, uid, move_line_foreign_currency, context=context)
+ rec_ids.append(new_id)
+
if line.move_line_id.id:
rec_lst_ids.append(rec_ids)
:return: mapping between fieldname and value of account move line to create
:rtype: dict
'''
- move_line_obj = self.pool.get('account.move.line')
currency_obj = self.pool.get('res.currency')
move_line = {}
'debit': diff < 0 and -diff or 0.0,
'amount_currency': company_currency <> current_currency and voucher_brw.writeoff_amount or False,
'currency_id': company_currency <> current_currency and current_currency or False,
+ 'analytic_account_id': voucher_brw.analytic_id and voucher_brw.analytic_id.id or False,
}
return move_line
context = {}
move_pool = self.pool.get('account.move')
move_line_pool = self.pool.get('account.move.line')
- currency_pool = self.pool.get('res.currency')
- tax_obj = self.pool.get('account.tax')
- seq_obj = self.pool.get('ir.sequence')
for voucher in self.browse(cr, uid, ids, context=context):
if voucher.move_id:
continue
# Create the writeoff line if needed
ml_writeoff = self.writeoff_move_line_get(cr, uid, voucher.id, line_total, move_id, name, company_currency, current_currency, context)
if ml_writeoff:
- ml_writeoff_id = move_line_pool.create(cr, uid, ml_writeoff, context)
+ move_line_pool.create(cr, uid, ml_writeoff, context)
# We post the voucher.
self.write(cr, uid, [voucher.id], {
'move_id': move_id,
'account_id':fields.many2one('account.account','Account', required=True),
'partner_id':fields.related('voucher_id', 'partner_id', type='many2one', relation='res.partner', string='Partner'),
'untax_amount':fields.float('Untax Amount'),
- 'amount':fields.float('Allocation', digits_compute=dp.get_precision('Account')),
+ 'amount':fields.float('Amount', digits_compute=dp.get_precision('Account')),
'reconcile': fields.boolean('Full Reconcile'),
'type':fields.selection([('dr','Debit'),('cr','Credit')], 'Dr/Cr'),
'account_analytic_id': fields.many2one('account.analytic.account', 'Analytic Account'),