diff --git a/addons/account/account_bank_statement.py b/addons/account/account_bank_statement.py
index 56c4ddba96e..a4431518a08 100644
--- a/addons/account/account_bank_statement.py
+++ b/addons/account/account_bank_statement.py
@@ -170,7 +170,9 @@ class account_bank_statement(osv.osv):
if line.state <> 'valid':
raise osv.except_osv(_('Error !'),
_('The account entries lines are not in valid state.'))
-
+ # for bank.statement.lines
+ # In line we get reconcile_id on bank.ste.rec.
+ # in bank stat.rec we get line_new_ids on bank.stat.rec.line
for move in st.line_ids:
move_id = account_move_obj.create(cr, uid, {
'journal_id': st.journal_id.id,
@@ -209,7 +211,7 @@ class account_bank_statement(osv.osv):
'period_id': st.period_id.id,
'currency_id': st.currency.id,
}
-
+
amount = res_currency_obj.compute(cr, uid, st.currency.id,
company_currency_id, move.amount, context=context,
account=acc_cur)
@@ -245,6 +247,7 @@ class account_bank_statement(osv.osv):
'statement_id': st.id,
'journal_id': st.journal_id.id,
'period_id': st.period_id.id,
+
}, context=context)
# Fill the secondary amount/currency
@@ -491,11 +494,14 @@ class account_bank_statement_reconcile_line(osv.osv):
_name = "account.bank.statement.reconcile.line"
_description = "Statement reconcile line"
_columns = {
- 'name': fields.char('Description', size=64),
+ 'name': fields.char('Description', size=64, required=True),
'account_id': fields.many2one('account.account', 'Account', required=True),
'line_id': fields.many2one('account.bank.statement.reconcile', 'Reconcile'),
'amount': fields.float('Amount', required=True),
}
+ _defaults = {
+ 'name': lambda *a: 'Write-Off',
+ }
account_bank_statement_reconcile_line()
diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py
index d7c098de206..f31fca91a44 100644
--- a/addons/account/account_move_line.py
+++ b/addons/account/account_move_line.py
@@ -616,6 +616,7 @@ class account_move_line(osv.osv):
'debit':debit,
'credit':credit,
'account_id':writeoff_acc_id,
+ 'analytic_account_id': context.get('analytic_id', False),
'date':date,
'partner_id':partner_id
})
@@ -624,7 +625,7 @@ class account_move_line(osv.osv):
writeoff_move_id = self.pool.get('account.move').create(cr, uid, {
'period_id': writeoff_period_id,
'journal_id': writeoff_journal_id,
-
+ 'date':date,
'state': 'draft',
'line_id': writeoff_lines
})
@@ -869,7 +870,7 @@ class account_move_line(osv.osv):
'amount': vals['debit'] or vals['credit'],
'general_account_id': vals['account_id'],
'journal_id': journal.analytic_journal_id.id,
- 'ref': vals['ref'],
+ 'ref': vals.get('ref', False),
})]
#else:
# raise osv.except_osv(_('No analytic journal !'), _('Please set an analytic journal on this financial journal !'))
diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml
index 97c50abdea8..91ebe4ba662 100644
--- a/addons/account/account_view.xml
+++ b/addons/account/account_view.xml
@@ -335,6 +335,7 @@
+
@@ -345,6 +346,7 @@
'''
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')]},
@@ -53,18 +54,24 @@ def _pay_and_reconcile(self, cr, uid, data, context):
pool = pooler.get_pool(cr.dbname)
cur_obj = pool.get('res.currency')
amount = form['amount']
+ context['analytic_id'] = form.get('analytic_id', False)
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={'date_p':form['date'],'comment':form['comment']}
+ context.update({'date_p':form['date'],'comment':form['comment']})
else:
- context={'date_p':form['date'],'comment':False}
+ context.update({'date_p':form['date'],'comment':False})
acc_id = journal.default_credit_account_id and journal.default_credit_account_id.id
if not acc_id:
@@ -78,31 +85,53 @@ def _wo_check(self, cr, uid, data, context):
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 current 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']
+ # Get the old payment if there are some
+ if invoice.payment_ids:
+ debit=credit=0.0
+ for payment in invoice.payment_ids:
+ debit+=payment.debit
+ credit+=payment.credit
+ amount_paid+=abs(debit-credit)
+
+ # 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'
_transaction_add_form = '''
'''
_transaction_add_fields = {
'writeoff_acc_id': {'string':'Write-Off account', 'type':'many2one', 'relation':'account.account', 'required':True},
'writeoff_journal_id': {'string': 'Write-Off journal', 'type': 'many2one', 'relation':'account.journal', 'required':True},
- 'comment': {'string': 'Entry Name', 'type':'char', 'size': 64, 'required':True},
+ 'comment': {'string': 'Comment', 'type':'char', 'size': 64 , 'required':True},
+ 'analytic_id': {'string':'Analytic Account', 'type': 'many2one', 'relation':'account.analytic.account'},
}
def _get_value_addendum(self, cr, uid, data, context={}):
- return {}
+ return {'comment': _('Write-Off')}
def _get_period(self, cr, uid, data, context={}):
pool = pooler.get_pool(cr.dbname)
diff --git a/addons/account/wizard/wizard_reconcile.py b/addons/account/wizard/wizard_reconcile.py
index d1f98ec191e..2b5385043d6 100644
--- a/addons/account/wizard/wizard_reconcile.py
+++ b/addons/account/wizard/wizard_reconcile.py
@@ -25,6 +25,8 @@ import netsvc
import time
import osv
import pooler
+from datetime import datetime
+from tools.translate import _
_transaction_form = '''
'''
_transaction_add_fields = {
'journal_id': {'string': 'Write-Off Journal', 'type': 'many2one', 'relation':'account.journal', 'required':True},
- 'period_id': {'string': 'Write-Off Period', 'type': 'many2one', 'relation':'account.period', 'required':True},
'writeoff_acc_id': {'string':'Write-Off account', 'type':'many2one', 'relation':'account.account', 'required':True},
+ 'date_p': {'string':'Date','type':'date'},
+ 'comment': {'string':'Comment','type':'char', 'size': 64, 'required':True},
+ 'analytic_id': {'string':'Analytic Account', 'type': 'many2one', 'relation':'account.analytic.account'},
}
def _trans_rec_addendum(self, cr, uid, data, context={}):
- pool = pooler.get_pool(cr.dbname)
- ids = pool.get('account.period').find(cr, uid, context=context)
- period_id = False
- if len(ids):
- period_id = ids[0]
- return {'period_id':period_id}
+ date_p = time.strftime('%Y-%m-%d')
+ return {'date_p':date_p, 'comment': _('Write-Off')}
class wiz_reconcile(wizard.interface):
diff --git a/addons/account_payment/wizard/wizard_payment_order.py b/addons/account_payment/wizard/wizard_payment_order.py
index 2e84efa5fa8..60dd10010b2 100644
--- a/addons/account_payment/wizard/wizard_payment_order.py
+++ b/addons/account_payment/wizard/wizard_payment_order.py
@@ -95,6 +95,7 @@ def create_payment(self, cr, uid, data, context):
'partner_id': line.partner_id and line.partner_id.id or False,
'communication': line.ref or '/',
'date': date_to_pay,
+ 'currency': line.invoice and line.invoice.currency_id.id or False,
}, context=context)
return {}