date=context['date_p']
else:
date=time.strftime('%Y-%m-%d')
+
+ # Take the amount in currency and the currency of the payment
+ if 'amount_currency' in context and context['amount_currency'] and 'currency_id' in context and context['currency_id']:
+ amount_currency = context['amount_currency']
+ currency_id = context['currency_id']
+ else:
+ amount_currency = False
+ currency_id = False
+
+ # Pay attention to the sign for both debit/credit AND amount_currency
l1 = {
'debit': direction * pay_amount>0 and direction * pay_amount,
'credit': direction * pay_amount<0 and - direction * pay_amount,
'partner_id': invoice.partner_id.id,
'ref':invoice.number,
'date': date,
+ 'currency_id':currency_id,
+ 'amount_currency':amount_currency and direction * amount_currency or 0.0,
}
l2 = {
'debit': direction * pay_amount<0 and - direction * pay_amount,
'partner_id': invoice.partner_id.id,
'ref':invoice.number,
'date': date,
+ 'currency_id':currency_id,
+ 'amount_currency':amount_currency and - direction * amount_currency or 0.0,
}
if not name:
import pooler
import time
from tools.translate import _
+import tools
pay_form = '''<?xml version="1.0"?>
<form string="Pay invoice">
</form>'''
pay_fields = {
- 'amount': {'string': 'Amount paid', 'type':'float', 'required':True},
+ 'amount': {'string': 'Amount paid', 'type':'float', 'required':True, 'digits': (16,int(tools.config['price_accuracy']))},
'name': {'string': 'Entry Name', 'type':'char', 'size': 64, 'required':True},
'date': {'string': 'Payment date', 'type':'date', 'required':True, 'default':lambda *args: time.strftime('%Y-%m-%d')},
'journal_id': {'string': 'Journal/Payment Mode', 'type': 'many2one', 'relation':'account.journal', 'required':True, 'domain':[('type','=','cash')]},
invoice = pool.get('account.invoice').browse(cr, uid, data['id'], context)
journal = pool.get('account.journal').browse(cr, uid, data['form']['journal_id'], context)
+ # Compute the amount in company's currency, with the journal currency (which is equal to payment currency)
+ # when it is needed : If payment currency (according to selected journal.currency) is <> from company currency
if journal.currency and invoice.company_id.currency_id.id<>journal.currency.id:
ctx = {'date':data['form']['date']}
amount = cur_obj.compute(cr, uid, journal.currency.id, invoice.company_id.currency_id.id, amount, context=ctx)
-
+ currency_id = journal.currency.id
+ # Put the paid amount in currency, and the currency, in the context if currency is different from company's currency
+ context.update({'amount_currency':form['amount'],'currency_id':currency_id})
+
# Take the choosen date
if form.has_key('comment'):
context.update({'date_p':form['date'],'comment':form['comment']})
pool = pooler.get_pool(cr.dbname)
invoice = pool.get('account.invoice').browse(cr, uid, data['id'], context)
journal = pool.get('account.journal').browse(cr, uid, data['form']['journal_id'], context)
- if invoice.company_id.currency_id.id <> invoice.currency_id.id:
- return 'addendum'
- if journal.currency and (journal.currency.id <> invoice.currency_id.id):
- return 'addendum'
- if pool.get('res.currency').is_zero(cr, uid, invoice.currency_id,
- (data['form']['amount'] - invoice.amount_total)):
+ cur_obj = pool.get('res.currency')
+ # Here we need that:
+ # The invoice total amount in company's currency <> paid amount in company currency
+ # (according to the correct day rate, invoicing rate and payment rate are may be different)
+ # => Ask to a write-off of the difference. This could happen even if both amount are equal,
+ # because if the currency rate
+ # Get the amount in company currency for the invoice (according to move lines)
+ inv_amount_company_currency=invoice.move_id.amount
+ # Get the amount paid in company currency
+ if journal.currency and invoice.company_id.currency_id.id<>journal.currency.id:
+ ctx = {'date':data['form']['date']}
+ amount_paid = cur_obj.compute(cr, uid, journal.currency.id, invoice.company_id.currency_id.id, data['form']['amount'], round=True, context=ctx)
+ else:
+ amount_paid = data['form']['amount']
+ # Test if there is a difference according to currency rouding setting
+ if pool.get('res.currency').is_zero(cr, uid, invoice.company_id.currency_id,
+ (amount_paid - inv_amount_company_currency)):
return 'reconcile'
return 'addendum'