Merge lp:~camptocamp/openerp-swiss-localization/7.0-wip-invoice-ref-transaction-id into lp:~camptocamp/openerp-swiss-localization/7.0

Proposed by Guewen Baconnier @ Camptocamp
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
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.

Description of the change

Compatibility with the base_transaction_id module. No BVR number for invoices with a transaction id.

To post a comment you must log in.
Revision history for this message
Joël Grand-Guillaume @ camptocamp (jgrandguillaume-c2c) wrote : Posted in a previous version of this proposal

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

review: Approve (code review, no tests)
Revision history for this message
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

review: Needs Fixing
Revision history for this message
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-invoice-report project [1].

>
> * 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_payment_transaction_id because the base_transaction_id module has no dependency on account_voucher / account_payment. It unfortunately requires the module "statement_voucher_killer" because this module redefine the wizards. I would have preferred this module to work with *and* without "statement_voucher_killer" though but the use case I'm covering here use it.

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_payment_transaction_id (same remark than above).

> - 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://code.launchpad.net/~camptocamp/banking-addons/7.0-bank-statement-reconcile-transaction_id-imp/+merge/202806
[1] https://code.launchpad.net/~camptocamp/account-invoice-report/7.0-invoice-webkit-hide-identical-ref/+merge/209436

Revision history for this message
Frederic Clementi - Camptocamp (frederic-clementi) wrote :

LGTM

review: Approve (functional)
Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

LGTM

