summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabien Pinckaers <fp@tinyerp.com>2008-06-16 13:48:57 +0000
committerFabien Pinckaers <fp@tinyerp.com>2008-06-16 13:48:57 +0000
commitab9cd583f8b010edfac07546f08dbf21f09b4b47 (patch)
treeb09a9855243f7b07b28bbc0af441e473d46ce655
parent74be20fc69f0c675ba050888da1c4d5747ebae53 (diff)
Bugfix Pay Invoice Wizard
bzr revid: fp@tinyerp.com-f898a8ebb7de7cbbcac763c71961b84f4126516c
-rw-r--r--addons/account/account_move_line.py32
-rw-r--r--addons/account/invoice.py11
-rw-r--r--addons/account/wizard/wizard_pay_invoice.py30
3 files changed, 52 insertions, 21 deletions
diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py
index 66948c51593..fb673995390 100644
--- a/addons/account/account_move_line.py
+++ b/addons/account/account_move_line.py
@@ -696,20 +696,28 @@ class account_move_line(osv.osv):
raise osv.except_osv('No piece number !', 'Can not create an automatic sequence for this piece !\n\nPut a sequence in the journal definition for automatic numbering or create a sequence manually for this piece.')
ok = not (journal.type_control_ids or journal.account_control_ids)
- if ('account_id' in vals) and journal.type_control_ids:
- type = account_obj.browse(cr, uid, vals['account_id']).type
- for t in journal.type_control_ids:
- if type==t.code:
- ok = True
- break
- if ('account_id' in vals) and journal.account_control_ids and not ok:
- for a in journal.account_control_ids:
- if a.id==vals['account_id']:
- ok = True
- break
+ if ('account_id' in vals):
+ account = account_obj.browse(cr, uid, vals['account_id'])
+ if journal.type_control_ids:
+ type = account.type
+ for t in journal.type_control_ids:
+ if type==t.code:
+ ok = True
+ break
+ if journal.account_control_ids and not ok:
+ for a in journal.account_control_ids:
+ if a.id==vals['account_id']:
+ ok = True
+ break
+ if (account.currency_id) and 'amount_currency' not in vals:
+ vals['currency_id'] = account.currency_id.id
+ cur_obj = self.pool.get('res.currency')
+ ctx = {}
+ if 'date' in vals:
+ ctx['date'] = vals['date']
+ vals['amount_currency'] = cur_obj.compute(cr, uid, account.company_id.currency_id.id, account.currency_id.id, vals.get('debit', 0.0)+vals.get('credit', 0.0), context=ctx)
if not ok:
raise osv.except_osv('Bad account !', 'You can not use this general account in this journal !')
-
result = super(osv.osv, self).create(cr, uid, vals, context)
if check:
self.pool.get('account.move').validate(cr, uid, [vals['move_id']], context)
diff --git a/addons/account/invoice.py b/addons/account/invoice.py
index 0c0aafd33cc..48e5b1b2885 100644
--- a/addons/account/invoice.py
+++ b/addons/account/invoice.py
@@ -674,16 +674,17 @@ class account_invoice(osv.osv):
new_ids.append(self.create(cr, uid, invoice))
return new_ids
- def pay_and_reconcile(self, cr, uid, ids, pay_amount, pay_account_id, period_id, pay_journal_id, writeoff_acc_id, writeoff_period_id, writeoff_journal_id, context={}):
+ def pay_and_reconcile(self, cr, uid, ids, pay_amount, pay_account_id, period_id, pay_journal_id, writeoff_acc_id, writeoff_period_id, writeoff_journal_id, context={}, name=''):
#TODO check if we can use different period for payment and the writeoff line
assert len(ids)==1, "Can only pay one invoice at a time"
invoice = self.browse(cr, uid, ids[0])
src_account_id = invoice.account_id.id
journal = self.pool.get('account.journal').browse(cr, uid, pay_journal_id)
- if journal.sequence_id:
- name = self.pool.get('ir.sequence').get_id(cr, uid, journal.sequence_id.id)
- else:
- raise osv.except_osv('No piece number !', 'Can not create an automatic sequence for this piece !\n\nPut a sequence in the journal definition for automatic numbering or create a sequence manually for this piece.')
+ if not name:
+ if journal.sequence_id:
+ name = self.pool.get('ir.sequence').get_id(cr, uid, journal.sequence_id.id)
+ else:
+ raise osv.except_osv('No piece number !', 'Can not create an automatic sequence for this piece !\n\nPut a sequence in the journal definition for automatic numbering or create a sequence manually for this piece.')
types = {'out_invoice': -1, 'in_invoice': 1, 'out_refund': 1, 'in_refund': -1}
direction = types[invoice.type]
l1 = {
diff --git a/addons/account/wizard/wizard_pay_invoice.py b/addons/account/wizard/wizard_pay_invoice.py
index 784e6d80c3b..706f3f92b10 100644
--- a/addons/account/wizard/wizard_pay_invoice.py
+++ b/addons/account/wizard/wizard_pay_invoice.py
@@ -30,16 +30,22 @@
import wizard
import netsvc
import pooler
+import time
pay_form = '''<?xml version="1.0"?>
<form string="Pay invoice">
<field name="amount"/>
+ <newline/>
+ <field name="name"/>
+ <field name="date"/>
<field name="journal_id"/>
<field name="period_id"/>
</form>'''
pay_fields = {
'amount': {'string': 'Amount paid', 'type':'float', 'required':True},
+ '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', 'type': 'many2one', 'relation':'account.journal', 'required':True, 'domain':[('type','=','cash')]},
'period_id': {'string': 'Period', 'type': 'many2one', 'relation':'account.period', 'required':True},
}
@@ -51,17 +57,29 @@ def _pay_and_reconcile(self, cr, uid, data, context):
writeoff_account_id = form.get('writeoff_acc_id', False)
writeoff_journal_id = form.get('writeoff_journal_id', False)
pool = pooler.get_pool(cr.dbname)
- acc_id = pool.get('account.journal').browse(cr, uid, journal_id, context).default_credit_account_id.id
+ cur_obj = pool.get('res.currency')
+ amount = form['amount']
+
+ 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 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)
+
+ acc_id = journal.default_credit_account_id and journal.default_credit_account_id.id
if not acc_id:
raise wizard.except_wizard('Error !', 'Your journal must have a default credit and debit account.')
pool.get('account.invoice').pay_and_reconcile(cr, uid, [data['id']],
- form['amount'], acc_id, period_id, journal_id, writeoff_account_id,
- period_id, writeoff_journal_id, context=context)
+ amount, acc_id, period_id, journal_id, writeoff_account_id,
+ period_id, writeoff_journal_id, context, data['form']['name'])
return {}
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<>journal.currency.id:
+ return 'addendum'
if pool.get('res.currency').is_zero(cr, uid, invoice.currency_id,
(data['form']['amount'] - invoice.amount_total)):
return 'reconcile'
@@ -91,7 +109,11 @@ def _get_period(self, cr, uid, data, context={}):
invoice = pool.get('account.invoice').browse(cr, uid, data['id'], context)
if invoice.state == 'draft':
raise wizard.except_wizard('Error !', 'Can not pay draft invoice.')
- return {'period_id': period_id, 'amount': invoice.amount_total}
+ return {
+ 'period_id': period_id,
+ 'amount': invoice.amount_total,
+ 'date': time.strftime('%Y-%m-%d')
+ }
class wizard_pay_invoice(wizard.interface):
states = {