Merge lp:~camptocamp/openerp-swiss-localization/7.0-wip-invoice-ref-transaction-id into lp:~camptocamp/openerp-swiss-localization/7.0
- 7.0-wip-invoice-ref-transaction-id
- Merge into 7.0
Status: | Merged |
---|---|
Approved by: | Alexandre Fayolle - camptocamp |
Approved revision: | 212 |
Merged at revision: | 198 |
Proposed branch: | lp:~camptocamp/openerp-swiss-localization/7.0-wip-invoice-ref-transaction-id |
Merge into: | lp:~camptocamp/openerp-swiss-localization/7.0 |
Diff against target: |
832 lines (+579/-89) 17 files modified
l10n_ch_base_bank/bank.py (+2/-0) l10n_ch_dta/wizard/create_dta.py (+8/-2) l10n_ch_dta_base_transaction_id/__init__.py (+22/-0) l10n_ch_dta_base_transaction_id/__openerp__.py (+48/-0) l10n_ch_dta_base_transaction_id/wizard/__init__.py (+3/-0) l10n_ch_dta_base_transaction_id/wizard/create_dta.py (+34/-0) l10n_ch_payment_slip/invoice.py (+80/-45) l10n_ch_payment_slip/wizard/bvr_import.py (+46/-42) l10n_ch_payment_slip_account_statement_base_completion/__init__.py (+23/-0) l10n_ch_payment_slip_account_statement_base_completion/__openerp__.py (+52/-0) l10n_ch_payment_slip_account_statement_base_completion/data.xml (+12/-0) l10n_ch_payment_slip_account_statement_base_completion/statement.py (+103/-0) l10n_ch_payment_slip_account_statement_base_completion/wizard/__init__.py (+3/-0) l10n_ch_payment_slip_account_statement_base_completion/wizard/bvr_import.py (+34/-0) l10n_ch_payment_slip_base_transaction_id/__init__.py (+22/-0) l10n_ch_payment_slip_base_transaction_id/__openerp__.py (+48/-0) l10n_ch_payment_slip_base_transaction_id/invoice.py (+39/-0) |
To merge this branch: | bzr merge lp:~camptocamp/openerp-swiss-localization/7.0-wip-invoice-ref-transaction-id |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Nicolas Bessi - Camptocamp (community) | Approve | ||
Yannick Vaucher @ Camptocamp | code review | Approve | |
Frederic Clementi - Camptocamp | functional | Approve | |
Joël Grand-Guillaume @ camptocamp | code review, no tests | Pending | |
Review via email: mp+212102@code.launchpad.net |
This proposal supersedes a proposal from 2014-01-24.
Commit message
Description of the change
Compatibility with the base_transaction_id module. No BVR number for invoices with a transaction id.
Joël Grand-Guillaume @ camptocamp (jgrandguillaume-c2c) wrote : Posted in a previous version of this proposal | # |
Frederic Clementi - Camptocamp (frederic-clementi) wrote : Posted in a previous version of this proposal | # |
Customer invoices creation :
* BVR number is populated on all account move lines. it is no relevant. We should only have this information on the account move line containing the same account_id than the one indicated on the related invoice.
* The field call reference on the SO (and the webkit pdf also) becomes a description on the invoice and the move line. I suggest to call it description everywhere.
note that on the webkit invoice this information appears twice under the name Subject & You reference... which is not ideal as well
* Bank statement with all swiss modules :
-> button 'import invoice' : no BVR no populated into the transaction ref
-> button 'import payment lines' : no BVR no populated into the transaction ref (but ok in payment lines)
- butoon 'import BVR' - transaction ref is correctely populated but I should have the invoice number into the field 'reference' and a / into 'communication' (currentely it is the other way around so it is not consistent with all the new logic in place)
Thanks
Frederic
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote : Posted in a previous version of this proposal | # |
> Customer invoices creation :
>
> * BVR number is populated on all account move lines. it is no relevant. We
> should only have this information on the account move line containing the same
> account_id than the one indicated on the related invoice.
Done (as well as for the transaction ids branch [0])
>
> * The field call reference on the SO (and the webkit pdf also) becomes a
> description on the invoice and the move line. I suggest to call it description
> everywhere.
> note that on the webkit invoice this information appears twice under the name
> Subject & You reference... which is not ideal as well
I won't rename the fields. This is the field name used by OpenERP and we should keep it even if it is bad, changing it will break the translations. We have 2 possible courses of action here: 1) propose a new name for the next OpenERP release and 2) change the name in a custom translation.
The "Your Reference" field is now hidden when both fields have the same content.
This is done in the account-
>
> * Bank statement with all swiss modules :
> -> button 'import invoice' : no BVR no populated into the transaction ref
Done in a new compatibility module (autoinstallable) account_
This is done in the generic MP [0], not in the swiss localization.
> -> button 'import payment lines' : no BVR no populated into the transaction
> ref (but ok in payment lines)
Added in account_
> - butoon 'import BVR' - transaction ref is correctely populated but I should
> have the invoice number into the field 'reference' and a / into
> 'communication' (currentely it is the other way around so it is not consistent
> with all the new logic in place)
Done.
>
> Thanks
>
> Frederic
[0] https:/
[1] https:/
Frederic Clementi - Camptocamp (frederic-clementi) wrote : | # |
LGTM
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote : | # |
LGTM
Nicolas Bessi - Camptocamp (nbessi-c2c-deactivatedaccount) wrote : | # |
LGTM
Preview Diff
1 | === modified file 'l10n_ch_base_bank/bank.py' |
2 | --- l10n_ch_base_bank/bank.py 2013-05-24 07:33:46 +0000 |
3 | +++ l10n_ch_base_bank/bank.py 2014-03-21 07:56:44 +0000 |
4 | @@ -162,6 +162,8 @@ |
5 | for p_bank in p_banks: |
6 | if not p_bank.state in ('bv', 'bvr'): |
7 | continue |
8 | + if not p_bank.get_account_number(): |
9 | + continue |
10 | if not (self._check_9_pos_postal_num(p_bank.get_account_number()) or |
11 | self._check_5_pos_postal_num(p_bank.get_account_number())): |
12 | return False |
13 | |
14 | === modified file 'l10n_ch_dta/wizard/create_dta.py' |
15 | --- l10n_ch_dta/wizard/create_dta.py 2014-01-15 08:13:14 +0000 |
16 | +++ l10n_ch_dta/wizard/create_dta.py 2014-03-21 07:56:44 +0000 |
17 | @@ -490,11 +490,17 @@ |
18 | bank = payment.mode.bank_id |
19 | if not bank: |
20 | raise except_osv(_('Error'), _('No bank account for the company.')) |
21 | - elec_context['comp_bank_name'] = bank.bank and bank.bank.name or False |
22 | + if not bank.bank: |
23 | + raise except_osv(_('Error'), |
24 | + _('You must set a bank ' |
25 | + 'for the bank account with number %s' % |
26 | + bank.acc_number or '')) |
27 | + elec_context['comp_bank_name'] = bank.bank.name |
28 | elec_context['comp_bank_clearing'] = bank.bank.clearing |
29 | if not elec_context['comp_bank_clearing']: |
30 | raise except_osv(_('Error'), |
31 | - _('You must provide a Clearing Number for your bank account.')) |
32 | + _('You must provide a Clearing Number ' |
33 | + 'for the bank %s.' % bank.bank.name)) |
34 | company = payment.company_id |
35 | co_addr = company.partner_id |
36 | elec_context['comp_country'] = co_addr.country_id and co_addr.country_id.name or '' |
37 | |
38 | === added directory 'l10n_ch_dta_base_transaction_id' |
39 | === added file 'l10n_ch_dta_base_transaction_id/__init__.py' |
40 | --- l10n_ch_dta_base_transaction_id/__init__.py 1970-01-01 00:00:00 +0000 |
41 | +++ l10n_ch_dta_base_transaction_id/__init__.py 2014-03-21 07:56:44 +0000 |
42 | @@ -0,0 +1,22 @@ |
43 | +# -*- coding: utf-8 -*- |
44 | +############################################################################## |
45 | +# |
46 | +# Author: Guewen Baconnier |
47 | +# Copyright 2014 Camptocamp SA |
48 | +# |
49 | +# This program is free software: you can redistribute it and/or modify |
50 | +# it under the terms of the GNU Affero General Public License as |
51 | +# published by the Free Software Foundation, either version 3 of the |
52 | +# License, or (at your option) any later version. |
53 | +# |
54 | +# This program is distributed in the hope that it will be useful, |
55 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
56 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
57 | +# GNU Affero General Public License for more details. |
58 | +# |
59 | +# You should have received a copy of the GNU Affero General Public License |
60 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
61 | +# |
62 | +############################################################################## |
63 | + |
64 | +from . import wizard |
65 | |
66 | === added file 'l10n_ch_dta_base_transaction_id/__openerp__.py' |
67 | --- l10n_ch_dta_base_transaction_id/__openerp__.py 1970-01-01 00:00:00 +0000 |
68 | +++ l10n_ch_dta_base_transaction_id/__openerp__.py 2014-03-21 07:56:44 +0000 |
69 | @@ -0,0 +1,48 @@ |
70 | +# -*- coding: utf-8 -*- |
71 | +############################################################################## |
72 | +# |
73 | +# Author: Guewen Baconnier |
74 | +# Copyright 2014 Camptocamp SA |
75 | +# |
76 | +# This program is free software: you can redistribute it and/or modify |
77 | +# it under the terms of the GNU Affero General Public License as |
78 | +# published by the Free Software Foundation, either version 3 of the |
79 | +# License, or (at your option) any later version. |
80 | +# |
81 | +# This program is distributed in the hope that it will be useful, |
82 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
83 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
84 | +# GNU Affero General Public License for more details. |
85 | +# |
86 | +# You should have received a copy of the GNU Affero General Public License |
87 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
88 | +# |
89 | +############################################################################## |
90 | + |
91 | +{'name' : 'Swiss Localization Bank Payment File (DTA) - Transaction ID Compatibility', |
92 | + 'version' : '1.0', |
93 | + 'author' : 'Camptocamp', |
94 | + 'maintainer': 'Camptocamp', |
95 | + 'license': 'AGPL-3', |
96 | + 'category': 'Hidden', |
97 | + 'depends' : ['l10n_ch_dta', |
98 | + 'base_transaction_id', # lp:banking-addons/bank-statement-reconcile-7.0 |
99 | + ], |
100 | + 'description': """ |
101 | +Swiss Localization Bank Payment File (DTA) - Transaction ID Compatibility |
102 | +========================================================================= |
103 | + |
104 | +Link module between the Swiss localization Payment File (DTA) module |
105 | +(l10n_ch_dta) and the module adding a transaction ID |
106 | +field (base_transaction_id). |
107 | + |
108 | +When an invoice has a transaction ID, the DTA is exported with this ID |
109 | +as reference. |
110 | + |
111 | +""", |
112 | + 'website': 'http://www.camptocamp.com', |
113 | + 'data': [], |
114 | + 'tests': [], |
115 | + 'installable': True, |
116 | + 'auto_install': True, |
117 | +} |
118 | |
119 | === added directory 'l10n_ch_dta_base_transaction_id/wizard' |
120 | === added file 'l10n_ch_dta_base_transaction_id/wizard/__init__.py' |
121 | --- l10n_ch_dta_base_transaction_id/wizard/__init__.py 1970-01-01 00:00:00 +0000 |
122 | +++ l10n_ch_dta_base_transaction_id/wizard/__init__.py 2014-03-21 07:56:44 +0000 |
123 | @@ -0,0 +1,3 @@ |
124 | +# -*- coding: utf-8 -*- |
125 | + |
126 | +from . import create_dta |
127 | |
128 | === added file 'l10n_ch_dta_base_transaction_id/wizard/create_dta.py' |
129 | --- l10n_ch_dta_base_transaction_id/wizard/create_dta.py 1970-01-01 00:00:00 +0000 |
130 | +++ l10n_ch_dta_base_transaction_id/wizard/create_dta.py 2014-03-21 07:56:44 +0000 |
131 | @@ -0,0 +1,34 @@ |
132 | +# -*- coding: utf-8 -*- |
133 | +############################################################################## |
134 | +# |
135 | +# Author: Guewen Baconnier |
136 | +# Copyright 2014 Camptocamp SA |
137 | +# |
138 | +# This program is free software: you can redistribute it and/or modify |
139 | +# it under the terms of the GNU Affero General Public License as |
140 | +# published by the Free Software Foundation, either version 3 of the |
141 | +# License, or (at your option) any later version. |
142 | +# |
143 | +# This program is distributed in the hope that it will be useful, |
144 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
145 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
146 | +# GNU Affero General Public License for more details. |
147 | +# |
148 | +# You should have received a copy of the GNU Affero General Public License |
149 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
150 | +# |
151 | +############################################################################## |
152 | + |
153 | +from openerp.osv import orm |
154 | + |
155 | + |
156 | +class DTAFileGenerator(orm.TransientModel): |
157 | + _inherit = "create.dta.wizard" |
158 | + |
159 | + def _set_bank_data(self, cr, uid, data, pline, elec_context, |
160 | + seq, context=None): |
161 | + super(DTAFileGenerator, self).\ |
162 | + _set_bank_data(cr, uid, data, pline, |
163 | + elec_context, seq, context=context) |
164 | + if pline.move_line_id.transaction_ref: |
165 | + elec_context['reference'] = pline.move_line_id.transaction_ref |
166 | |
167 | === modified file 'l10n_ch_payment_slip/invoice.py' |
168 | --- l10n_ch_payment_slip/invoice.py 2013-09-20 08:59:37 +0000 |
169 | +++ l10n_ch_payment_slip/invoice.py 2014-03-21 07:56:44 +0000 |
170 | @@ -33,14 +33,13 @@ |
171 | 'transaction_ref': fields.char('Transaction Ref.', size=128), |
172 | } |
173 | |
174 | - def init(self, cr): |
175 | - cr.execute('UPDATE account_move_line SET transaction_ref = ref' |
176 | - ' WHERE transaction_ref IS NULL' |
177 | - ' AND ref IS NOT NULL') |
178 | - return True |
179 | - |
180 | def get_bvr_ref(self, cursor, uid, move_line_id, context=None): |
181 | - """Retrieve ESR/BVR reference from move line in order to print it""" |
182 | + """Retrieve ESR/BVR reference from move line in order to print it |
183 | + |
184 | + Returns False when no BVR reference should be generated. No |
185 | + reference is generated when a transaction reference already |
186 | + exists for the line (likely been generated by a payment service). |
187 | + """ |
188 | res = '' |
189 | if isinstance(move_line_id, (tuple, list)): |
190 | assert len(move_line_id) == 1, "Only 1 ID expected" |
191 | @@ -55,7 +54,13 @@ |
192 | move_number = '' |
193 | if move_line.invoice.number: |
194 | move_number = self._compile_get_ref.sub('', str(move_line.invoice.number) + str(move_line_id)) |
195 | - return mod10r(res + move_number.rjust(26 - len(res), '0')) |
196 | + reference = mod10r(res + move_number.rjust(26 - len(res), '0')) |
197 | + if (move_line.transaction_ref and |
198 | + move_line.transaction_ref != reference): |
199 | + # the line has already a transaction id and it is not |
200 | + # a BVR reference |
201 | + return '' |
202 | + return reference |
203 | |
204 | |
205 | class AccountInvoice(Model): |
206 | @@ -102,22 +107,35 @@ |
207 | store=True, readonly=True) |
208 | } |
209 | |
210 | + def _get_bvr_ref(self, cr, uid, invoice, context=None): |
211 | + """Retrieve ESR/BVR reference form invoice in order to print it |
212 | + |
213 | + Receive a browse record so it can be overloaded without rebrowsing |
214 | + the invoice. |
215 | + """ |
216 | + res = '' |
217 | + ## We check if the type is bvr, if not we return false |
218 | + if invoice.partner_bank_id.state != 'bvr': |
219 | + return '' |
220 | + ## |
221 | + if invoice.partner_bank_id.bvr_adherent_num: |
222 | + res = invoice.partner_bank_id.bvr_adherent_num |
223 | + invoice_number = '' |
224 | + if invoice.number: |
225 | + invoice_number = self._compile_get_ref.sub('', invoice.number) |
226 | + return mod10r(res + invoice_number.rjust(26 - len(res), '0')) |
227 | + |
228 | def get_bvr_ref(self, cursor, uid, inv_id, context=None): |
229 | - """Retrieve ESR/BVR reference form invoice in order to print it""" |
230 | - res = '' |
231 | - if isinstance(inv_id, list): |
232 | + """Retrieve ESR/BVR reference form invoice in order to print it |
233 | + |
234 | + Returns False when no BVR reference should be generated. No |
235 | + reference is generated when the invoice is not a BVR invoice. |
236 | + """ |
237 | + if isinstance(inv_id, (list, tuple)): |
238 | + assert len(inv_id) == 1, "1 ID expected, got %s" % inv_id |
239 | inv_id = inv_id[0] |
240 | inv = self.browse(cursor, uid, inv_id, context=context) |
241 | - ## We check if the type is bvr, if not we return false |
242 | - if inv.partner_bank_id.state != 'bvr': |
243 | - return '' |
244 | - ## |
245 | - if inv.partner_bank_id.bvr_adherent_num: |
246 | - res = inv.partner_bank_id.bvr_adherent_num |
247 | - invoice_number = '' |
248 | - if inv.number: |
249 | - invoice_number = self._compile_get_ref.sub('', inv.number) |
250 | - return mod10r(res + invoice_number.rjust(26 - len(res), '0')) |
251 | + return self._get_bvr_ref(cursor, uid, inv, context=context) |
252 | |
253 | def _space(self, nbr, nbrspc=5): |
254 | """Spaces * 5. |
255 | @@ -136,37 +154,54 @@ |
256 | (ref, move_id)) |
257 | return True |
258 | |
259 | + def _action_bvr_number_move_line(self, cr, uid, invoice, move_line, |
260 | + ref, context=None): |
261 | + if not ref: |
262 | + return |
263 | + cr.execute('UPDATE account_move_line SET transaction_ref=%s' |
264 | + ' WHERE id=%s', (ref, move_line.id)) |
265 | + self._update_ref_on_account_analytic_line(cr, uid, ref, |
266 | + move_line.move_id.id) |
267 | + |
268 | def action_number(self, cr, uid, ids, context=None): |
269 | + """ Copy the BVR/ESR reference in the transaction_ref of move lines. |
270 | + |
271 | + For customers invoices: the BVR reference is computed using |
272 | + ``get_bvr_ref()`` on the invoice or move lines. |
273 | + |
274 | + For suppliers invoices: the BVR reference is stored in the reference |
275 | + field of the invoice. |
276 | + |
277 | + """ |
278 | res = super(AccountInvoice, self).action_number(cr, uid, ids, context=context) |
279 | move_line_obj = self.pool.get('account.move.line') |
280 | - account_obj = self.pool.get('account.account') |
281 | - tier_account_id = account_obj.search(cr, uid, [('type', 'in', ['receivable', 'payable'])]) |
282 | |
283 | for inv in self.browse(cr, uid, ids, context=context): |
284 | - if inv.type != 'out_invoice' and inv.partner_bank_id.state != 'bvr': |
285 | + move_line_ids = move_line_obj.search( |
286 | + cr, uid, |
287 | + [('move_id', '=', inv.move_id.id), |
288 | + ('account_id', '=', inv.account_id.id)], |
289 | + context=context) |
290 | + if not move_line_ids: |
291 | continue |
292 | - move_lines = move_line_obj.search(cr, uid, [('move_id', '=', inv.move_id.id), |
293 | - ('account_id', 'in', tier_account_id)]) |
294 | - # We keep this branch for compatibility with single BVR report. |
295 | - # This should be cleaned when porting to V8 |
296 | - if move_lines: |
297 | - if len(move_lines) == 1: |
298 | - ref = inv.get_bvr_ref() |
299 | - move_id = inv.move_id |
300 | - if move_id: |
301 | - cr.execute('UPDATE account_move_line SET transaction_ref=%s' |
302 | - ' WHERE move_id=%s', |
303 | - (ref, move_id.id)) |
304 | - self._update_ref_on_account_analytic_line(cr, uid, ref, move_id.id) |
305 | - else: |
306 | - for move_line in move_line_obj.browse(cr, uid, move_lines, context=context): |
307 | + move_lines = move_line_obj.browse(cr, uid, move_line_ids, |
308 | + context=context) |
309 | + for move_line in move_lines: |
310 | + if inv.type in ('out_invoice', 'out_refund'): |
311 | + if len(move_lines) == 1: |
312 | + # We keep this branch for compatibility with single |
313 | + # BVR report. |
314 | + # This should be cleaned when porting to V8 |
315 | + ref = inv.get_bvr_ref() |
316 | + else: |
317 | ref = move_line.get_bvr_ref() |
318 | - if ref: |
319 | - cr.execute('UPDATE account_move_line SET transaction_ref=%s' |
320 | - ' WHERE id=%s', |
321 | - (ref, move_line.id)) |
322 | - self._update_ref_on_account_analytic_line(cr, uid, ref, |
323 | - move_line.move_id.id) |
324 | + elif inv.reference_type == 'bvr' and inv.reference: |
325 | + ref = inv.reference |
326 | + else: |
327 | + ref = False |
328 | + self._action_bvr_number_move_line(cr, uid, inv, |
329 | + move_line, ref, |
330 | + context=context) |
331 | return res |
332 | |
333 | def copy(self, cursor, uid, inv_id, default=None, context=None): |
334 | |
335 | === modified file 'l10n_ch_payment_slip/wizard/bvr_import.py' |
336 | --- l10n_ch_payment_slip/wizard/bvr_import.py 2013-08-14 14:32:54 +0000 |
337 | +++ l10n_ch_payment_slip/wizard/bvr_import.py 2014-03-21 07:56:44 +0000 |
338 | @@ -181,6 +181,49 @@ |
339 | _('The properties account payable account receivable are not set')) |
340 | return account_id |
341 | |
342 | + def _prepare_line_vals(self, cursor, uid, statement, record, |
343 | + voucher_enabled, context=None): |
344 | + # Remove the 11 first char because it can be adherent number |
345 | + # TODO check if 11 is the right number |
346 | + move_line_obj = self.pool.get('account.move.line') |
347 | + reference = record['reference'] |
348 | + values = {'name': '/', |
349 | + 'date': record['date'], |
350 | + 'amount': record['amount'], |
351 | + 'ref': reference, |
352 | + 'type': (record['amount'] >= 0 and 'customer') or 'supplier', |
353 | + 'statement_id': statement.id, |
354 | + } |
355 | + line_ids = move_line_obj.search(cursor, uid, |
356 | + [('ref', '=', reference), |
357 | + ('reconcile_id', '=', False), |
358 | + ('account_id.type', 'in', ['receivable', 'payable']), |
359 | + ('journal_id.type', '=', 'sale')], |
360 | + order='date desc', context=context) |
361 | + #for multiple payments |
362 | + if not line_ids: |
363 | + line_ids = move_line_obj.search(cursor, uid, |
364 | + [('transaction_ref', '=', reference), |
365 | + ('reconcile_id', '=', False), |
366 | + ('account_id.type', 'in', ['receivable', 'payable']), |
367 | + ('journal_id.type', '=', 'sale')], |
368 | + order='date desc', context=context) |
369 | + if not line_ids: |
370 | + line_ids = self._reconstruct_invoice_ref(cursor, uid, reference, None) |
371 | + if line_ids and voucher_enabled: |
372 | + values['voucher_id'] = self._create_voucher_from_record(cursor, uid, record, |
373 | + statement, line_ids, |
374 | + context=context) |
375 | + account_id = self._get_account(cursor, uid, line_ids, |
376 | + record, context=context) |
377 | + values['account_id'] = account_id |
378 | + if line_ids: |
379 | + line = move_line_obj.browse(cursor, uid, line_ids[0]) |
380 | + partner_id = line.partner_id.id |
381 | + values['name'] = line.invoice and (_('Inv. no ') + line.invoice.number) or values['name'] |
382 | + values['partner_id'] = partner_id |
383 | + return values |
384 | + |
385 | def import_v11(self, cursor, uid, ids, data, context=None): |
386 | """Import v11 file and transfor it into statement lines""" |
387 | if context is None: context = {} |
388 | @@ -196,7 +239,6 @@ |
389 | if para.lower() not in ['0', 'false']: # if voucher is disabled |
390 | voucher_enabled = False |
391 | statement_line_obj = self.pool.get('account.bank.statement.line') |
392 | - move_line_obj = self.pool.get('account.move.line') |
393 | attachment_obj = self.pool.get('ir.attachment') |
394 | statement_obj = self.pool.get('account.bank.statement') |
395 | file = data['form']['file'] |
396 | @@ -207,49 +249,11 @@ |
397 | lines = base64.decodestring(file).split("\n") |
398 | records = self._parse_lines(cursor, uid, lines, context=context) |
399 | |
400 | - if context is None: |
401 | - context = {} |
402 | - |
403 | statement = statement_obj.browse(cursor, uid, statement_id, context=context) |
404 | for record in records: |
405 | - # Remove the 11 first char because it can be adherent number |
406 | - # TODO check if 11 is the right number |
407 | - reference = record['reference'] |
408 | - values = {'name': reference, |
409 | - 'date': record['date'], |
410 | - 'amount': record['amount'], |
411 | - 'ref': reference, |
412 | - 'type': (record['amount'] >= 0 and 'customer') or 'supplier', |
413 | - 'statement_id': statement_id, |
414 | - } |
415 | - line_ids = move_line_obj.search(cursor, uid, |
416 | - [('ref', '=', reference), |
417 | - ('reconcile_id', '=', False), |
418 | - ('account_id.type', 'in', ['receivable', 'payable']), |
419 | - ('journal_id.type', '=', 'sale')], |
420 | - order='date desc', context=context) |
421 | - #for multiple payments |
422 | - if not line_ids: |
423 | - line_ids = move_line_obj.search(cursor, uid, |
424 | - [('transaction_ref', '=', reference), |
425 | - ('reconcile_id', '=', False), |
426 | - ('account_id.type', 'in', ['receivable', 'payable']), |
427 | - ('journal_id.type', '=', 'sale')], |
428 | - order='date desc', context=context) |
429 | - if not line_ids: |
430 | - line_ids = self._reconstruct_invoice_ref(cursor, uid, reference, None) |
431 | - if line_ids and voucher_enabled: |
432 | - values['voucher_id'] = self._create_voucher_from_record(cursor, uid, record, |
433 | - statement, line_ids, |
434 | - context=context) |
435 | - account_id = self._get_account(cursor, uid, line_ids, |
436 | - record, context=context) |
437 | - values['account_id'] = account_id |
438 | - if line_ids: |
439 | - line = move_line_obj.browse(cursor, uid, line_ids[0]) |
440 | - partner_id = line.partner_id.id |
441 | - values['name'] = line.invoice and (_('Inv. no ') + line.invoice.number) or values['name'] |
442 | - values['partner_id'] = partner_id |
443 | + values = self._prepare_line_vals(cursor, uid, statement, |
444 | + record, voucher_enabled, |
445 | + context=context) |
446 | statement_line_obj.create(cursor, uid, values, context=context) |
447 | attachment_obj.create(cursor, uid, |
448 | {'name': 'BVR %s' % time.strftime("%Y-%m-%d_%H:%M:%S", time.gmtime()), |
449 | |
450 | === added directory 'l10n_ch_payment_slip_account_statement_base_completion' |
451 | === added file 'l10n_ch_payment_slip_account_statement_base_completion/__init__.py' |
452 | --- l10n_ch_payment_slip_account_statement_base_completion/__init__.py 1970-01-01 00:00:00 +0000 |
453 | +++ l10n_ch_payment_slip_account_statement_base_completion/__init__.py 2014-03-21 07:56:44 +0000 |
454 | @@ -0,0 +1,23 @@ |
455 | +# -*- coding: utf-8 -*- |
456 | +############################################################################## |
457 | +# |
458 | +# Author: Guewen Baconnier |
459 | +# Copyright 2014 Camptocamp SA |
460 | +# |
461 | +# This program is free software: you can redistribute it and/or modify |
462 | +# it under the terms of the GNU Affero General Public License as |
463 | +# published by the Free Software Foundation, either version 3 of the |
464 | +# License, or (at your option) any later version. |
465 | +# |
466 | +# This program is distributed in the hope that it will be useful, |
467 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
468 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
469 | +# GNU Affero General Public License for more details. |
470 | +# |
471 | +# You should have received a copy of the GNU Affero General Public License |
472 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
473 | +# |
474 | +############################################################################## |
475 | + |
476 | +from . import wizard |
477 | +from . import statement |
478 | |
479 | === added file 'l10n_ch_payment_slip_account_statement_base_completion/__openerp__.py' |
480 | --- l10n_ch_payment_slip_account_statement_base_completion/__openerp__.py 1970-01-01 00:00:00 +0000 |
481 | +++ l10n_ch_payment_slip_account_statement_base_completion/__openerp__.py 2014-03-21 07:56:44 +0000 |
482 | @@ -0,0 +1,52 @@ |
483 | +# -*- coding: utf-8 -*- |
484 | +############################################################################## |
485 | +# |
486 | +# Author: Guewen Baconnier |
487 | +# Copyright 2014 Camptocamp SA |
488 | +# |
489 | +# This program is free software: you can redistribute it and/or modify |
490 | +# it under the terms of the GNU Affero General Public License as |
491 | +# published by the Free Software Foundation, either version 3 of the |
492 | +# License, or (at your option) any later version. |
493 | +# |
494 | +# This program is distributed in the hope that it will be useful, |
495 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
496 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
497 | +# GNU Affero General Public License for more details. |
498 | +# |
499 | +# You should have received a copy of the GNU Affero General Public License |
500 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
501 | +# |
502 | +############################################################################## |
503 | + |
504 | +{'name' : 'Swiss Localization BVR/ESR - Bank statement Completion', |
505 | + 'version' : '1.0', |
506 | + 'author' : 'Camptocamp', |
507 | + 'maintainer': 'Camptocamp', |
508 | + 'license': 'AGPL-3', |
509 | + 'category': 'Hidden', |
510 | + 'depends' : ['l10n_ch_payment_slip', |
511 | + 'account_statement_base_completion', # lp:banking-addons/bank-statement-reconcile-7.0 |
512 | + ], |
513 | + 'description': """ |
514 | +Swiss Localization BVR/ESR - Bank statement Completion |
515 | +====================================================== |
516 | + |
517 | +Link module between the Swiss localization BVR/ESR module |
518 | +(l10n_ch_payment_slip) and the module adding a transaction ID |
519 | +field in the bank statement (account_statement_base_completion). |
520 | + |
521 | +It adds a completion rule to search the partner from the invoice |
522 | +using the BVR/ESR reference. |
523 | + |
524 | +When importing a BVR/ESR, the transaction ID is also copied to the |
525 | +transaction id field of the bank statement. |
526 | + |
527 | + """, |
528 | + 'website': 'http://www.camptocamp.com', |
529 | + 'data': ['data.xml', |
530 | + ], |
531 | + 'tests': [], |
532 | + 'installable': True, |
533 | + 'auto_install': True, |
534 | +} |
535 | |
536 | === added file 'l10n_ch_payment_slip_account_statement_base_completion/data.xml' |
537 | --- l10n_ch_payment_slip_account_statement_base_completion/data.xml 1970-01-01 00:00:00 +0000 |
538 | +++ l10n_ch_payment_slip_account_statement_base_completion/data.xml 2014-03-21 07:56:44 +0000 |
539 | @@ -0,0 +1,12 @@ |
540 | +<?xml version="1.0" encoding="utf-8"?> |
541 | +<openerp> |
542 | + <data noupdate="1"> |
543 | + |
544 | + <record id="bank_statement_completion_rule_bvr_invoice" model="account.statement.completion.rule"> |
545 | + <field name="name">Match from Invoice using BVR/ESR Reference</field> |
546 | + <field name="sequence">40</field> |
547 | + <field name="function_to_call">get_from_bvr_reference_and_invoice</field> |
548 | + </record> |
549 | + |
550 | + </data> |
551 | +</openerp> |
552 | |
553 | === added file 'l10n_ch_payment_slip_account_statement_base_completion/statement.py' |
554 | --- l10n_ch_payment_slip_account_statement_base_completion/statement.py 1970-01-01 00:00:00 +0000 |
555 | +++ l10n_ch_payment_slip_account_statement_base_completion/statement.py 2014-03-21 07:56:44 +0000 |
556 | @@ -0,0 +1,103 @@ |
557 | +# -*- coding: utf-8 -*- |
558 | +############################################################################## |
559 | +# |
560 | +# Author: Guewen Baconnier |
561 | +# Copyright 2014 Camptocamp SA |
562 | +# |
563 | +# This program is free software: you can redistribute it and/or modify |
564 | +# it under the terms of the GNU Affero General Public License as |
565 | +# published by the Free Software Foundation, either version 3 of the |
566 | +# License, or (at your option) any later version. |
567 | +# |
568 | +# This program is distributed in the hope that it will be useful, |
569 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
570 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
571 | +# GNU Affero General Public License for more details. |
572 | +# |
573 | +# You should have received a copy of the GNU Affero General Public License |
574 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
575 | +# |
576 | +############################################################################## |
577 | + |
578 | +from openerp.tools.translate import _ |
579 | +from openerp.osv import orm, fields |
580 | +from openerp.addons.account_statement_base_completion.statement import ( |
581 | + ErrorTooManyPartner |
582 | +) |
583 | + |
584 | + |
585 | +class account_statement_completion_rule(orm.Model): |
586 | + """ Add a rule based on BVR Reference """ |
587 | + _inherit = "account.statement.completion.rule" |
588 | + |
589 | + def _get_functions(self, cr, uid, context=None): |
590 | + res = super(account_statement_completion_rule, self).\ |
591 | + _get_functions(cr, uid, context=context) |
592 | + res.append(('get_from_bvr_reference_and_invoice', |
593 | + 'Match Invoice using BVR/ESR Reference')) |
594 | + return res |
595 | + |
596 | + _columns = { |
597 | + 'function_to_call': fields.selection(_get_functions, 'Method'), |
598 | + } |
599 | + |
600 | + def get_from_bvr_reference_and_invoice(self, cr, uid, st_line, context=None): |
601 | + """ |
602 | + Match the partner based on the BVR reference field of the invoice. |
603 | + Then, call the generic st_line method to complete other values. |
604 | + |
605 | + In that case, we always fulfill the reference of the line with |
606 | + the invoice name. |
607 | + |
608 | + :param dict st_line: read of the concerned account.bank.statement.line |
609 | + :return: |
610 | + A dict of value that can be passed directly to the write method of |
611 | + the statement line or {} |
612 | + {'partner_id': value, |
613 | + 'account_id' : value, |
614 | + ...} |
615 | + """ |
616 | + st_obj = self.pool.get('account.bank.statement.line') |
617 | + res = {} |
618 | + invoice_obj = self.pool.get('account.invoice') |
619 | + # For customer invoices, search in bvr_reference that is as list |
620 | + # of references separated by semicolons and formatted with |
621 | + # spaces inside them. |
622 | + # For supplier invoices, search in 'reference' |
623 | + query = ("SELECT id FROM account_invoice " |
624 | + "WHERE company_id = %s " |
625 | + "AND (%s = ANY (string_to_array( " |
626 | + " replace(bvr_reference, ' ', ''), " |
627 | + " ';')) " |
628 | + " AND type IN ('out_invoice', 'out_refund') " |
629 | + " OR type IN ('in_invoice', 'in_refund') " |
630 | + " AND reference_type = 'bvr' AND reference = %s " |
631 | + ")") |
632 | + cr.execute(query, (st_line['company_id'][0], |
633 | + st_line['transaction_id'], |
634 | + st_line['transaction_id'])) |
635 | + rows = cr.fetchall() |
636 | + invoice_ids = [row[0] for row in rows] |
637 | + if len(invoice_ids) > 1: |
638 | + raise ErrorTooManyPartner( |
639 | + _('Line named "%s" (Ref:%s) was matched by more than ' |
640 | + 'one partner.') % (st_line['name'], st_line['ref'])) |
641 | + elif len(invoice_ids) == 1: |
642 | + invoice = invoice_obj.browse(cr, uid, invoice_ids[0], |
643 | + context=context) |
644 | + res['partner_id'] = invoice.partner_id.id |
645 | + # we want the move to have the same ref than the found |
646 | + # invoice's move, thus it will be easier to link them for the |
647 | + # accountants |
648 | + if invoice.move_id: |
649 | + res['ref'] = invoice.move_id.ref |
650 | + st_vals = st_obj.get_values_for_line( |
651 | + cr, uid, |
652 | + profile_id=st_line['profile_id'], |
653 | + master_account_id=st_line['master_account_id'], |
654 | + partner_id=res.get('partner_id', False), |
655 | + line_type=st_line['type'], |
656 | + amount=st_line['amount'] if st_line['amount'] else 0.0, |
657 | + context=context) |
658 | + res.update(st_vals) |
659 | + return res |
660 | |
661 | === added directory 'l10n_ch_payment_slip_account_statement_base_completion/wizard' |
662 | === added file 'l10n_ch_payment_slip_account_statement_base_completion/wizard/__init__.py' |
663 | --- l10n_ch_payment_slip_account_statement_base_completion/wizard/__init__.py 1970-01-01 00:00:00 +0000 |
664 | +++ l10n_ch_payment_slip_account_statement_base_completion/wizard/__init__.py 2014-03-21 07:56:44 +0000 |
665 | @@ -0,0 +1,3 @@ |
666 | +# -*- coding: utf-8 -*- |
667 | + |
668 | +from . import bvr_import |
669 | |
670 | === added file 'l10n_ch_payment_slip_account_statement_base_completion/wizard/bvr_import.py' |
671 | --- l10n_ch_payment_slip_account_statement_base_completion/wizard/bvr_import.py 1970-01-01 00:00:00 +0000 |
672 | +++ l10n_ch_payment_slip_account_statement_base_completion/wizard/bvr_import.py 2014-03-21 07:56:44 +0000 |
673 | @@ -0,0 +1,34 @@ |
674 | +# -*- coding: utf-8 -*- |
675 | +############################################################################## |
676 | +# |
677 | +# Author: Guewen Baconnier |
678 | +# Copyright 2014 Camptocamp SA |
679 | +# |
680 | +# This program is free software: you can redistribute it and/or modify |
681 | +# it under the terms of the GNU Affero General Public License as |
682 | +# published by the Free Software Foundation, either version 3 of the |
683 | +# License, or (at your option) any later version. |
684 | +# |
685 | +# This program is distributed in the hope that it will be useful, |
686 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
687 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
688 | +# GNU Affero General Public License for more details. |
689 | +# |
690 | +# You should have received a copy of the GNU Affero General Public License |
691 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
692 | +# |
693 | +############################################################################## |
694 | + |
695 | +from openerp.osv import orm |
696 | + |
697 | + |
698 | +class BvrImporterWizard(orm.TransientModel): |
699 | + _inherit = 'bvr.import.wizard' |
700 | + |
701 | + def _prepare_line_vals(self, cursor, uid, statement, record, |
702 | + voucher_enabled, context=None): |
703 | + record = super(BvrImporterWizard, self).\ |
704 | + _prepare_line_vals(cursor, uid, statement, record, |
705 | + voucher_enabled, context=context) |
706 | + record['transaction_id'] = record['ref'] |
707 | + return record |
708 | |
709 | === added directory 'l10n_ch_payment_slip_base_transaction_id' |
710 | === added file 'l10n_ch_payment_slip_base_transaction_id/__init__.py' |
711 | --- l10n_ch_payment_slip_base_transaction_id/__init__.py 1970-01-01 00:00:00 +0000 |
712 | +++ l10n_ch_payment_slip_base_transaction_id/__init__.py 2014-03-21 07:56:44 +0000 |
713 | @@ -0,0 +1,22 @@ |
714 | +# -*- coding: utf-8 -*- |
715 | +############################################################################## |
716 | +# |
717 | +# Author: Guewen Baconnier |
718 | +# Copyright 2014 Camptocamp SA |
719 | +# |
720 | +# This program is free software: you can redistribute it and/or modify |
721 | +# it under the terms of the GNU Affero General Public License as |
722 | +# published by the Free Software Foundation, either version 3 of the |
723 | +# License, or (at your option) any later version. |
724 | +# |
725 | +# This program is distributed in the hope that it will be useful, |
726 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
727 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
728 | +# GNU Affero General Public License for more details. |
729 | +# |
730 | +# You should have received a copy of the GNU Affero General Public License |
731 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
732 | +# |
733 | +############################################################################## |
734 | + |
735 | +from . import invoice |
736 | |
737 | === added file 'l10n_ch_payment_slip_base_transaction_id/__openerp__.py' |
738 | --- l10n_ch_payment_slip_base_transaction_id/__openerp__.py 1970-01-01 00:00:00 +0000 |
739 | +++ l10n_ch_payment_slip_base_transaction_id/__openerp__.py 2014-03-21 07:56:44 +0000 |
740 | @@ -0,0 +1,48 @@ |
741 | +# -*- coding: utf-8 -*- |
742 | +############################################################################## |
743 | +# |
744 | +# Author: Guewen Baconnier |
745 | +# Copyright 2014 Camptocamp SA |
746 | +# |
747 | +# This program is free software: you can redistribute it and/or modify |
748 | +# it under the terms of the GNU Affero General Public License as |
749 | +# published by the Free Software Foundation, either version 3 of the |
750 | +# License, or (at your option) any later version. |
751 | +# |
752 | +# This program is distributed in the hope that it will be useful, |
753 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
754 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
755 | +# GNU Affero General Public License for more details. |
756 | +# |
757 | +# You should have received a copy of the GNU Affero General Public License |
758 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
759 | +# |
760 | +############################################################################## |
761 | + |
762 | +{'name' : 'Swiss Localization BVR/ESR - Transaction ID Compatibility', |
763 | + 'version' : '1.0', |
764 | + 'author' : 'Camptocamp', |
765 | + 'maintainer': 'Camptocamp', |
766 | + 'license': 'AGPL-3', |
767 | + 'category': 'Hidden', |
768 | + 'depends' : ['l10n_ch_payment_slip', |
769 | + 'base_transaction_id', # lp:banking-addons/bank-statement-reconcile-7.0 |
770 | + ], |
771 | + 'description': """ |
772 | +Swiss Localization BVR/ESR - Transaction ID Compatibility |
773 | +========================================================== |
774 | + |
775 | +Link module between the Swiss localization BVR/ESR module |
776 | +(l10n_ch_payment_slip) and the module adding a transaction ID |
777 | +field (base_transaction_id). |
778 | + |
779 | +When an invoice has a transaction ID, no BVR reference should be generated |
780 | +because the reconciliation should be done with the transaction ID, not |
781 | +a new reference. |
782 | + """, |
783 | + 'website': 'http://www.camptocamp.com', |
784 | + 'data': [], |
785 | + 'tests': [], |
786 | + 'installable': True, |
787 | + 'auto_install': True, |
788 | +} |
789 | |
790 | === added file 'l10n_ch_payment_slip_base_transaction_id/invoice.py' |
791 | --- l10n_ch_payment_slip_base_transaction_id/invoice.py 1970-01-01 00:00:00 +0000 |
792 | +++ l10n_ch_payment_slip_base_transaction_id/invoice.py 2014-03-21 07:56:44 +0000 |
793 | @@ -0,0 +1,39 @@ |
794 | +# -*- coding: utf-8 -*- |
795 | +############################################################################## |
796 | +# |
797 | +# Author: Guewen Baconnier |
798 | +# Copyright 2014 Camptocamp SA |
799 | +# |
800 | +# This program is free software: you can redistribute it and/or modify |
801 | +# it under the terms of the GNU Affero General Public License as |
802 | +# published by the Free Software Foundation, either version 3 of the |
803 | +# License, or (at your option) any later version. |
804 | +# |
805 | +# This program is distributed in the hope that it will be useful, |
806 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
807 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
808 | +# GNU Affero General Public License for more details. |
809 | +# |
810 | +# You should have received a copy of the GNU Affero General Public License |
811 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
812 | +# |
813 | +############################################################################## |
814 | + |
815 | +from openerp.osv import orm |
816 | + |
817 | + |
818 | +class account_invoice(orm.Model): |
819 | + _inherit = 'account.invoice' |
820 | + |
821 | + def _get_bvr_ref(self, cr, uid, invoice, context=None): |
822 | + """Retrieve ESR/BVR reference form invoice in order to print it |
823 | + |
824 | + Returns False when no BVR reference should be generated. No |
825 | + reference is generated when a transaction ID already exists on |
826 | + the invoice (likely generated by a payment service so BVR ref not |
827 | + used). |
828 | + """ |
829 | + if invoice.transaction_id: |
830 | + return '' |
831 | + return super(account_invoice, self)._get_bvr_ref(cr, uid, invoice, |
832 | + context=context) |
Hi,
Thanks for the good work. I will love to have Fred's comment in there. But for what I see, that' LGTM.
Regards,
Joël