review: Approve (code review)
Revision history for this message
Nicolas Bessi - Camptocamp (nbessi-c2c-deactivatedaccount) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'l10n_ch_base_bank/bank.py'
--- l10n_ch_base_bank/bank.py 2013-05-24 07:33:46 +0000
+++ l10n_ch_base_bank/bank.py 2014-03-21 07:56:44 +0000
@@ -162,6 +162,8 @@
162 for p_bank in p_banks:162 for p_bank in p_banks:
163 if not p_bank.state in ('bv', 'bvr'):163 if not p_bank.state in ('bv', 'bvr'):
164 continue164 continue
165 if not p_bank.get_account_number():
166 continue
165 if not (self._check_9_pos_postal_num(p_bank.get_account_number()) or167 if not (self._check_9_pos_postal_num(p_bank.get_account_number()) or
166 self._check_5_pos_postal_num(p_bank.get_account_number())):168 self._check_5_pos_postal_num(p_bank.get_account_number())):
167 return False169 return False
168170
=== modified file 'l10n_ch_dta/wizard/create_dta.py'
--- l10n_ch_dta/wizard/create_dta.py 2014-01-15 08:13:14 +0000
+++ l10n_ch_dta/wizard/create_dta.py 2014-03-21 07:56:44 +0000
@@ -490,11 +490,17 @@
490 bank = payment.mode.bank_id490 bank = payment.mode.bank_id
491 if not bank:491 if not bank:
492 raise except_osv(_('Error'), _('No bank account for the company.'))492 raise except_osv(_('Error'), _('No bank account for the company.'))
493 elec_context['comp_bank_name'] = bank.bank and bank.bank.name or False493 if not bank.bank:
494 raise except_osv(_('Error'),
495 _('You must set a bank '
496 'for the bank account with number %s' %
497 bank.acc_number or ''))
498 elec_context['comp_bank_name'] = bank.bank.name
494 elec_context['comp_bank_clearing'] = bank.bank.clearing499 elec_context['comp_bank_clearing'] = bank.bank.clearing
495 if not elec_context['comp_bank_clearing']:500 if not elec_context['comp_bank_clearing']:
496 raise except_osv(_('Error'),501 raise except_osv(_('Error'),
497 _('You must provide a Clearing Number for your bank account.'))502 _('You must provide a Clearing Number '
503 'for the bank %s.' % bank.bank.name))
498 company = payment.company_id504 company = payment.company_id
499 co_addr = company.partner_id505 co_addr = company.partner_id
500 elec_context['comp_country'] = co_addr.country_id and co_addr.country_id.name or ''506 elec_context['comp_country'] = co_addr.country_id and co_addr.country_id.name or ''
501507
=== added directory 'l10n_ch_dta_base_transaction_id'
=== added file 'l10n_ch_dta_base_transaction_id/__init__.py'
--- l10n_ch_dta_base_transaction_id/__init__.py 1970-01-01 00:00:00 +0000
+++ l10n_ch_dta_base_transaction_id/__init__.py 2014-03-21 07:56:44 +0000
@@ -0,0 +1,22 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Guewen Baconnier
5# Copyright 2014 Camptocamp SA
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 . import wizard
023
=== added file 'l10n_ch_dta_base_transaction_id/__openerp__.py'
--- l10n_ch_dta_base_transaction_id/__openerp__.py 1970-01-01 00:00:00 +0000
+++ l10n_ch_dta_base_transaction_id/__openerp__.py 2014-03-21 07:56:44 +0000
@@ -0,0 +1,48 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Guewen Baconnier
5# Copyright 2014 Camptocamp SA
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' : 'Swiss Localization Bank Payment File (DTA) - Transaction ID Compatibility',
23 'version' : '1.0',
24 'author' : 'Camptocamp',
25 'maintainer': 'Camptocamp',
26 'license': 'AGPL-3',
27 'category': 'Hidden',
28 'depends' : ['l10n_ch_dta',
29 'base_transaction_id', # lp:banking-addons/bank-statement-reconcile-7.0
30 ],
31 'description': """
32Swiss Localization Bank Payment File (DTA) - Transaction ID Compatibility
33=========================================================================
34
35Link module between the Swiss localization Payment File (DTA) module
36(l10n_ch_dta) and the module adding a transaction ID
37field (base_transaction_id).
38
39When an invoice has a transaction ID, the DTA is exported with this ID
40as reference.
41
42""",
43 'website': 'http://www.camptocamp.com',
44 'data': [],
45 'tests': [],
46 'installable': True,
47 'auto_install': True,
48}
049
=== added directory 'l10n_ch_dta_base_transaction_id/wizard'
=== added file 'l10n_ch_dta_base_transaction_id/wizard/__init__.py'
--- l10n_ch_dta_base_transaction_id/wizard/__init__.py 1970-01-01 00:00:00 +0000
+++ l10n_ch_dta_base_transaction_id/wizard/__init__.py 2014-03-21 07:56:44 +0000
@@ -0,0 +1,3 @@
1# -*- coding: utf-8 -*-
2
3from . import create_dta
04
=== added file 'l10n_ch_dta_base_transaction_id/wizard/create_dta.py'
--- l10n_ch_dta_base_transaction_id/wizard/create_dta.py 1970-01-01 00:00:00 +0000
+++ l10n_ch_dta_base_transaction_id/wizard/create_dta.py 2014-03-21 07:56:44 +0000
@@ -0,0 +1,34 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Guewen Baconnier
5# Copyright 2014 Camptocamp SA
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 orm
23
24
25class DTAFileGenerator(orm.TransientModel):
26 _inherit = "create.dta.wizard"
27
28 def _set_bank_data(self, cr, uid, data, pline, elec_context,
29 seq, context=None):
30 super(DTAFileGenerator, self).\
31 _set_bank_data(cr, uid, data, pline,
32 elec_context, seq, context=context)
33 if pline.move_line_id.transaction_ref:
34 elec_context['reference'] = pline.move_line_id.transaction_ref
035
=== modified file 'l10n_ch_payment_slip/invoice.py'
--- l10n_ch_payment_slip/invoice.py 2013-09-20 08:59:37 +0000
+++ l10n_ch_payment_slip/invoice.py 2014-03-21 07:56:44 +0000
@@ -33,14 +33,13 @@
33 'transaction_ref': fields.char('Transaction Ref.', size=128),33 'transaction_ref': fields.char('Transaction Ref.', size=128),
34 }34 }
3535
36 def init(self, cr):
37 cr.execute('UPDATE account_move_line SET transaction_ref = ref'
38 ' WHERE transaction_ref IS NULL'
39 ' AND ref IS NOT NULL')
40 return True
41
42 def get_bvr_ref(self, cursor, uid, move_line_id, context=None):36 def get_bvr_ref(self, cursor, uid, move_line_id, context=None):
43 """Retrieve ESR/BVR reference from move line in order to print it"""37 """Retrieve ESR/BVR reference from move line in order to print it
38
39 Returns False when no BVR reference should be generated. No
40 reference is generated when a transaction reference already
41 exists for the line (likely been generated by a payment service).
42 """
44 res = ''43 res = ''
45 if isinstance(move_line_id, (tuple, list)):44 if isinstance(move_line_id, (tuple, list)):
46 assert len(move_line_id) == 1, "Only 1 ID expected"45 assert len(move_line_id) == 1, "Only 1 ID expected"
@@ -55,7 +54,13 @@
55 move_number = ''54 move_number = ''
56 if move_line.invoice.number:55 if move_line.invoice.number:
57 move_number = self._compile_get_ref.sub('', str(move_line.invoice.number) + str(move_line_id))56 move_number = self._compile_get_ref.sub('', str(move_line.invoice.number) + str(move_line_id))
58 return mod10r(res + move_number.rjust(26 - len(res), '0'))57 reference = mod10r(res + move_number.rjust(26 - len(res), '0'))
58 if (move_line.transaction_ref and
59 move_line.transaction_ref != reference):
60 # the line has already a transaction id and it is not
61 # a BVR reference
62 return ''
63 return reference
5964
6065
61class AccountInvoice(Model):66class AccountInvoice(Model):
@@ -102,22 +107,35 @@
102 store=True, readonly=True)107 store=True, readonly=True)
103 }108 }
104109
110 def _get_bvr_ref(self, cr, uid, invoice, context=None):
111 """Retrieve ESR/BVR reference form invoice in order to print it
112
113 Receive a browse record so it can be overloaded without rebrowsing
114 the invoice.
115 """
116 res = ''
117 ## We check if the type is bvr, if not we return false
118 if invoice.partner_bank_id.state != 'bvr':
119 return ''
120 ##
121 if invoice.partner_bank_id.bvr_adherent_num:
122 res = invoice.partner_bank_id.bvr_adherent_num
123 invoice_number = ''
124 if invoice.number:
125 invoice_number = self._compile_get_ref.sub('', invoice.number)
126 return mod10r(res + invoice_number.rjust(26 - len(res), '0'))
127
105 def get_bvr_ref(self, cursor, uid, inv_id, context=None):128 def get_bvr_ref(self, cursor, uid, inv_id, context=None):
106 """Retrieve ESR/BVR reference form invoice in order to print it"""129 """Retrieve ESR/BVR reference form invoice in order to print it
107 res = ''130
108 if isinstance(inv_id, list):131 Returns False when no BVR reference should be generated. No
132 reference is generated when the invoice is not a BVR invoice.
133 """
134 if isinstance(inv_id, (list, tuple)):
135 assert len(inv_id) == 1, "1 ID expected, got %s" % inv_id
109 inv_id = inv_id[0]136 inv_id = inv_id[0]
110 inv = self.browse(cursor, uid, inv_id, context=context)137 inv = self.browse(cursor, uid, inv_id, context=context)
111 ## We check if the type is bvr, if not we return false138 return self._get_bvr_ref(cursor, uid, inv, context=context)
112 if inv.partner_bank_id.state != 'bvr':
113 return ''
114 ##
115 if inv.partner_bank_id.bvr_adherent_num:
116 res = inv.partner_bank_id.bvr_adherent_num
117 invoice_number = ''
118 if inv.number:
119 invoice_number = self._compile_get_ref.sub('', inv.number)
120 return mod10r(res + invoice_number.rjust(26 - len(res), '0'))
121139
122 def _space(self, nbr, nbrspc=5):140 def _space(self, nbr, nbrspc=5):
123 """Spaces * 5.141 """Spaces * 5.
@@ -136,37 +154,54 @@
136 (ref, move_id))154 (ref, move_id))
137 return True155 return True
138156
157 def _action_bvr_number_move_line(self, cr, uid, invoice, move_line,
158 ref, context=None):
159 if not ref:
160 return
161 cr.execute('UPDATE account_move_line SET transaction_ref=%s'
162 ' WHERE id=%s', (ref, move_line.id))
163 self._update_ref_on_account_analytic_line(cr, uid, ref,
164 move_line.move_id.id)
165
139 def action_number(self, cr, uid, ids, context=None):166 def action_number(self, cr, uid, ids, context=None):
167 """ Copy the BVR/ESR reference in the transaction_ref of move lines.
168
169 For customers invoices: the BVR reference is computed using
170 ``get_bvr_ref()`` on the invoice or move lines.
171
172 For suppliers invoices: the BVR reference is stored in the reference
173 field of the invoice.
174
175 """
140 res = super(AccountInvoice, self).action_number(cr, uid, ids, context=context)176 res = super(AccountInvoice, self).action_number(cr, uid, ids, context=context)
141 move_line_obj = self.pool.get('account.move.line')177 move_line_obj = self.pool.get('account.move.line')
142 account_obj = self.pool.get('account.account')
143 tier_account_id = account_obj.search(cr, uid, [('type', 'in', ['receivable', 'payable'])])
144178
145 for inv in self.browse(cr, uid, ids, context=context):179 for inv in self.browse(cr, uid, ids, context=context):
146 if inv.type != 'out_invoice' and inv.partner_bank_id.state != 'bvr':180 move_line_ids = move_line_obj.search(
181 cr, uid,
182 [('move_id', '=', inv.move_id.id),
183 ('account_id', '=', inv.account_id.id)],
184 context=context)
185 if not move_line_ids:
147 continue186 continue
148 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', inv.move_id.id),187 move_lines = move_line_obj.browse(cr, uid, move_line_ids,
149 ('account_id', 'in', tier_account_id)])188 context=context)
150 # We keep this branch for compatibility with single BVR report.189 for move_line in move_lines:
151 # This should be cleaned when porting to V8190 if inv.type in ('out_invoice', 'out_refund'):
152 if move_lines:191 if len(move_lines) == 1:
153 if len(move_lines) == 1:192 # We keep this branch for compatibility with single
154 ref = inv.get_bvr_ref()193 # BVR report.
155 move_id = inv.move_id194 # This should be cleaned when porting to V8
156 if move_id:195 ref = inv.get_bvr_ref()
157 cr.execute('UPDATE account_move_line SET transaction_ref=%s'196 else:
158 ' WHERE move_id=%s',
159 (ref, move_id.id))
160 self._update_ref_on_account_analytic_line(cr, uid, ref, move_id.id)
161 else:
162 for move_line in move_line_obj.browse(cr, uid, move_lines, context=context):
163 ref = move_line.get_bvr_ref()197 ref = move_line.get_bvr_ref()
164 if ref:198 elif inv.reference_type == 'bvr' and inv.reference:
165 cr.execute('UPDATE account_move_line SET transaction_ref=%s'199 ref = inv.reference
166 ' WHERE id=%s',200 else:
167 (ref, move_line.id))201 ref = False
168 self._update_ref_on_account_analytic_line(cr, uid, ref,202 self._action_bvr_number_move_line(cr, uid, inv,
169 move_line.move_id.id)203 move_line, ref,
204 context=context)
170 return res205 return res
171206
172 def copy(self, cursor, uid, inv_id, default=None, context=None):207 def copy(self, cursor, uid, inv_id, default=None, context=None):
173208
=== modified file 'l10n_ch_payment_slip/wizard/bvr_import.py'
--- l10n_ch_payment_slip/wizard/bvr_import.py 2013-08-14 14:32:54 +0000
+++ l10n_ch_payment_slip/wizard/bvr_import.py 2014-03-21 07:56:44 +0000
@@ -181,6 +181,49 @@
181 _('The properties account payable account receivable are not set'))181 _('The properties account payable account receivable are not set'))
182 return account_id182 return account_id
183183
184 def _prepare_line_vals(self, cursor, uid, statement, record,
185 voucher_enabled, context=None):
186 # Remove the 11 first char because it can be adherent number
187 # TODO check if 11 is the right number
188 move_line_obj = self.pool.get('account.move.line')
189 reference = record['reference']
190 values = {'name': '/',
191 'date': record['date'],
192 'amount': record['amount'],
193 'ref': reference,
194 'type': (record['amount'] >= 0 and 'customer') or 'supplier',
195 'statement_id': statement.id,
196 }
197 line_ids = move_line_obj.search(cursor, uid,
198 [('ref', '=', reference),
199 ('reconcile_id', '=', False),
200 ('account_id.type', 'in', ['receivable', 'payable']),
201 ('journal_id.type', '=', 'sale')],
202 order='date desc', context=context)
203 #for multiple payments
204 if not line_ids:
205 line_ids = move_line_obj.search(cursor, uid,
206 [('transaction_ref', '=', reference),
207 ('reconcile_id', '=', False),
208 ('account_id.type', 'in', ['receivable', 'payable']),
209 ('journal_id.type', '=', 'sale')],
210 order='date desc', context=context)
211 if not line_ids:
212 line_ids = self._reconstruct_invoice_ref(cursor, uid, reference, None)
213 if line_ids and voucher_enabled:
214 values['voucher_id'] = self._create_voucher_from_record(cursor, uid, record,
215 statement, line_ids,
216 context=context)
217 account_id = self._get_account(cursor, uid, line_ids,
218 record, context=context)
219 values['account_id'] = account_id
220 if line_ids:
221 line = move_line_obj.browse(cursor, uid, line_ids[0])
222 partner_id = line.partner_id.id
223 values['name'] = line.invoice and (_('Inv. no ') + line.invoice.number) or values['name']
224 values['partner_id'] = partner_id
225 return values
226
184 def import_v11(self, cursor, uid, ids, data, context=None):227 def import_v11(self, cursor, uid, ids, data, context=None):
185 """Import v11 file and transfor it into statement lines"""228 """Import v11 file and transfor it into statement lines"""
186 if context is None: context = {}229 if context is None: context = {}
@@ -196,7 +239,6 @@
196 if para.lower() not in ['0', 'false']: # if voucher is disabled239 if para.lower() not in ['0', 'false']: # if voucher is disabled
197 voucher_enabled = False240 voucher_enabled = False
198 statement_line_obj = self.pool.get('account.bank.statement.line')241 statement_line_obj = self.pool.get('account.bank.statement.line')
199 move_line_obj = self.pool.get('account.move.line')
200 attachment_obj = self.pool.get('ir.attachment')242 attachment_obj = self.pool.get('ir.attachment')
201 statement_obj = self.pool.get('account.bank.statement')243 statement_obj = self.pool.get('account.bank.statement')
202 file = data['form']['file']244 file = data['form']['file']
@@ -207,49 +249,11 @@
207 lines = base64.decodestring(file).split("\n")249 lines = base64.decodestring(file).split("\n")
208 records = self._parse_lines(cursor, uid, lines, context=context)250 records = self._parse_lines(cursor, uid, lines, context=context)
209251
210 if context is None:
211 context = {}
212
213 statement = statement_obj.browse(cursor, uid, statement_id, context=context)252 statement = statement_obj.browse(cursor, uid, statement_id, context=context)
214 for record in records:253 for record in records:
215 # Remove the 11 first char because it can be adherent number254 values = self._prepare_line_vals(cursor, uid, statement,
216 # TODO check if 11 is the right number255 record, voucher_enabled,
217 reference = record['reference']256 context=context)
218 values = {'name': reference,
219 'date': record['date'],
220 'amount': record['amount'],
221 'ref': reference,
222 'type': (record['amount'] >= 0 and 'customer') or 'supplier',
223 'statement_id': statement_id,
224 }
225 line_ids = move_line_obj.search(cursor, uid,
226 [('ref', '=', reference),
227 ('reconcile_id', '=', False),
228 ('account_id.type', 'in', ['receivable', 'payable']),
229 ('journal_id.type', '=', 'sale')],
230 order='date desc', context=context)
231 #for multiple payments
232 if not line_ids:
233 line_ids = move_line_obj.search(cursor, uid,
234 [('transaction_ref', '=', reference),
235 ('reconcile_id', '=', False),
236 ('account_id.type', 'in', ['receivable', 'payable']),
237 ('journal_id.type', '=', 'sale')],
238 order='date desc', context=context)
239 if not line_ids:
240 line_ids = self._reconstruct_invoice_ref(cursor, uid, reference, None)
241 if line_ids and voucher_enabled:
242 values['voucher_id'] = self._create_voucher_from_record(cursor, uid, record,
243 statement, line_ids,
244 context=context)
245 account_id = self._get_account(cursor, uid, line_ids,
246 record, context=context)
247 values['account_id'] = account_id
248 if line_ids:
249 line = move_line_obj.browse(cursor, uid, line_ids[0])
250 partner_id = line.partner_id.id
251 values['name'] = line.invoice and (_('Inv. no ') + line.invoice.number) or values['name']
252 values['partner_id'] = partner_id
253 statement_line_obj.create(cursor, uid, values, context=context)257 statement_line_obj.create(cursor, uid, values, context=context)
254 attachment_obj.create(cursor, uid,258 attachment_obj.create(cursor, uid,
255 {'name': 'BVR %s' % time.strftime("%Y-%m-%d_%H:%M:%S", time.gmtime()),259 {'name': 'BVR %s' % time.strftime("%Y-%m-%d_%H:%M:%S", time.gmtime()),
256260
=== added directory 'l10n_ch_payment_slip_account_statement_base_completion'
=== added file 'l10n_ch_payment_slip_account_statement_base_completion/__init__.py'
--- l10n_ch_payment_slip_account_statement_base_completion/__init__.py 1970-01-01 00:00:00 +0000
+++ l10n_ch_payment_slip_account_statement_base_completion/__init__.py 2014-03-21 07:56:44 +0000
@@ -0,0 +1,23 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Guewen Baconnier
5# Copyright 2014 Camptocamp SA
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 . import wizard
23from . import statement
024
=== added file 'l10n_ch_payment_slip_account_statement_base_completion/__openerp__.py'
--- l10n_ch_payment_slip_account_statement_base_completion/__openerp__.py 1970-01-01 00:00:00 +0000
+++ l10n_ch_payment_slip_account_statement_base_completion/__openerp__.py 2014-03-21 07:56:44 +0000
@@ -0,0 +1,52 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Guewen Baconnier
5# Copyright 2014 Camptocamp SA
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' : 'Swiss Localization BVR/ESR - Bank statement Completion',
23 'version' : '1.0',
24 'author' : 'Camptocamp',
25 'maintainer': 'Camptocamp',
26 'license': 'AGPL-3',
27 'category': 'Hidden',
28 'depends' : ['l10n_ch_payment_slip',
29 'account_statement_base_completion', # lp:banking-addons/bank-statement-reconcile-7.0
30 ],
31 'description': """
32Swiss Localization BVR/ESR - Bank statement Completion
33======================================================
34
35Link module between the Swiss localization BVR/ESR module
36(l10n_ch_payment_slip) and the module adding a transaction ID
37field in the bank statement (account_statement_base_completion).
38
39It adds a completion rule to search the partner from the invoice
40using the BVR/ESR reference.
41
42When importing a BVR/ESR, the transaction ID is also copied to the
43transaction id field of the bank statement.
44
45 """,
46 'website': 'http://www.camptocamp.com',
47 'data': ['data.xml',
48 ],
49 'tests': [],
50 'installable': True,
51 'auto_install': True,
52}
053
=== added file 'l10n_ch_payment_slip_account_statement_base_completion/data.xml'
--- l10n_ch_payment_slip_account_statement_base_completion/data.xml 1970-01-01 00:00:00 +0000
+++ l10n_ch_payment_slip_account_statement_base_completion/data.xml 2014-03-21 07:56:44 +0000
@@ -0,0 +1,12 @@
1<?xml version="1.0" encoding="utf-8"?>
2<openerp>
3 <data noupdate="1">
4
5 <record id="bank_statement_completion_rule_bvr_invoice" model="account.statement.completion.rule">
6 <field name="name">Match from Invoice using BVR/ESR Reference</field>
7 <field name="sequence">40</field>
8 <field name="function_to_call">get_from_bvr_reference_and_invoice</field>
9 </record>
10
11 </data>
12</openerp>
013
=== added file 'l10n_ch_payment_slip_account_statement_base_completion/statement.py'
--- l10n_ch_payment_slip_account_statement_base_completion/statement.py 1970-01-01 00:00:00 +0000
+++ l10n_ch_payment_slip_account_statement_base_completion/statement.py 2014-03-21 07:56:44 +0000
@@ -0,0 +1,103 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Guewen Baconnier
5# Copyright 2014 Camptocamp SA
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.tools.translate import _
23from openerp.osv import orm, fields
24from openerp.addons.account_statement_base_completion.statement import (
25 ErrorTooManyPartner
26)
27
28
29class account_statement_completion_rule(orm.Model):
30 """ Add a rule based on BVR Reference """
31 _inherit = "account.statement.completion.rule"
32
33 def _get_functions(self, cr, uid, context=None):
34 res = super(account_statement_completion_rule, self).\
35 _get_functions(cr, uid, context=context)
36 res.append(('get_from_bvr_reference_and_invoice',
37 'Match Invoice using BVR/ESR Reference'))
38 return res
39
40 _columns = {
41 'function_to_call': fields.selection(_get_functions, 'Method'),
42 }
43
44 def get_from_bvr_reference_and_invoice(self, cr, uid, st_line, context=None):
45 """
46 Match the partner based on the BVR reference field of the invoice.
47 Then, call the generic st_line method to complete other values.
48
49 In that case, we always fulfill the reference of the line with
50 the invoice name.
51
52 :param dict st_line: read of the concerned account.bank.statement.line
53 :return:
54 A dict of value that can be passed directly to the write method of
55 the statement line or {}
56 {'partner_id': value,
57 'account_id' : value,
58 ...}
59 """
60 st_obj = self.pool.get('account.bank.statement.line')
61 res = {}
62 invoice_obj = self.pool.get('account.invoice')
63 # For customer invoices, search in bvr_reference that is as list
64 # of references separated by semicolons and formatted with
65 # spaces inside them.
66 # For supplier invoices, search in 'reference'
67 query = ("SELECT id FROM account_invoice "
68 "WHERE company_id = %s "
69 "AND (%s = ANY (string_to_array( "
70 " replace(bvr_reference, ' ', ''), "
71 " ';')) "
72 " AND type IN ('out_invoice', 'out_refund') "
73 " OR type IN ('in_invoice', 'in_refund') "
74 " AND reference_type = 'bvr' AND reference = %s "
75 ")")
76 cr.execute(query, (st_line['company_id'][0],
77 st_line['transaction_id'],
78 st_line['transaction_id']))
79 rows = cr.fetchall()
80 invoice_ids = [row[0] for row in rows]
81 if len(invoice_ids) > 1:
82 raise ErrorTooManyPartner(
83 _('Line named "%s" (Ref:%s) was matched by more than '
84 'one partner.') % (st_line['name'], st_line['ref']))
85 elif len(invoice_ids) == 1:
86 invoice = invoice_obj.browse(cr, uid, invoice_ids[0],
87 context=context)
88 res['partner_id'] = invoice.partner_id.id
89 # we want the move to have the same ref than the found
90 # invoice's move, thus it will be easier to link them for the
91 # accountants
92 if invoice.move_id:
93 res['ref'] = invoice.move_id.ref
94 st_vals = st_obj.get_values_for_line(
95 cr, uid,
96 profile_id=st_line['profile_id'],
97 master_account_id=st_line['master_account_id'],
98 partner_id=res.get('partner_id', False),
99 line_type=st_line['type'],
100 amount=st_line['amount'] if st_line['amount'] else 0.0,
101 context=context)
102 res.update(st_vals)
103 return res
0104
=== added directory 'l10n_ch_payment_slip_account_statement_base_completion/wizard'
=== added file 'l10n_ch_payment_slip_account_statement_base_completion/wizard/__init__.py'
--- l10n_ch_payment_slip_account_statement_base_completion/wizard/__init__.py 1970-01-01 00:00:00 +0000
+++ l10n_ch_payment_slip_account_statement_base_completion/wizard/__init__.py 2014-03-21 07:56:44 +0000
@@ -0,0 +1,3 @@
1# -*- coding: utf-8 -*-
2
3from . import bvr_import
04
=== added file 'l10n_ch_payment_slip_account_statement_base_completion/wizard/bvr_import.py'
--- l10n_ch_payment_slip_account_statement_base_completion/wizard/bvr_import.py 1970-01-01 00:00:00 +0000
+++ l10n_ch_payment_slip_account_statement_base_completion/wizard/bvr_import.py 2014-03-21 07:56:44 +0000
@@ -0,0 +1,34 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Guewen Baconnier
5# Copyright 2014 Camptocamp SA
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 orm
23
24
25class BvrImporterWizard(orm.TransientModel):
26 _inherit = 'bvr.import.wizard'
27
28 def _prepare_line_vals(self, cursor, uid, statement, record,
29 voucher_enabled, context=None):
30 record = super(BvrImporterWizard, self).\
31 _prepare_line_vals(cursor, uid, statement, record,
32 voucher_enabled, context=context)
33 record['transaction_id'] = record['ref']
34 return record
035
=== added directory 'l10n_ch_payment_slip_base_transaction_id'
=== added file 'l10n_ch_payment_slip_base_transaction_id/__init__.py'
--- l10n_ch_payment_slip_base_transaction_id/__init__.py 1970-01-01 00:00:00 +0000
+++ l10n_ch_payment_slip_base_transaction_id/__init__.py 2014-03-21 07:56:44 +0000
@@ -0,0 +1,22 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Guewen Baconnier
5# Copyright 2014 Camptocamp SA
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 . import invoice
023
=== added file 'l10n_ch_payment_slip_base_transaction_id/__openerp__.py'
--- l10n_ch_payment_slip_base_transaction_id/__openerp__.py 1970-01-01 00:00:00 +0000
+++ l10n_ch_payment_slip_base_transaction_id/__openerp__.py 2014-03-21 07:56:44 +0000
@@ -0,0 +1,48 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Guewen Baconnier
5# Copyright 2014 Camptocamp SA
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' : 'Swiss Localization BVR/ESR - Transaction ID Compatibility',
23 'version' : '1.0',
24 'author' : 'Camptocamp',
25 'maintainer': 'Camptocamp',
26 'license': 'AGPL-3',
27 'category': 'Hidden',
28 'depends' : ['l10n_ch_payment_slip',
29 'base_transaction_id', # lp:banking-addons/bank-statement-reconcile-7.0
30 ],
31 'description': """
32Swiss Localization BVR/ESR - Transaction ID Compatibility
33==========================================================
34
35Link module between the Swiss localization BVR/ESR module
36(l10n_ch_payment_slip) and the module adding a transaction ID
37field (base_transaction_id).
38
39When an invoice has a transaction ID, no BVR reference should be generated
40because the reconciliation should be done with the transaction ID, not
41a new reference.
42 """,
43 'website': 'http://www.camptocamp.com',
44 'data': [],
45 'tests': [],
46 'installable': True,
47 'auto_install': True,
48}
049
=== added file 'l10n_ch_payment_slip_base_transaction_id/invoice.py'
--- l10n_ch_payment_slip_base_transaction_id/invoice.py 1970-01-01 00:00:00 +0000
+++ l10n_ch_payment_slip_base_transaction_id/invoice.py 2014-03-21 07:56:44 +0000
@@ -0,0 +1,39 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Guewen Baconnier
5# Copyright 2014 Camptocamp SA
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 orm
23
24
25class account_invoice(orm.Model):
26 _inherit = 'account.invoice'
27
28 def _get_bvr_ref(self, cr, uid, invoice, context=None):
29 """Retrieve ESR/BVR reference form invoice in order to print it
30
31 Returns False when no BVR reference should be generated. No
32 reference is generated when a transaction ID already exists on
33 the invoice (likely generated by a payment service so BVR ref not
34 used).
35 """
36 if invoice.transaction_id:
37 return ''
38 return super(account_invoice, self)._get_bvr_ref(cr, uid, invoice,
39 context=context)

Subscribers

People subscribed via source and target branches

to all changes: