Merge lp:~therp-nl/banking-addons/6.1-bank_statement_instant_voucher into lp:banking-addons/6.1

Proposed by Stefan Rijnhart (Opener)
Status: Merged
Merged at revision: 143
Proposed branch: lp:~therp-nl/banking-addons/6.1-bank_statement_instant_voucher
Merge into: lp:banking-addons/6.1
Diff against target: 688 lines (+645/-0)
8 files modified
bank_statement_instant_voucher/__init__.py (+1/-0)
bank_statement_instant_voucher/__openerp__.py (+56/-0)
bank_statement_instant_voucher/i18n/nl.po (+158/-0)
bank_statement_instant_voucher/model/__init__.py (+2/-0)
bank_statement_instant_voucher/model/account_bank_statement_line.py (+49/-0)
bank_statement_instant_voucher/model/account_voucher_instant.py (+306/-0)
bank_statement_instant_voucher/view/account_bank_statement_line.xml (+21/-0)
bank_statement_instant_voucher/view/account_voucher_instant.xml (+52/-0)
To merge this branch: bzr merge lp:~therp-nl/banking-addons/6.1-bank_statement_instant_voucher
Reviewer Review Type Date Requested Status
Guewen Baconnier @ Camptocamp no test, review Approve
Review via email: mp+133907@code.launchpad.net

Description of the change

This module adds the option of instantly creating a sales or purchase voucher based on a specific statement line.

Although this module is not dependent on account_banking, if this module is installed, upon confirmation of the wizard that created the voucher the statement line will be confirmed and reconciled with the voucher.

Depends on the merge of https://code.launchpad.net/~therp-nl/banking-addons/6.1-lp1066826-matching_wizard_on_manual_statements for creating import transactions on the fly for manually encoded statements

To post a comment you must log in.
142. By Stefan Rijnhart (Opener)

[FIX] Select view based on voucher type
[FIX] Use different icon than interactive reconcilation wizard from Banking Addons

143. By Stefan Rijnhart (Opener)

[IMP] Take conditional defaults into account when creating voucher

144. By Stefan Rijnhart (Opener)

[IMP] Take advantage of instantly created import transactions on
 manually encoded statements

 See https://code.launchpad.net/~therp-nl/banking-addons/6.1-lp1066826-matching_wizard_on_manual_statements

Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

Hi,

319+from osv import osv, fields
320+from tools.translate import _
The full import pathes should now be used as per the new Model classes
Example
from openerp.osv import orm, osv, fields
from openerp.tools.translate import _

class instant_voucher(orm.TransientModel):

277+ context['active_id'] = ids[0]
285+ 'context': context,
you probably want to use the local_context created just upper (line 276)

332+ instant = self.browse(cr, uid, ids[0], context=context)
361+ instant = self.browse(cr, uid, ids[0], context=context)
496+ instant = self.browse(cr, uid, ids[0], context=context)
As the first item only of the ids argument is used, it would be a good idea
to check that only 1 id have been given. ie. use an assert

345+ for (key, val) in vals.items():
Better have to use vals.iteritems() to avoid the generation of a unnecessary list.

340+ def update_voucher_defaults(
It should not return a None value because it is callable from XML/RPC.
I had been mingled by the vals which is a mutable argument and modified in place.
I would have returned only the default vals in this method and updated the vals in the callee method.

145. By Stefan Rijnhart (Opener)

[FIX] Style and optimalizations as per review

Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

Looks fine!

review: Approve (no test, review)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added directory 'bank_statement_instant_voucher'
=== added file 'bank_statement_instant_voucher/__init__.py'
--- bank_statement_instant_voucher/__init__.py 1970-01-01 00:00:00 +0000
+++ bank_statement_instant_voucher/__init__.py 2012-12-05 20:19:21 +0000
@@ -0,0 +1,1 @@
1import model
02
=== added file 'bank_statement_instant_voucher/__openerp__.py'
--- bank_statement_instant_voucher/__openerp__.py 1970-01-01 00:00:00 +0000
+++ bank_statement_instant_voucher/__openerp__.py 2012-12-05 20:19:21 +0000
@@ -0,0 +1,56 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# OpenERP, Open Source Management Solution
5# This module copyright (C) 2012 Therp BV (<http://therp.nl>).
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21{
22 "name": "Bank statement instant voucher",
23 "version": "1.0r028",
24 "author": "Therp BV",
25 "category": 'Base',
26 'complexity': "normal",
27 "description": """
28This module adds a new button on the bank statement line that allows the
29accountant to instantly create a sales or purchase voucher based on the
30values of the bank statement line.
31
32This module does not depend on account_banking, but if this module is
33installed, the bank statement line will be reconciled automatically
34in the confirmation step of the wizard.
35
36If account_banking is not installed, the accountant will still have to
37reconcile the associated move line with the move line from the bank
38statement line manually.
39
40If the wizard is cancelled,the created voucher will be deleted again.
41
42Known limitations:
43
44Currency conversion and payment difference writeoff are not yet
45supported.
46 """,
47 'website': 'http://therp.nl',
48 'images': [],
49 'depends': ['account_voucher'],
50 'data': [
51 'view/account_voucher_instant.xml',
52 'view/account_bank_statement_line.xml',
53 ],
54 "license": 'AGPL-3',
55}
56# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
057
=== added directory 'bank_statement_instant_voucher/i18n'
=== added file 'bank_statement_instant_voucher/i18n/nl.po'
--- bank_statement_instant_voucher/i18n/nl.po 1970-01-01 00:00:00 +0000
+++ bank_statement_instant_voucher/i18n/nl.po 2012-12-05 20:19:21 +0000
@@ -0,0 +1,158 @@
1# Translation of OpenERP Server.
2# This file contains the translation of the following modules:
3# * bank_statement_instant_voucher
4#
5msgid ""
6msgstr ""
7"Project-Id-Version: OpenERP Server 6.1\n"
8"Report-Msgid-Bugs-To: \n"
9"POT-Creation-Date: 2012-11-12 10:42+0000\n"
10"PO-Revision-Date: 2012-11-12 10:42+0000\n"
11"Last-Translator: <>\n"
12"Language-Team: \n"
13"MIME-Version: 1.0\n"
14"Content-Type: text/plain; charset=UTF-8\n"
15"Content-Transfer-Encoding: \n"
16"Plural-Forms: \n"
17
18#. module: bank_statement_instant_voucher
19#: view:account.voucher.instant:0
20msgid "Confirm"
21msgstr "Bevestig"
22
23#. module: bank_statement_instant_voucher
24#: code:addons/bank_statement_instant_voucher/model/account_voucher_instant.py:71
25#, python-format
26msgid "Voucher for statement line %s.%s"
27msgstr "Journaalbon voor bankafschrift %s.%s"
28
29#. module: bank_statement_instant_voucher
30#: field:account.voucher.instant,state:0
31msgid "State"
32msgstr "Status"
33
34#. module: bank_statement_instant_voucher
35#: code:addons/bank_statement_instant_voucher/model/account_voucher_instant.py:201
36#, python-format
37msgid "The voucher could not be posted."
38msgstr "De journaalbon kon niet worden bevestigd."
39
40#. module: bank_statement_instant_voucher
41#: selection:account.voucher.instant,state:0
42msgid "ready"
43msgstr "ready"
44
45#. module: bank_statement_instant_voucher
46#: model:ir.model,name:bank_statement_instant_voucher.model_account_voucher_instant
47msgid "Instant Voucher"
48msgstr "Instant journaalbon"
49
50#. module: bank_statement_instant_voucher
51#: selection:account.voucher.instant,state:0
52msgid "confirm"
53msgstr "confirm"
54
55#. module: bank_statement_instant_voucher
56#: view:account.bank.statement:0
57#: model:ir.actions.act_window,name:bank_statement_instant_voucher.act_instant_voucher
58msgid "Create matching voucher"
59msgstr "Bijpassende journaalbon aanmaken"
60
61#. module: bank_statement_instant_voucher
62#: code:addons/bank_statement_instant_voucher/model/account_voucher_instant.py:137
63#, python-format
64msgid "Cannot determine statement line"
65msgstr "Kan de bankafschriftregel niet afleiden"
66
67#. module: bank_statement_instant_voucher
68#: selection:account.voucher.instant,state:0
69msgid "init"
70msgstr "init"
71
72#. module: bank_statement_instant_voucher
73#: code:addons/bank_statement_instant_voucher/model/account_voucher_instant.py:209
74#, python-format
75msgid "The voucher's move line could not be posted."
76msgstr "De journaalposten van de journaalbon konden niet geboekt worden"
77
78#. module: bank_statement_instant_voucher
79#: model:ir.model,name:bank_statement_instant_voucher.model_account_bank_statement_line
80msgid "Bank Statement Line"
81msgstr "Bankafschriftregel"
82
83#. module: bank_statement_instant_voucher
84#: view:account.voucher.instant:0
85msgid "Create voucher"
86msgstr "Journaalbon aanmaken"
87
88#. module: bank_statement_instant_voucher
89#: code:addons/bank_statement_instant_voucher/model/account_voucher_instant.py:214
90#, python-format
91msgid "The amount on the bank statement line needs to be the same as on the voucher. Write-off is not yet supported."
92msgstr "Het bedrag op het bankafschrift dient gelijk te zijn aan het bedrag op de journaalbon. Afschrijven is nog niet ondersteund."
93
94#. module: bank_statement_instant_voucher
95#: code:addons/bank_statement_instant_voucher/model/account_voucher_instant.py:59
96#: code:addons/bank_statement_instant_voucher/model/account_voucher_instant.py:136
97#: code:addons/bank_statement_instant_voucher/model/account_voucher_instant.py:190
98#: code:addons/bank_statement_instant_voucher/model/account_voucher_instant.py:200
99#: code:addons/bank_statement_instant_voucher/model/account_voucher_instant.py:208
100#: code:addons/bank_statement_instant_voucher/model/account_voucher_instant.py:213
101#: code:addons/bank_statement_instant_voucher/model/account_voucher_instant.py:224
102#, python-format
103msgid "Error"
104msgstr "Fout"
105
106#. module: bank_statement_instant_voucher
107#: code:addons/bank_statement_instant_voucher/model/account_voucher_instant.py:60
108#, python-format
109msgid "No %s journal defined"
110msgstr "Geen %s-dagboek ingesteld"
111
112#. module: bank_statement_instant_voucher
113#: constraint:account.bank.statement.line:0
114msgid "The amount of the voucher must be the same amount as the one on the statement line"
115msgstr "Het bedrag op de bon moet hetzelfde bedrag zijn dat vermeld staat op de afschriftregel"
116
117#. module: bank_statement_instant_voucher
118#: field:account.voucher.instant,balance:0
119msgid "Balance"
120msgstr "Balans"
121
122#. module: bank_statement_instant_voucher
123#: field:account.voucher.instant,statement_line_id:0
124msgid "Bank statement line"
125msgstr "Bankafschriftregel"
126
127#. module: bank_statement_instant_voucher
128#: field:account.voucher.instant,ref:0
129msgid "Reference"
130msgstr "Referentie"
131
132#. module: bank_statement_instant_voucher
133#: code:addons/bank_statement_instant_voucher/model/account_voucher_instant.py:191
134#, python-format
135msgid "Currency on the bank statement line needs to be the same as on the voucher. Currency conversion is not yet supported."
136msgstr "De valuta van de bankafschriftregel dient gelijk te zijn aan die op de journaalbon. Omrekenen tussen valuta is nog niet ondersteund."
137
138#. module: bank_statement_instant_voucher
139#: code:addons/bank_statement_instant_voucher/model/account_voucher_instant.py:225
140#, python-format
141msgid "Cannot match a confirmed statement line"
142msgstr "Kan een bevestigde bankafschriftregel niet afletteren"
143
144#. module: bank_statement_instant_voucher
145#: field:account.voucher.instant,voucher_id:0
146msgid "Voucher"
147msgstr "Journaalbon"
148
149#. module: bank_statement_instant_voucher
150#: view:account.voucher.instant:0
151msgid "Cancel"
152msgstr "Annuleer"
153
154#. module: bank_statement_instant_voucher
155#: field:account.voucher.instant,partner_id:0
156msgid "Partner"
157msgstr "Relatie"
158
0159
=== added directory 'bank_statement_instant_voucher/model'
=== added file 'bank_statement_instant_voucher/model/__init__.py'
--- bank_statement_instant_voucher/model/__init__.py 1970-01-01 00:00:00 +0000
+++ bank_statement_instant_voucher/model/__init__.py 2012-12-05 20:19:21 +0000
@@ -0,0 +1,2 @@
1import account_voucher_instant
2import account_bank_statement_line
03
=== added file 'bank_statement_instant_voucher/model/account_bank_statement_line.py'
--- bank_statement_instant_voucher/model/account_bank_statement_line.py 1970-01-01 00:00:00 +0000
+++ bank_statement_instant_voucher/model/account_bank_statement_line.py 2012-12-05 20:19:21 +0000
@@ -0,0 +1,49 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# OpenERP, Open Source Management Solution
5# This module copyright (C) 2012 Therp BV (<http://therp.nl>).
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21
22from openerp.osv import osv, fields
23
24
25class account_bank_statement_line(osv.Model):
26 _inherit = 'account.bank.statement.line'
27 def create_instant_voucher(self, cr, uid, ids, context=None):
28 res = False
29 if ids:
30 if isinstance(ids, (int, float)):
31 ids = [ids]
32 if context is None:
33 context = {}
34 local_context = context.copy()
35 local_context['active_id'] = ids[0]
36 wizard_obj = self.pool.get('account.voucher.instant')
37 res = {
38 'name': wizard_obj._description,
39 'view_type': 'form',
40 'view_mode': 'form',
41 'res_model': wizard_obj._name,
42 'domain': [],
43 'context': local_context,
44 'type': 'ir.actions.act_window',
45 'target': 'new',
46 'res_id': False,
47 'nodestroy': False,
48 }
49 return res
050
=== added file 'bank_statement_instant_voucher/model/account_voucher_instant.py'
--- bank_statement_instant_voucher/model/account_voucher_instant.py 1970-01-01 00:00:00 +0000
+++ bank_statement_instant_voucher/model/account_voucher_instant.py 2012-12-05 20:19:21 +0000
@@ -0,0 +1,306 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# OpenERP, Open Source Management Solution
5# This module copyright (C) 2012 Therp BV (<http://therp.nl>).
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21
22from openerp.osv import osv, fields
23from openerp.tools.translate import _
24from openerp.addons.decimal_precision import decimal_precision as dp
25
26
27class instant_voucher(osv.TransientModel):
28 _name = 'account.voucher.instant'
29 _description = 'Instant Voucher'
30
31 def cancel(self, cr, uid, ids, context=None):
32 """
33 Delete the voucher and close window
34 """
35 assert len(ids) == 1, "Will only take one resource id"
36 instant = self.browse(cr, uid, ids[0], context=context)
37 if instant.voucher_id:
38 self.pool.get('account.voucher').cancel_voucher(
39 cr, uid, [instant.voucher_id.id], context=context)
40 self.pool.get('account.voucher').unlink(
41 cr, uid, [instant.voucher_id.id], context=context)
42 return {'type': 'ir.actions.act_window_close'}
43
44 def get_voucher_defaults(
45 self, cr, uid, vals, context=None):
46 """
47 Gather conditional defaults based on given key, value pairs
48
49 :param vals: dictionary of key, value pairs
50 :returns: dictionary of default values for fields not in vals
51 """
52 values_pool = self.pool.get('ir.values')
53 voucher_pool = self.pool.get('account.voucher')
54 res = {}
55 for (key, val) in vals.iteritems():
56 if val and voucher_pool._all_columns[key].column.change_default:
57 for default in values_pool.get_defaults(
58 cr, uid, 'account.voucher', '%s=%s' % (key, val)):
59 if default[1] not in vals:
60 res[default[1]] = default[2]
61 return res
62
63 def create_voucher(self, cr, uid, ids, context=None):
64 """
65 Create a fully fledged voucher counterpart for the
66 statement line. User only needs to process taxes and may
67 adapt cost/income account.
68 """
69 assert len(ids) == 1, "Will only take one resource id"
70 voucher_pool = self.pool.get('account.voucher')
71 period_pool = self.pool.get('account.period')
72 instant = self.browse(cr, uid, ids[0], context=context)
73 line = instant.statement_line_id
74 voucher_type = line.amount < 0 and 'purchase' or 'sale'
75 journal_ids = self.pool.get('account.journal').search(
76 cr, uid, [('company_id', '=', line.company_id.id),
77 ('type', '=', voucher_type)])
78 if not journal_ids:
79 osv.exept_osv(
80 _('Error'),
81 _('No %s journal defined') % voucher_type)
82
83 journal = self.pool.get('account.journal').browse(
84 cr, uid, journal_ids[0], context=context)
85 if journal.type in ('sale', 'sale_refund'):
86 line_account_id = (journal.default_credit_account_id and
87 journal.default_credit_account_id.id or False)
88 elif journal.type in ('purchase', 'expense', 'purchase_refund'):
89 line_account_id = (journal.default_debit_account_id and
90 journal.default_debit_account_id.id or False)
91 vals = {
92 'name': _('Voucher for statement line %s.%s') % (line.statement_id.name, line.name),
93 'reference': line.ref or False,
94 'company_id': line.company_id.id,
95 'partner_id': instant.partner_id.id,
96 'date': line.date or res.get('line.date', False),
97 'account_id': line.account_id.id,
98 'type': voucher_type,
99 'line_ids': [(0, 0, {'amount': abs(line.amount),
100 'account_id': line_account_id,
101 'type': line.amount < 0 and 'dr' or 'cr',
102 'name': line.ref or False,
103 })],
104 'amount': line.amount and abs(line.amount) or res.get('amount', False),
105 'journal_id': journal_ids[0],
106 }
107 if vals['date']:
108 period_ids = period_pool.find(cr, uid, vals['date'], context=context)
109 if period_ids:
110 vals['period_id'] = period_ids[0]
111 vals.update(self.get_voucher_defaults(cr, uid, vals, context=context))
112
113 voucher_id = voucher_pool.create(
114 cr, uid, vals, context=context)
115 self.write(
116 cr, uid, ids[0],
117 {'voucher_id': voucher_id,
118 'state': 'ready',
119 'type': voucher_type,
120 }, context=context)
121 return {
122 'name': self._description,
123 'view_type': 'form',
124 'view_mode': 'form',
125 'res_model': self._name,
126 'domain': [],
127 'context': context,
128 'type': 'ir.actions.act_window',
129 'target': 'new',
130 'res_id': ids[0],
131 'nodestroy': False,
132 }
133
134 def dummy(self, cr, uid, ids, context=None):
135 return {
136 'name': self._description,
137 'view_type': 'form',
138 'view_mode': 'form',
139 'res_model': self._name,
140 'domain': [],
141 'context': context,
142 'type': 'ir.actions.act_window',
143 'target': 'new',
144 'res_id': ids[0],
145 'nodestroy': False,
146 }
147
148 def default_get(self, cr, uid, fields_list, context=None):
149 """
150 Gather sane default values from the originating statement line
151 """
152 res = super(instant_voucher, self).default_get(
153 cr, uid, fields_list, context=context)
154 if 'statement_line_id' in fields_list:
155 res['statement_line_id'] = (
156 context.get('active_id') or
157 context.get('active_ids') and context.get('active_ids')[0])
158 if not res['statement_line_id']:
159 raise osv.except_osv(
160 _('Error'),
161 _('Cannot determine statement line'))
162 line = self.pool.get('account.bank.statement.line').browse(
163 cr, uid, res['statement_line_id'], context=context)
164 if 'balance' in fields_list:
165 res['balance'] = line.amount
166 if 'ref' in fields_list:
167 res['ref'] = line.ref
168 if 'partner_id' in fields_list:
169 if line.partner_id:
170 res['partner_id'] = line.partner_id.id
171 return res
172
173 def _get_balance(self, cr, uid, ids, field_name, args, context=None):
174 """
175 Compute the expected residual
176 TODO: currency conversion
177 """
178 res = {}
179 for instant in self.browse(cr, uid, ids, context=context):
180 if instant.voucher_id and instant.voucher_id.state == 'posted':
181 amount = instant.statement_line_id.amount
182 counteramount = 0.0
183 for line in instant.voucher_id.move_ids:
184 if line.account_id.id == instant.statement_line_id.account_id.id:
185 counteramount = line.debit - line.credit
186 for line in instant.voucher_id.move_ids:
187 if line.account_id.id == instant.statement_line_id.account_id.id:
188 counteramount = line.debit - line.credit
189 else:
190 amount = abs(instant.statement_line_id.amount)
191 counteramount = abs(instant.voucher_id and instant.voucher_id.amount or 0.0)
192 res[instant.id] = amount - counteramount
193 return res
194
195 def confirm(self, cr, uid, ids, context=None):
196 """
197 Post the voucher if necessary
198 Post the voucher's move lines if necessary
199 Sanity checks on currency and residual = 0.0
200
201 If the account_banking module is installed, perform matching
202 and reconciliation. If not, the user is left to manual
203 reconciliation of OpenERP.
204 """
205 assert len(ids) == 1, "Will only take one resource id"
206 statement_line_obj = self.pool.get('account.bank.statement.line')
207 voucher_obj = self.pool.get('account.voucher')
208 move_obj = self.pool.get('account.move')
209 instant = self.browse(cr, uid, ids[0], context=context)
210 voucher_currency = (instant.voucher_id.currency_id and
211 instant.voucher_id.currency_id or
212 instant.voucher_id.company_id.currency_id)
213 if (instant.statement_line_id.statement_id.currency.id !=
214 voucher_currency.id):
215 raise osv.except_osv(
216 _("Error"),
217 _("Currency on the bank statement line needs to be the "
218 "same as on the voucher. Currency conversion is not yet "
219 "supported."))
220 if instant.voucher_id.state != 'posted':
221 voucher_obj.proforma_voucher(
222 cr, uid, [instant.voucher_id.id], context=context)
223 instant.refresh()
224 if instant.voucher_id.state != 'posted':
225 raise osv.except_osv(
226 _("Error"),
227 _("The voucher could not be posted."))
228 if instant.voucher_id.move_id.state != 'posted':
229 move_obj.post(
230 cr, uid, [instant.voucher_id.move_id.id], context=context)
231 instant.refresh()
232 if instant.voucher_id.move_id.state != 'posted':
233 raise osv.except_osv(
234 _("Error"),
235 _("The voucher's move line could not be posted."))
236 if not self.pool.get('res.currency').is_zero(
237 cr, uid, voucher_currency, instant.balance):
238 raise osv.except_osv(
239 _("Error"),
240 _("The amount on the bank statement line needs to be the "
241 "same as on the voucher. Write-off is not yet "
242 "supported."))
243 # Banking Addons integration:
244 # Gather the info needed to match the bank statement line
245 # and trigger its posting and reconciliation.
246 if 'import_transaction_id' in statement_line_obj._columns:
247 if instant.statement_line_id.state == 'confirmed':
248 raise osv.except_osv(
249 _("Error"),
250 _("Cannot match a confirmed statement line"))
251 if not instant.statement_line_id.import_transaction_id:
252 statement_line_obj.create_instant_transaction(
253 cr, uid, instant.statement_line_id.id, context=context)
254 instant.statement_line_id.refresh()
255 for line in instant.voucher_id.move_ids:
256 if line.account_id.id == instant.statement_line_id.account_id.id:
257 self.pool.get('banking.import.transaction').write(
258 cr, uid, instant.statement_line_id.import_transaction_id.id,
259 {
260 'move_line_id': line.id,
261 'move_line_ids': [(6, 0, [line.id])],
262 'match_type': 'move',
263 'invoice_id': False,
264 'invoice_ids': [(6, 0, [])],
265 }, context=context)
266
267 statement_line_obj.confirm(
268 cr, uid, [instant.statement_line_id.id], context=context)
269 break
270 return {'type': 'ir.actions.act_window_close'}
271
272 _columns = {
273 'balance': fields.function(
274 _get_balance,
275 type='float',
276 digits_compute=dp.get_precision('Account'),
277 string="Balance",),
278 'partner_id': fields.many2one(
279 'res.partner',
280 'Partner',
281 required=True),
282 'statement_line_id': fields.many2one(
283 'account.bank.statement.line',
284 'Bank statement line',
285 readonly=True),
286 'ref': fields.related(
287 'statement_line_id', 'ref',
288 type="char", size="48",
289 readonly=True,
290 string="Reference"),
291 'voucher_id': fields.many2one(
292 'account.voucher',
293 'Voucher',
294 readonly=True),
295 'state': fields.selection(
296 [('init', 'init'),
297 ('ready', 'ready'),
298 ('confirm', 'confirm')],
299 'State'),
300 'type': fields.selection(
301 [('sale', 'Sale'),
302 ('purchase', 'Purchase')],
303 'Voucher type'),
304 }
305
306 _defaults = {'state': 'init'}
0307
=== added directory 'bank_statement_instant_voucher/view'
=== added file 'bank_statement_instant_voucher/view/account_bank_statement_line.xml'
--- bank_statement_instant_voucher/view/account_bank_statement_line.xml 1970-01-01 00:00:00 +0000
+++ bank_statement_instant_voucher/view/account_bank_statement_line.xml 2012-12-05 20:19:21 +0000
@@ -0,0 +1,21 @@
1<?xml version="1.0" encoding="utf-8"?>
2<openerp>
3 <data>
4 <record id="view_banking_bank_statement_form" model="ir.ui.view">
5 <field name="name">Add instant voucher button to bank statement line on statement form</field>
6 <field name="inherit_id" ref="account.view_bank_statement_form" />
7 <field name="model">account.bank.statement</field>
8 <field name="type">form</field>
9 <field name="priority" eval="30"/>
10 <field name="arch" type="xml">
11 <xpath expr="/form/notebook/page/field[@name='line_ids']/tree/field[@name='voucher_id']"
12 position="before">
13 <button name="create_instant_voucher" states="draft"
14 string="Create matching voucher"
15 icon="STOCK_COPY"
16 type="object"/>
17 </xpath>
18 </field>
19 </record>
20 </data>
21</openerp>
022
=== added file 'bank_statement_instant_voucher/view/account_voucher_instant.xml'
--- bank_statement_instant_voucher/view/account_voucher_instant.xml 1970-01-01 00:00:00 +0000
+++ bank_statement_instant_voucher/view/account_voucher_instant.xml 2012-12-05 20:19:21 +0000
@@ -0,0 +1,52 @@
1<?xml version="1.0" encoding="utf-8"?>
2<openerp>
3 <data>
4 <record id="instant_voucher_form" model="ir.ui.view">
5 <field name="name">Instant voucher form view</field>
6 <field name="model">account.voucher.instant</field>
7 <field name="type">form</field>
8 <field name="arch" type="xml">
9 <form>
10 <field name="state" invisible="1" readonly="1"/>
11 <field name="statement_line_id"/>
12 <field name="ref"/>
13 <newline/>
14 <field name="partner_id"/>
15 <field name="balance"/>
16 <newline/>
17 <field name="type" invisible="1"/>
18 <field name="voucher_id"
19 context="{'statement_line_id': statement_line_id,
20 'form_view_ref': (
21 type == 'sale' and 'account_voucher.view_sale_receipt_form'
22 or 'account_voucher.view_purchase_receipt_form')
23 }"
24 />
25 <newline/>
26 <newline/>
27 <button icon="gtk-cancel"
28 string="Cancel"
29 name="cancel"
30 type="object"/>
31 <button icon="gtk-ok" string="Confirm"
32 states="ready"
33 name="confirm"
34 type="object"
35 />
36 <button icon="gtk-ok" string="Create voucher"
37 states="init"
38 name="create_voucher"
39 type="object"
40 />
41 </form>
42 </field>
43 </record>
44 <act_window name="Create matching voucher"
45 res_model="account.voucher.instant"
46 src_model="account.bank.statement.line"
47 view_mode="form"
48 target="new"
49 key2="client_action_multi"
50 id="act_instant_voucher"/>
51 </data>
52</openerp>

Subscribers

People subscribed via source and target branches