summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuentin <qdp@jade>2009-01-20 18:29:04 +0100
committerQuentin <qdp@jade>2009-01-20 18:29:04 +0100
commitd3ab3d05533cd9bef39eae4bc44bf9bcd9d90a67 (patch)
treee4e420dbad6826e3b0d46ff716337a47cdbca88f
parentbb9e48c18362b6e62f0ea75f18c0d90dd011ab2d (diff)
[IMP] the importing of invoices from bank.statement are now more generic and allow user to select journals for filtering
bzr revid: qdp@jade-20090120172904-8q63hrpj8me3yp31
-rw-r--r--addons/account/wizard/wizard_statement_from_invoice.py76
1 files changed, 34 insertions, 42 deletions
diff --git a/addons/account/wizard/wizard_statement_from_invoice.py b/addons/account/wizard/wizard_statement_from_invoice.py
index b32d4933ad6..351e7197546 100644
--- a/addons/account/wizard/wizard_statement_from_invoice.py
+++ b/addons/account/wizard/wizard_statement_from_invoice.py
@@ -40,26 +40,49 @@ FIELDS = {
START_FIELD = {
'date': {'string': 'Date payment', 'type': 'date','required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')},
-
+ 'journal_id': {'string': 'Journal', 'type': 'many2many', 'relation': 'account.journal', 'domain': '[("type","in",["sale","purchase"])]', 'help': 'This field allow you to choose the accounting journals you want for filtering the invoices. If you left this field empty, it will search on all sale and purchase journals.'},
}
+
START_FORM = '''<?xml version="1.0"?>
<form string="Import invoices in statement">
- <label string="Choose invoice type and payment date" colspan="4"/>
+ <label string="Choose Journal and Payment Date" colspan="4"/>
<field name="date"/>
+ <field name="journal_id" colspan="4"/>
</form>'''
-def _search_customer_invoices(obj, cursor, user, data, context):
- pool = pooler.get_pool(cursor.dbname)
+def _search_invoices(obj, cr, uid, data, context):
+ pool = pooler.get_pool(cr.dbname)
line_obj = pool.get('account.move.line')
statement_obj = pool.get('account.bank.statement')
+ journal_obj = pool.get('account.journal')
- statement = statement_obj.browse(cursor, user, data['id'], context=context)
- line_ids = line_obj.search(cursor, user, [
+ statement = statement_obj.browse(cr, uid, data['id'], context=context)
+ journal_ids = data['form']['journal_id'][0][2]
+
+ if journal_ids == []:
+ sale_journal_ids = journal_obj.search(cr, uid, [('type', '=', 'sale')], context=context)
+ pur_journal_ids = journal_obj.search(cr, uid, [('type', '=', 'purchase')], context=context)
+ else:
+ pur_journal_ids = sale_journal_ids = []
+ for journal in pool.get('account.journal').browse(cr, uid, journal_ids):
+ if journal.type == 'sale':
+ sale_journal_ids.append(journal.id)
+ else:
+ pur_journal_ids.append(journal.id)
+
+ line_ids = line_obj.search(cr, uid, [
('reconcile_id', '=', False),
+ ('journal_id', 'in', sale_journal_ids),
('account_id.type', '=', 'receivable')],
#order='date DESC, id DESC', #doesn't work
context=context)
-
+ line_ids += line_obj.search(cr, uid, [
+ ('reconcile_id', '=', False),
+ ('journal_id', 'in', pur_journal_ids),
+ ('account_id.type', '=', 'payable')],
+ #order='date DESC, id DESC', #doesn't work
+ context=context)
+
FORM.string = '''<?xml version="1.0"?>
<form string="Import entries from customer invoice">
<field name="lines" colspan="4" height="300" width="800" nolabel="1"
@@ -68,25 +91,6 @@ def _search_customer_invoices(obj, cursor, user, data, context):
return {'type':'customer'}
# return {'lines': line_ids,'type':'customer'}
-def _search_supplier_invoices(obj, cursor, user, data, context):
- pool = pooler.get_pool(cursor.dbname)
- line_obj = pool.get('account.move.line')
- statement_obj = pool.get('account.bank.statement')
- statement = statement_obj.browse(cursor, user, data['id'], context=context)
- line_ids = line_obj.search(cursor, user, [
- ('reconcile_id', '=', False),
- ('account_id.type', '=', 'payable')
- ], context=context)
- # order='date DESC, id DESC', context=context) #doesn't work
- FORM.string = '''<?xml version="1.0"?>
-<form string="Import entries from supplier invoice">
- <field name="lines" colspan="4" height="300" width="800" nolabel="1"
- domain="[('id', 'in', [%s])]"/>
-</form>''' % (','.join([str(x) for x in line_ids]))
- return {'type':'supplier'}
- # return {'lines': line_ids,'type':'supplier'}
-
-
def _populate_statement(obj, cursor, user, data, context):
line_ids = data['form']['lines'][0][2]
line_date=data['form']['date']
@@ -147,25 +151,12 @@ class PopulateStatementFromInv(wizard.interface):
'fields':START_FIELD,
'state': [
('end', '_Cancel'),
- ('customer', '_Customer invoices', '', True),
- ('supplier', '_Supplier invoices', '', True)
- ]
- },
- },
- 'customer': {
- 'actions': [_search_customer_invoices],
- 'result': {
- 'type': 'form',
- 'arch': FORM,
- 'fields': FIELDS,
- 'state': [
- ('end', '_Cancel','', True),
- ('finish', 'O_k','', True)
+ ('go', '_Go', '', True),
]
},
},
- 'supplier': {
- 'actions': [_search_supplier_invoices],
+ 'go': {
+ 'actions': [_search_invoices],
'result': {
'type': 'form',
'arch': FORM,
@@ -176,6 +167,7 @@ class PopulateStatementFromInv(wizard.interface):
]
},
},
+
'finish': {
'actions': [],
'result': {