1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# Copyright (c) 2008 Camptocamp SA All Rights Reserved. (JGG)
6
# WARNING: This program as such is intended to be used by professional
7
# programmers who take the whole responsability of assessing all potential
8
# consequences resulting from its eventual inadequacies and bugs
9
# End users who are looking for a ready-to-use solution with commercial
10
# garantees and support are strongly adviced to contract a Free Software
13
# This program is Free Software; you can redistribute it and/or
14
# modify it under the terms of the GNU General Public License
15
# as published by the Free Software Foundation; either version 2
16
# of the License, or (at your option) any later version.
18
# This program is distributed in the hope that it will be useful,
19
# but WITHOUT ANY WARRANTY; without even the implied warranty of
20
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
# GNU General Public License for more details.
23
# You should have received a copy of the GNU General Public License
24
# along with this program; if not, write to the Free Software
25
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27
##############################################################################
31
from tools.misc import UpdateableStr
34
FORM = UpdateableStr()
37
'lines': {'string': 'Invoices', 'type': 'many2many',
38
'relation': 'account.move.line'},
43
'date': {'string': 'Date payment', 'type': 'date','required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')},
44
'journal_id': {'string': 'Journal', 'type': 'many2many', 'relation': 'account.journal', 'domain': '[("type","in",["sale","purchase","cash"])]', '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, purchase and cash journals.'},
47
START_FORM = '''<?xml version="1.0"?>
48
<form string="Import Invoices in Statement">
49
<label string="Choose Journal and Payment Date" colspan="4"/>
51
<field name="journal_id" colspan="4"/>
54
def _search_invoices(obj, cr, uid, data, context):
55
pool = pooler.get_pool(cr.dbname)
56
line_obj = pool.get('account.move.line')
57
statement_obj = pool.get('account.bank.statement')
58
journal_obj = pool.get('account.journal')
60
statement = statement_obj.browse(cr, uid, data['id'], context=context)
61
journal_ids = data['form']['journal_id'][0][2]
64
journal_ids = journal_obj.search(cr, uid, [('type', 'in', ('sale','cash','purchase'))], context=context)
66
line_ids = line_obj.search(cr, uid, [
67
('reconcile_id', '=', False),
68
('journal_id', 'in', journal_ids),
69
('account_id.reconcile', '=', True)],
70
#order='date DESC, id DESC', #doesn't work
73
FORM.string = '''<?xml version="1.0"?>
74
<form string="Import Entries">
75
<field name="lines" colspan="4" height="300" width="800" nolabel="1"
76
domain="[('id', 'in', [%s])]"/>
77
</form>''' % (','.join([str(x) for x in line_ids]))
80
def _populate_statement(obj, cursor, user, data, context):
81
line_ids = data['form']['lines'][0][2]
82
line_date=data['form']['date']
86
pool = pooler.get_pool(cursor.dbname)
87
line_obj = pool.get('account.move.line')
88
statement_obj = pool.get('account.bank.statement')
89
statement_line_obj = pool.get('account.bank.statement.line')
90
currency_obj = pool.get('res.currency')
91
statement_reconcile_obj = pool.get('account.bank.statement.reconcile')
93
statement = statement_obj.browse(cursor, user, data['id'], context=context)
94
# for each selected move lines
95
for line in line_obj.browse(cursor, user, line_ids, context=context):
97
# take the date for computation of currency => use payment date
98
# if line.date_maturity:
99
# ctx['date'] = line.date_maturity
101
ctx['date'] = line_date
103
if line.amount_currency:
104
amount = currency_obj.compute(cursor, user, line.currency_id.id,
105
statement.currency.id, line.amount_currency, context=ctx)
109
elif line.credit > 0:
111
reconcile_id = statement_reconcile_obj.create(cursor, user, {
112
'line_ids': [(6, 0, [line.id])]
114
if line.journal_id.type == 'sale':
116
elif line.journal_id.type == 'purchase':
120
if not line.cost_center_id and line.cost_center_id.id:
121
raise wizard.except_wizard(_('Error !'), _("The cost center field is required in the movements'%s'!") % (line.name,))
122
statement_line_obj.create(cursor, user, {
123
'name': line.name or '?',
126
'partner_id': line.partner_id.id,
127
'account_id': line.account_id.id,
128
'statement_id': statement.id,
130
'reconcile_id': reconcile_id,
131
'date':line_date, #time.strftime('%Y-%m-%d'), #line.date_maturity or,
132
'cost_center_id': line.cost_center_id and line.cost_center_id.id,
137
class PopulateStatementFromInvoice(wizard.interface):
139
Populate the current statement with selected invoices
147
'fields':START_FIELD,
150
('go', '_Go', '', True),
155
'actions': [_search_invoices],
161
('end', '_Cancel','', True),
162
('finish', 'O_k','', True)
171
'action': _populate_statement,
176
PopulateStatementFromInvoice('populate_statement_from_invoice')
177
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: