Merge lp:~luc-demeyer/openobject-addons/61-update-l10n_be_invoice_bba into lp:openobject-addons/6.1

Proposed by Luc De Meyer (Noviat)
Status: Needs review
Proposed branch: lp:~luc-demeyer/openobject-addons/61-update-l10n_be_invoice_bba
Merge into: lp:openobject-addons/6.1
Diff against target: 992 lines (+353/-501)
8 files modified
l10n_be_invoice_bba/__init__.py (+3/-2)
l10n_be_invoice_bba/__openerp__.py (+6/-4)
l10n_be_invoice_bba/account_invoice_view.xml (+6/-7)
l10n_be_invoice_bba/i18n/fr.po (+14/-128)
l10n_be_invoice_bba/i18n/nl.po (+14/-128)
l10n_be_invoice_bba/invoice.py (+300/-217)
l10n_be_invoice_bba/partner.py (+9/-14)
l10n_be_invoice_bba/partner_view.xml (+1/-1)
To merge this branch: bzr merge lp:~luc-demeyer/openobject-addons/61-update-l10n_be_invoice_bba
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+129254@code.launchpad.net
To post a comment you must log in.

Unmerged revisions

7027. By root <root@oerp61>

update 6.1 l10n_be_invoice_bba

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'l10n_be_invoice_bba/__init__.py' (properties changed: -x to +x)
2--- l10n_be_invoice_bba/__init__.py 2011-12-19 16:54:40 +0000
3+++ l10n_be_invoice_bba/__init__.py 2012-10-11 16:56:43 +0000
4@@ -3,7 +3,7 @@
5 #
6 # OpenERP, Open Source Management Solution
7 #
8-# Copyright (c) 2011 Noviat nv/sa (www.noviat.be). All rights reserved.
9+# Copyright (c) 2012 Noviat nv/sa (www.noviat.be). All rights reserved.
10 #
11 # This program is free software: you can redistribute it and/or modify
12 # it under the terms of the GNU Affero General Public License as
13@@ -22,5 +22,6 @@
14
15 import partner
16 import invoice
17+import account_invoice_refund
18
19-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
20+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
21\ No newline at end of file
22
23=== modified file 'l10n_be_invoice_bba/__openerp__.py' (properties changed: -x to +x)
24--- l10n_be_invoice_bba/__openerp__.py 2012-04-25 08:31:05 +0000
25+++ l10n_be_invoice_bba/__openerp__.py 2012-10-11 16:56:43 +0000
26@@ -3,7 +3,7 @@
27 #
28 # OpenERP, Open Source Management Solution
29 #
30-# Copyright (c) 2011 Noviat nv/sa (www.noviat.be). All rights reserved.
31+# Copyright (c) 2012 Noviat nv/sa (www.noviat.be). All rights reserved.
32 #
33 # This program is free software: you can redistribute it and/or modify
34 # it under the terms of the GNU Affero General Public License as
35@@ -22,7 +22,7 @@
36
37 {
38 'name': 'Belgium - Structured Communication',
39- 'version': '1.2',
40+ 'version': '1.5',
41 'license': 'AGPL-3',
42 'author': 'Noviat',
43 'category' : 'Localization',
44@@ -52,7 +52,9 @@
45 'account_invoice_view.xml',
46 ],
47 'auto_install': False,
48- 'installable': True, 'certificate': '00137058831885',
49-}
50+ 'installable': True,
51+ 'certificate': '00137058831885',
52+ }
53
54 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
55+
56
57=== modified file 'l10n_be_invoice_bba/account_invoice_view.xml' (properties changed: -x to +x)
58--- l10n_be_invoice_bba/account_invoice_view.xml 2011-08-12 15:14:50 +0000
59+++ l10n_be_invoice_bba/account_invoice_view.xml 2012-10-11 16:56:43 +0000
60@@ -4,17 +4,16 @@
61
62 <!-- Adapt Customer Invoices to support bba structured communication -->
63 <record id="customer_invoice_bbacomm_form" model="ir.ui.view">
64- <field name="name">account.invoice.form.inherit</field>
65+ <field name="name">account.invoice.form.bbacomm.inherit</field>
66 <field name="model">account.invoice</field>
67 <field name="type">form</field>
68 <field name="inherit_id" ref="account.invoice_form"/>
69 <field name="arch" type="xml">
70- <field name="payment_term" position="after">
71- <group col="4" colspan="2">
72- <field name="reference_type" nolabel="1" select="2" size="0" attrs="{'readonly':[('state','!=','draft')]}"
73- on_change="generate_bbacomm(type,reference_type,algorithm,partner_id,reference)" colspan="1"/>
74- <field name="reference" nolabel="1" select="1" colspan="3" attrs="{'readonly':[('state','!=','draft')]}"/>
75- </group>
76+ <field name="invoice_line" position="before">
77+ <newline/>
78+ <field name="reference_type" nolabel="1" select="2" size="0" attrs="{'readonly':[('state','!=','draft')]}"
79+ on_change="generate_bbacomm(type,reference_type,partner_id,reference)"/>
80+ <field name="reference" nolabel="1" select="1" colspan="3" attrs="{'readonly':[('state','!=','draft')]}"/>
81 </field>
82 </field>
83 </record>
84
85=== modified file 'l10n_be_invoice_bba/i18n/fr.po' (properties changed: -x to +x)
86--- l10n_be_invoice_bba/i18n/fr.po 2012-08-28 10:07:53 +0000
87+++ l10n_be_invoice_bba/i18n/fr.po 2012-10-11 16:56:43 +0000
88@@ -1,140 +1,26 @@
89-# French translation of openobject-addons.
90+# French translation of OpenERP Server 6.1.
91 # This file contains the translation of the following modules:
92-# * l10n_be_extra
93+# * l10n_be_invoice_bba
94 #
95 msgid ""
96 msgstr ""
97-"Project-Id-Version: openobject-addons\n"
98+"Project-Id-Version: OpenERP Server 6.1\n"
99 "Report-Msgid-Bugs-To: support@noviat.be\n"
100-"POT-Creation-Date: 2012-02-08 00:36+0000\n"
101-"PO-Revision-Date: 2012-02-17 15:56+0000\n"
102-"Last-Translator: Antony Lesuisse (OpenERP) <al@openerp.com>\n"
103+"POT-Creation-Date: 2012-07-19 14:18:28.337000\n"
104+"PO-Revision-Date: 2012-07-19 14:18:28.337000\n"
105+"Last-Translator: Luc De Meyer (Noviat nv/sa)\n"
106 "Language-Team: \n"
107 "MIME-Version: 1.0\n"
108 "Content-Type: text/plain; charset=UTF-8\n"
109 "Content-Transfer-Encoding: 8bit\n"
110-"X-Launchpad-Export-Date: 2012-08-28 09:48+0000\n"
111-"X-Generator: Launchpad (build 15864)\n"
112-
113-#. module: l10n_be_invoice_bba
114-#: sql_constraint:account.invoice:0
115-msgid "Invoice Number must be unique per Company!"
116-msgstr ""
117-
118-#. module: l10n_be_invoice_bba
119-#: model:ir.model,name:l10n_be_invoice_bba.model_account_invoice
120-msgid "Invoice"
121-msgstr ""
122-
123-#. module: l10n_be_invoice_bba
124-#: constraint:res.partner:0
125-msgid "Error ! You cannot create recursive associated members."
126-msgstr ""
127-
128-#. module: l10n_be_invoice_bba
129-#: constraint:account.invoice:0
130-msgid "Invalid BBA Structured Communication !"
131-msgstr ""
132-
133-#. module: l10n_be_invoice_bba
134-#: selection:res.partner,out_inv_comm_algorithm:0
135-msgid "Random"
136-msgstr ""
137-
138-#. module: l10n_be_invoice_bba
139-#: help:res.partner,out_inv_comm_type:0
140-msgid "Select Default Communication Type for Outgoing Invoices."
141-msgstr ""
142-
143-#. module: l10n_be_invoice_bba
144-#: help:res.partner,out_inv_comm_algorithm:0
145-msgid ""
146-"Select Algorithm to generate the Structured Communication on Outgoing "
147-"Invoices."
148-msgstr ""
149-
150-#. module: l10n_be_invoice_bba
151-#: code:addons/l10n_be_invoice_bba/invoice.py:114
152-#: code:addons/l10n_be_invoice_bba/invoice.py:140
153-#, python-format
154-msgid ""
155-"The daily maximum of outgoing invoices with an automatically generated BBA "
156-"Structured Communications has been exceeded!\n"
157-"Please create manually a unique BBA Structured Communication."
158-msgstr ""
159-
160-#. module: l10n_be_invoice_bba
161-#: code:addons/l10n_be_invoice_bba/invoice.py:155
162-#, python-format
163-msgid "Error!"
164-msgstr ""
165-
166-#. module: l10n_be_invoice_bba
167-#: code:addons/l10n_be_invoice_bba/invoice.py:126
168-#, python-format
169-msgid ""
170-"The Partner should have a 3-7 digit Reference Number for the generation of "
171-"BBA Structured Communications!\n"
172-"Please correct the Partner record."
173-msgstr ""
174-
175-#. module: l10n_be_invoice_bba
176-#: code:addons/l10n_be_invoice_bba/invoice.py:113
177-#: code:addons/l10n_be_invoice_bba/invoice.py:125
178-#: code:addons/l10n_be_invoice_bba/invoice.py:139
179-#: code:addons/l10n_be_invoice_bba/invoice.py:167
180-#: code:addons/l10n_be_invoice_bba/invoice.py:177
181-#: code:addons/l10n_be_invoice_bba/invoice.py:202
182-#, python-format
183-msgid "Warning!"
184-msgstr ""
185-
186-#. module: l10n_be_invoice_bba
187-#: selection:res.partner,out_inv_comm_algorithm:0
188-msgid "Customer Reference"
189-msgstr ""
190-
191-#. module: l10n_be_invoice_bba
192-#: field:res.partner,out_inv_comm_type:0
193+
194+#. module: l10n_be_invoice_bba
195+#: field:account.invoice,reference:0
196+msgid "Communication"
197+msgstr "Communication"
198+
199+#. module: l10n_be_invoice_bba
200+#: field:account.invoice,reference_type:0
201 msgid "Communication Type"
202 msgstr "Type de communication"
203
204-#. module: l10n_be_invoice_bba
205-#: code:addons/l10n_be_invoice_bba/invoice.py:178
206-#: code:addons/l10n_be_invoice_bba/invoice.py:203
207-#, python-format
208-msgid ""
209-"The BBA Structured Communication has already been used!\n"
210-"Please create manually a unique BBA Structured Communication."
211-msgstr ""
212-
213-#. module: l10n_be_invoice_bba
214-#: selection:res.partner,out_inv_comm_algorithm:0
215-msgid "Date"
216-msgstr ""
217-
218-#. module: l10n_be_invoice_bba
219-#: model:ir.model,name:l10n_be_invoice_bba.model_res_partner
220-msgid "Partner"
221-msgstr ""
222-
223-#. module: l10n_be_invoice_bba
224-#: code:addons/l10n_be_invoice_bba/invoice.py:156
225-#, python-format
226-msgid ""
227-"Unsupported Structured Communication Type Algorithm '%s' !\n"
228-"Please contact your OpenERP support channel."
229-msgstr ""
230-
231-#. module: l10n_be_invoice_bba
232-#: field:res.partner,out_inv_comm_algorithm:0
233-msgid "Communication Algorithm"
234-msgstr ""
235-
236-#. module: l10n_be_invoice_bba
237-#: code:addons/l10n_be_invoice_bba/invoice.py:168
238-#, python-format
239-msgid ""
240-"Empty BBA Structured Communication!\n"
241-"Please fill in a unique BBA Structured Communication."
242-msgstr ""
243
244=== modified file 'l10n_be_invoice_bba/i18n/nl.po' (properties changed: -x to +x)
245--- l10n_be_invoice_bba/i18n/nl.po 2012-08-28 10:07:53 +0000
246+++ l10n_be_invoice_bba/i18n/nl.po 2012-10-11 16:56:43 +0000
247@@ -1,140 +1,26 @@
248-# Dutch translation of openobject-addons.
249+# Dutch translation of OpenERP Server 6.1.
250 # This file contains the translation of the following modules:
251-# * l10n_be_extra
252+# * l10n_be_invoice_bba
253 #
254 msgid ""
255 msgstr ""
256-"Project-Id-Version: openobject-addons\n"
257+"Project-Id-Version: OpenERP Server 6.1\n"
258 "Report-Msgid-Bugs-To: support@noviat.be\n"
259-"POT-Creation-Date: 2012-02-08 00:36+0000\n"
260-"PO-Revision-Date: 2012-02-17 11:38+0000\n"
261-"Last-Translator: Antony Lesuisse (OpenERP) <al@openerp.com>\n"
262+"POT-Creation-Date: 2012-07-19 14:18:28.302000\n"
263+"PO-Revision-Date: 2012-07-19 14:18:28.302000\n"
264+"Last-Translator: Luc De Meyer (Noviat nv/sa)\n"
265 "Language-Team: \n"
266 "MIME-Version: 1.0\n"
267 "Content-Type: text/plain; charset=UTF-8\n"
268 "Content-Transfer-Encoding: 8bit\n"
269-"X-Launchpad-Export-Date: 2012-08-28 09:48+0000\n"
270-"X-Generator: Launchpad (build 15864)\n"
271-
272-#. module: l10n_be_invoice_bba
273-#: sql_constraint:account.invoice:0
274-msgid "Invoice Number must be unique per Company!"
275-msgstr ""
276-
277-#. module: l10n_be_invoice_bba
278-#: model:ir.model,name:l10n_be_invoice_bba.model_account_invoice
279-msgid "Invoice"
280-msgstr ""
281-
282-#. module: l10n_be_invoice_bba
283-#: constraint:res.partner:0
284-msgid "Error ! You cannot create recursive associated members."
285-msgstr ""
286-
287-#. module: l10n_be_invoice_bba
288-#: constraint:account.invoice:0
289-msgid "Invalid BBA Structured Communication !"
290-msgstr ""
291-
292-#. module: l10n_be_invoice_bba
293-#: selection:res.partner,out_inv_comm_algorithm:0
294-msgid "Random"
295-msgstr ""
296-
297-#. module: l10n_be_invoice_bba
298-#: help:res.partner,out_inv_comm_type:0
299-msgid "Select Default Communication Type for Outgoing Invoices."
300-msgstr ""
301-
302-#. module: l10n_be_invoice_bba
303-#: help:res.partner,out_inv_comm_algorithm:0
304-msgid ""
305-"Select Algorithm to generate the Structured Communication on Outgoing "
306-"Invoices."
307-msgstr ""
308-
309-#. module: l10n_be_invoice_bba
310-#: code:addons/l10n_be_invoice_bba/invoice.py:114
311-#: code:addons/l10n_be_invoice_bba/invoice.py:140
312-#, python-format
313-msgid ""
314-"The daily maximum of outgoing invoices with an automatically generated BBA "
315-"Structured Communications has been exceeded!\n"
316-"Please create manually a unique BBA Structured Communication."
317-msgstr ""
318-
319-#. module: l10n_be_invoice_bba
320-#: code:addons/l10n_be_invoice_bba/invoice.py:155
321-#, python-format
322-msgid "Error!"
323-msgstr ""
324-
325-#. module: l10n_be_invoice_bba
326-#: code:addons/l10n_be_invoice_bba/invoice.py:126
327-#, python-format
328-msgid ""
329-"The Partner should have a 3-7 digit Reference Number for the generation of "
330-"BBA Structured Communications!\n"
331-"Please correct the Partner record."
332-msgstr ""
333-
334-#. module: l10n_be_invoice_bba
335-#: code:addons/l10n_be_invoice_bba/invoice.py:113
336-#: code:addons/l10n_be_invoice_bba/invoice.py:125
337-#: code:addons/l10n_be_invoice_bba/invoice.py:139
338-#: code:addons/l10n_be_invoice_bba/invoice.py:167
339-#: code:addons/l10n_be_invoice_bba/invoice.py:177
340-#: code:addons/l10n_be_invoice_bba/invoice.py:202
341-#, python-format
342-msgid "Warning!"
343-msgstr ""
344-
345-#. module: l10n_be_invoice_bba
346-#: selection:res.partner,out_inv_comm_algorithm:0
347-msgid "Customer Reference"
348-msgstr ""
349-
350-#. module: l10n_be_invoice_bba
351-#: field:res.partner,out_inv_comm_type:0
352+
353+#. module: l10n_be_invoice_bba
354+#: field:account.invoice,reference:0
355+msgid "Communication"
356+msgstr "Mededeling"
357+
358+#. module: l10n_be_invoice_bba
359+#: field:account.invoice,reference_type:0
360 msgid "Communication Type"
361 msgstr "Type mededeling"
362
363-#. module: l10n_be_invoice_bba
364-#: code:addons/l10n_be_invoice_bba/invoice.py:178
365-#: code:addons/l10n_be_invoice_bba/invoice.py:203
366-#, python-format
367-msgid ""
368-"The BBA Structured Communication has already been used!\n"
369-"Please create manually a unique BBA Structured Communication."
370-msgstr ""
371-
372-#. module: l10n_be_invoice_bba
373-#: selection:res.partner,out_inv_comm_algorithm:0
374-msgid "Date"
375-msgstr ""
376-
377-#. module: l10n_be_invoice_bba
378-#: model:ir.model,name:l10n_be_invoice_bba.model_res_partner
379-msgid "Partner"
380-msgstr ""
381-
382-#. module: l10n_be_invoice_bba
383-#: code:addons/l10n_be_invoice_bba/invoice.py:156
384-#, python-format
385-msgid ""
386-"Unsupported Structured Communication Type Algorithm '%s' !\n"
387-"Please contact your OpenERP support channel."
388-msgstr ""
389-
390-#. module: l10n_be_invoice_bba
391-#: field:res.partner,out_inv_comm_algorithm:0
392-msgid "Communication Algorithm"
393-msgstr ""
394-
395-#. module: l10n_be_invoice_bba
396-#: code:addons/l10n_be_invoice_bba/invoice.py:168
397-#, python-format
398-msgid ""
399-"Empty BBA Structured Communication!\n"
400-"Please fill in a unique BBA Structured Communication."
401-msgstr ""
402
403=== modified file 'l10n_be_invoice_bba/invoice.py' (properties changed: -x to +x)
404--- l10n_be_invoice_bba/invoice.py 2011-12-19 16:54:40 +0000
405+++ l10n_be_invoice_bba/invoice.py 2012-10-11 16:56:43 +0000
406@@ -1,219 +1,302 @@
407-# -*- encoding: utf-8 -*-
408-##############################################################################
409-#
410-# OpenERP, Open Source Management Solution
411-#
412-# Copyright (c) 2011 Noviat nv/sa (www.noviat.be). All rights reserved.
413-#
414-# This program is free software: you can redistribute it and/or modify
415-# it under the terms of the GNU Affero General Public License as
416-# published by the Free Software Foundation, either version 3 of the
417-# License, or (at your option) any later version.
418-#
419-# This program is distributed in the hope that it will be useful,
420-# but WITHOUT ANY WARRANTY; without even the implied warranty of
421-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
422-# GNU Affero General Public License for more details.
423-#
424-# You should have received a copy of the GNU Affero General Public License
425-# along with this program. If not, see <http://www.gnu.org/licenses/>.
426-#
427-##############################################################################
428-
429-import re, time, random
430-from osv import fields, osv
431-from tools.translate import _
432-import netsvc
433-logger=netsvc.Logger()
434-
435-"""
436-account.invoice object:
437- - Add support for Belgian structured communication
438- - Rename 'reference' field labels to 'Communication'
439-"""
440-
441-class account_invoice(osv.osv):
442- _inherit = 'account.invoice'
443-
444- def _get_reference_type(self, cursor, user, context=None):
445- """Add BBA Structured Communication Type and change labels from 'reference' into 'communication' """
446- res = super(account_invoice, self)._get_reference_type(cursor, user,
447- context=context)
448- res[[i for i,x in enumerate(res) if x[0] == 'none'][0]] = ('none', 'Free Communication')
449- res.append(('bba', 'BBA Structured Communication'))
450- #logger.notifyChannel('addons.'+self._name, netsvc.LOG_WARNING, 'reference_type = %s' %res )
451- return res
452-
453- def check_bbacomm(self, val):
454- supported_chars = '0-9+*/ '
455- pattern = re.compile('[^' + supported_chars + ']')
456- if pattern.findall(val or ''):
457- return False
458- bbacomm = re.sub('\D', '', val or '')
459- if len(bbacomm) == 12:
460- base = int(bbacomm[:10])
461- mod = base % 97 or 97
462- if mod == int(bbacomm[-2:]):
463- return True
464- return False
465-
466- def _check_communication(self, cr, uid, ids):
467- for inv in self.browse(cr, uid, ids):
468- if inv.reference_type == 'bba':
469- return self.check_bbacomm(inv.reference)
470- return True
471-
472- def onchange_partner_id(self, cr, uid, ids, type, partner_id,
473- date_invoice=False, payment_term=False, partner_bank_id=False, company_id=False):
474- result = super(account_invoice, self).onchange_partner_id(cr, uid, ids, type, partner_id,
475- date_invoice, payment_term, partner_bank_id, company_id)
476-# reference_type = self.default_get(cr, uid, ['reference_type'])['reference_type']
477-# logger.notifyChannel('addons.'+self._name, netsvc.LOG_WARNING, 'partner_id %s' % partner_id)
478- reference = False
479- reference_type = 'none'
480- if partner_id:
481- if (type == 'out_invoice'):
482- reference_type = self.pool.get('res.partner').browse(cr, uid, partner_id).out_inv_comm_type
483- if reference_type:
484- algorithm = self.pool.get('res.partner').browse(cr, uid, partner_id).out_inv_comm_algorithm
485- if not algorithm:
486- algorithm = 'random'
487- reference = self.generate_bbacomm(cr, uid, ids, type, reference_type, algorithm, partner_id, '')['value']['reference']
488- res_update = {
489- 'reference_type': reference_type or 'none',
490- 'reference': reference,
491- }
492- result['value'].update(res_update)
493- return result
494-
495- def generate_bbacomm(self, cr, uid, ids, type, reference_type, algorithm, partner_id, reference):
496- partner_obj = self.pool.get('res.partner')
497- reference = reference or ''
498- if (type == 'out_invoice'):
499- if reference_type == 'bba':
500- if not algorithm:
501- if partner_id:
502- algorithm = partner_obj.browse(cr, uid, partner_id).out_inv_comm_algorithm
503- if not algorithm:
504- if not algorithm:
505- algorithm = 'random'
506- if algorithm == 'date':
507- if not self.check_bbacomm(reference):
508- doy = time.strftime('%j')
509- year = time.strftime('%Y')
510- seq = '001'
511- seq_ids = self.search(cr, uid,
512- [('type', '=', 'out_invoice'), ('reference_type', '=', 'bba'),
513- ('reference', 'like', '+++%s/%s/%%' % (doy, year))], order='reference')
514- if seq_ids:
515- prev_seq = int(self.browse(cr, uid, seq_ids[-1]).reference[12:15])
516- if prev_seq < 999:
517- seq = '%03d' % (prev_seq + 1)
518- else:
519- raise osv.except_osv(_('Warning!'),
520- _('The daily maximum of outgoing invoices with an automatically generated BBA Structured Communications has been exceeded!' \
521- '\nPlease create manually a unique BBA Structured Communication.'))
522- bbacomm = doy + year + seq
523- base = int(bbacomm)
524- mod = base % 97 or 97
525- reference = '+++%s/%s/%s%02d+++' % (doy, year, seq, mod)
526- elif algorithm == 'partner_ref':
527- if not self.check_bbacomm(reference):
528- partner_ref = self.pool.get('res.partner').browse(cr, uid, partner_id).ref
529- partner_ref_nr = re.sub('\D', '', partner_ref or '')
530- if (len(partner_ref_nr) < 3) or (len(partner_ref_nr) > 7):
531- raise osv.except_osv(_('Warning!'),
532- _('The Partner should have a 3-7 digit Reference Number for the generation of BBA Structured Communications!' \
533- '\nPlease correct the Partner record.'))
534- else:
535- partner_ref_nr = partner_ref_nr.ljust(7, '0')
536- seq = '001'
537- seq_ids = self.search(cr, uid,
538- [('type', '=', 'out_invoice'), ('reference_type', '=', 'bba'),
539- ('reference', 'like', '+++%s/%s/%%' % (partner_ref_nr[:3], partner_ref_nr[3:]))], order='reference')
540- if seq_ids:
541- prev_seq = int(self.browse(cr, uid, seq_ids[-1]).reference[12:15])
542- if prev_seq < 999:
543- seq = '%03d' % (prev_seq + 1)
544- else:
545- raise osv.except_osv(_('Warning!'),
546- _('The daily maximum of outgoing invoices with an automatically generated BBA Structured Communications has been exceeded!' \
547- '\nPlease create manually a unique BBA Structured Communication.'))
548- bbacomm = partner_ref_nr + seq
549- base = int(bbacomm)
550- mod = base % 97 or 97
551- reference = '+++%s/%s/%s%02d+++' % (partner_ref_nr[:3], partner_ref_nr[3:], seq, mod)
552- elif algorithm == 'random':
553- if not self.check_bbacomm(reference):
554- base = random.randint(1, 9999999999)
555- bbacomm = str(base).rjust(7, '0')
556- base = int(bbacomm)
557- mod = base % 97 or 97
558- mod = str(mod).rjust(2, '0')
559- reference = '+++%s/%s/%s%s+++' % (bbacomm[:3], bbacomm[3:7], bbacomm[7:], mod)
560- else:
561- raise osv.except_osv(_('Error!'),
562- _("Unsupported Structured Communication Type Algorithm '%s' !" \
563- "\nPlease contact your OpenERP support channel.") % algorithm)
564- return {'value': {'reference': reference}}
565-
566- def create(self, cr, uid, vals, context=None):
567- if vals.has_key('reference_type'):
568- reference_type = vals['reference_type']
569- if reference_type == 'bba':
570- if vals.has_key('reference'):
571- bbacomm = vals['reference']
572- else:
573- raise osv.except_osv(_('Warning!'),
574- _('Empty BBA Structured Communication!' \
575- '\nPlease fill in a unique BBA Structured Communication.'))
576- if self.check_bbacomm(bbacomm):
577- reference = re.sub('\D', '', bbacomm)
578- vals['reference'] = '+++' + reference[0:3] + '/' + reference[3:7] + '/' + reference[7:] + '+++'
579- same_ids = self.search(cr, uid,
580- [('type', '=', 'out_invoice'), ('reference_type', '=', 'bba'),
581- ('reference', '=', vals['reference'])])
582- if same_ids:
583- raise osv.except_osv(_('Warning!'),
584- _('The BBA Structured Communication has already been used!' \
585- '\nPlease create manually a unique BBA Structured Communication.'))
586- return super(account_invoice, self).create(cr, uid, vals, context=context)
587-
588- def write(self, cr, uid, ids, vals, context={}):
589- if isinstance(ids, (int, long)):
590- ids = [ids]
591- for inv in self.browse(cr, uid, ids, context):
592- if vals.has_key('reference_type'):
593- reference_type = vals['reference_type']
594- else:
595- reference_type = inv.reference_type or ''
596- if reference_type == 'bba':
597- if vals.has_key('reference'):
598- bbacomm = vals['reference']
599- else:
600- bbacomm = inv.reference or ''
601- if self.check_bbacomm(bbacomm):
602- reference = re.sub('\D', '', bbacomm)
603- vals['reference'] = '+++' + reference[0:3] + '/' + reference[3:7] + '/' + reference[7:] + '+++'
604- same_ids = self.search(cr, uid,
605- [('id', '!=', inv.id), ('type', '=', 'out_invoice'),
606- ('reference_type', '=', 'bba'), ('reference', '=', vals['reference'])])
607- if same_ids:
608- raise osv.except_osv(_('Warning!'),
609- _('The BBA Structured Communication has already been used!' \
610- '\nPlease create manually a unique BBA Structured Communication.'))
611- return super(account_invoice, self).write(cr, uid, ids, vals, context)
612-
613- _columns = {
614- 'reference': fields.char('Communication', size=64, help="The partner reference of this invoice."),
615- 'reference_type': fields.selection(_get_reference_type, 'Communication Type',
616- required=True),
617- }
618-
619- _constraints = [
620- (_check_communication, 'Invalid BBA Structured Communication !', ['Communication']),
621- ]
622-
623-account_invoice()
624+# -*- encoding: utf-8 -*-
625+##############################################################################
626+#
627+# OpenERP, Open Source Management Solution
628+#
629+# Copyright (c) 2012 Noviat nv/sa (www.noviat.be). All rights reserved.
630+#
631+# This program is free software: you can redistribute it and/or modify
632+# it under the terms of the GNU Affero General Public License as
633+# published by the Free Software Foundation, either version 3 of the
634+# License, or (at your option) any later version.
635+#
636+# This program is distributed in the hope that it will be useful,
637+# but WITHOUT ANY WARRANTY; without even the implied warranty of
638+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
639+# GNU Affero General Public License for more details.
640+#
641+# You should have received a copy of the GNU Affero General Public License
642+# along with this program. If not, see <http://www.gnu.org/licenses/>.
643+#
644+##############################################################################
645+
646+import re, time, random
647+from osv import fields, osv
648+from tools.translate import _
649+import logging
650+_logger = logging.getLogger(__name__)
651+
652+"""
653+account.invoice object:
654+ - Add support for Belgian structured communication
655+ - Rename 'reference' field labels to 'Communication'
656+"""
657+
658+class account_invoice(osv.osv):
659+ _inherit = 'account.invoice'
660+
661+ def _get_reference_type(self, cursor, user, context=None):
662+ """Add BBA Structured Communication Type and change labels from 'reference' into 'communication' """
663+ res = super(account_invoice, self)._get_reference_type(cursor, user,
664+ context=context)
665+ res[[i for i,x in enumerate(res) if x[0] == 'none'][0]] = ('none', 'Free Communication')
666+ res.append(('bba', 'BBA Structured Communication'))
667+ return res
668+
669+ def check_bbacomm(self, val):
670+ supported_chars = '0-9+*/ '
671+ pattern = re.compile('[^' + supported_chars + ']')
672+ if pattern.findall(val or ''):
673+ return False
674+ bbacomm = re.sub('\D', '', val or '')
675+ if len(bbacomm) == 12:
676+ base = int(bbacomm[:10])
677+ mod = base % 97 or 97
678+ if mod == int(bbacomm[-2:]):
679+ return True
680+ return False
681+
682+ def duplicate_bba(self, cr, uid, inv_type, reference, partner):
683+ """ overwrite this method to customise the handling of duplicate BBA communications """
684+ error = False
685+ reference_type = 'bba'
686+ if inv_type == 'out_invoice':
687+ if partner.out_inv_comm_algorithm == 'random':
688+ # generate new bbacom to cope with following situation duplicate bba coming out of random generator
689+ reference = self.generate_bbacomm(cr, uid, [], inv_type, reference_type, partner.id, False)['value']['reference']
690+ else:
691+ # replace duplicate BBA Comms created manually or by OpenERP applications (e.g. Sales Order Refund/Modify)
692+ reference = self.generate_bbacomm(cr, uid, [], inv_type, reference_type, partner.id, False)['value']['reference']
693+ if error:
694+ raise osv.except_osv(_('Warning!'),
695+ _('The BBA Structured Communication has already been used!' \
696+ '\nPlease use a unique BBA Structured Communication.'))
697+ return reference_type, reference
698+
699+ def _check_communication(self, cr, uid, ids):
700+ for inv in self.browse(cr, uid, ids):
701+ if inv.reference_type == 'bba':
702+ return self.check_bbacomm(inv.reference)
703+ return True
704+
705+ def onchange_partner_id(self, cr, uid, ids, type, partner_id,
706+ date_invoice=False, payment_term=False, partner_bank_id=False, company_id=False):
707+ result = super(account_invoice, self).onchange_partner_id(cr, uid, ids, type, partner_id,
708+ date_invoice, payment_term, partner_bank_id, company_id)
709+ reference = False
710+ reference_type = 'none'
711+ if partner_id:
712+ if type in ['out_invoice']:
713+ reference_type = self.pool.get('res.partner').browse(cr, uid, partner_id).out_inv_comm_type or 'none'
714+ if (type == 'out_invoice'):
715+ if reference_type == 'bba':
716+ reference = self.generate_bbacomm(cr, uid, ids, type, reference_type, partner_id, reference)['value']['reference']
717+ res_update = {
718+ 'reference_type': reference_type,
719+ 'reference': reference,
720+ }
721+ result['value'].update(res_update)
722+ return result
723+
724+ def generate_bbacomm(self, cr, uid, ids, type, reference_type, partner_id, reference):
725+ reference = reference or ''
726+ if partner_id:
727+ partner = self.pool.get('res.partner').browse(cr, uid, partner_id)
728+ if not reference_type:
729+ reference_type = partner.out_inv_comm_type
730+ if (type == 'out_invoice'):
731+ if reference_type == 'bba':
732+ algorithm = partner.out_inv_comm_algorithm or 'random'
733+ if algorithm == 'date':
734+ if not self.check_bbacomm(reference):
735+ doy = time.strftime('%j')
736+ year = time.strftime('%Y')
737+ seq = '001'
738+ seq_ids = self.search(cr, uid,
739+ [('type', '=', 'out_invoice'), ('reference_type', '=', 'bba'),
740+ ('reference', 'like', '+++%s/%s/%%' % (doy, year))], order='reference')
741+ if seq_ids:
742+ prev_seq = int(self.browse(cr, uid, seq_ids[-1]).reference[12:15])
743+ if prev_seq < 999:
744+ seq = '%03d' % (prev_seq + 1)
745+ else:
746+ raise osv.except_osv(_('Warning!'),
747+ _('The daily maximum of outgoing invoices with an automatically generated BBA Structured Communications has been exceeded!' \
748+ '\nPlease create manually a unique BBA Structured Communication.'))
749+ bbacomm = doy + year + seq
750+ base = int(bbacomm)
751+ mod = base % 97 or 97
752+ reference = '+++%s/%s/%s%02d+++' % (doy, year, seq, mod)
753+ elif algorithm == 'partner_ref':
754+ if not self.check_bbacomm(reference):
755+ partner_ref = partner.ref
756+ partner_ref_nr = re.sub('\D', '', partner_ref or '')
757+ if (len(partner_ref_nr) < 3) or (len(partner_ref_nr) > 7):
758+ raise osv.except_osv(_('Warning!'),
759+ _('The Partner should have a 3-7 digit Reference Number for the generation of BBA Structured Communications!' \
760+ '\nPlease correct the Partner record.'))
761+ else:
762+ partner_ref_nr = partner_ref_nr.ljust(7, '0')
763+ seq = '001'
764+ seq_ids = self.search(cr, uid,
765+ [('type', '=', 'out_invoice'), ('reference_type', '=', 'bba'),
766+ ('reference', 'like', '+++%s/%s/%%' % (partner_ref_nr[:3], partner_ref_nr[3:]))], order='reference')
767+ if seq_ids:
768+ prev_seq = int(self.browse(cr, uid, seq_ids[-1]).reference[12:15])
769+ if prev_seq < 999:
770+ seq = '%03d' % (prev_seq + 1)
771+ else:
772+ raise osv.except_osv(_('Warning!'),
773+ _('The daily maximum of outgoing invoices with an automatically generated BBA Structured Communications has been exceeded!' \
774+ '\nPlease create manually a unique BBA Structured Communication.'))
775+ bbacomm = partner_ref_nr + seq
776+ base = int(bbacomm)
777+ mod = base % 97 or 97
778+ reference = '+++%s/%s/%s%02d+++' % (partner_ref_nr[:3], partner_ref_nr[3:], seq, mod)
779+ elif algorithm == 'random':
780+ if not self.check_bbacomm(reference):
781+ base = random.randint(1, 9999999999)
782+ bbacomm = str(base).rjust(10, '0')
783+ base = int(bbacomm)
784+ mod = base % 97 or 97
785+ mod = str(mod).rjust(2, '0')
786+ reference = '+++%s/%s/%s%s+++' % (bbacomm[:3], bbacomm[3:7], bbacomm[7:], mod)
787+ else:
788+ raise osv.except_osv(_('Error!'),
789+ _("Unsupported Structured Communication Type Algorithm '%s' !" \
790+ "\nPlease contact your OpenERP support channel.") % algorithm)
791+ return {'value': {'reference': reference}}
792+
793+ def refund(self, cr, uid, ids, date=None, period_id=None, description=None, journal_id=None):
794+ """ overwrite of account_invoice refund method to add reference_type field """
795+ invoices = self.read(cr, uid, ids, ['name', 'type', 'number', 'reference_type', 'reference', 'comment', 'date_due', 'partner_id', 'address_contact_id', 'address_invoice_id', 'partner_contact', 'partner_insite', 'partner_ref', 'payment_term', 'account_id', 'currency_id', 'invoice_line', 'tax_line', 'journal_id', 'user_id', 'fiscal_position']) # change by Noviat : add reference_type
796+ obj_invoice_line = self.pool.get('account.invoice.line')
797+ obj_invoice_tax = self.pool.get('account.invoice.tax')
798+ obj_journal = self.pool.get('account.journal')
799+ new_ids = []
800+ for invoice in invoices:
801+ del invoice['id']
802+
803+ type_dict = {
804+ 'out_invoice': 'out_refund', # Customer Invoice
805+ 'in_invoice': 'in_refund', # Supplier Invoice
806+ 'out_refund': 'out_invoice', # Customer Refund
807+ 'in_refund': 'in_invoice', # Supplier Refund
808+ }
809+
810+ invoice_lines = obj_invoice_line.read(cr, uid, invoice['invoice_line'])
811+ invoice_lines = self._refund_cleanup_lines(cr, uid, invoice_lines)
812+
813+ tax_lines = obj_invoice_tax.read(cr, uid, invoice['tax_line'])
814+ tax_lines = filter(lambda l: l['manual'], tax_lines)
815+ tax_lines = self._refund_cleanup_lines(cr, uid, tax_lines)
816+ if journal_id:
817+ refund_journal_ids = [journal_id]
818+ elif invoice['type'] == 'in_invoice':
819+ refund_journal_ids = obj_journal.search(cr, uid, [('type','=','purchase_refund')])
820+ else:
821+ refund_journal_ids = obj_journal.search(cr, uid, [('type','=','sale_refund')])
822+
823+ if not date:
824+ date = time.strftime('%Y-%m-%d')
825+ invoice.update({
826+ 'type': type_dict[invoice['type']],
827+ 'date_invoice': date,
828+ 'state': 'draft',
829+ 'number': False,
830+ 'invoice_line': invoice_lines,
831+ 'tax_line': tax_lines,
832+ 'journal_id': refund_journal_ids
833+ })
834+ if period_id:
835+ invoice.update({
836+ 'period_id': period_id,
837+ })
838+ if description:
839+ invoice.update({
840+ 'name': description,
841+ })
842+ # take the id part of the tuple returned for many2one fields
843+ for field in ('address_contact_id', 'address_invoice_id', 'partner_id',
844+ 'account_id', 'currency_id', 'payment_term', 'journal_id',
845+ 'user_id', 'fiscal_position'):
846+ invoice[field] = invoice[field] and invoice[field][0]
847+ # create the new invoice
848+ new_ids.append(self.create(cr, uid, invoice))
849+
850+ return new_ids
851+
852+ def create(self, cr, uid, vals, context=None):
853+ partner_id = vals.get('partner_id')
854+ if not partner_id:
855+ raise osv.except_osv(_('Warning!'), _('Please fill in the Partner field.'))
856+ partner = self.pool.get('res.partner').browse(cr, uid, partner_id)
857+ if vals.get('type'):
858+ inv_type = vals.get('type')
859+ else:
860+ inv_type = self._get_type(cr, uid, context=context)
861+ vals['type'] = inv_type
862+ reference_type = vals.get('reference_type')
863+ reference = vals.get('reference')
864+ if inv_type == 'out_invoice':
865+ reference_type = reference_type or partner.out_inv_comm_type or 'none'
866+ if not self.check_bbacomm(reference):
867+ reference = self.generate_bbacomm(cr, uid, [], inv_type, reference_type, partner_id, reference)['value']['reference']
868+ elif not reference_type:
869+ reference_type = 'none'
870+
871+ if reference_type == 'bba':
872+ if not reference:
873+ raise osv.except_osv(_('Warning!'),
874+ _('Empty BBA Structured Communication!' \
875+ '\nPlease fill in a BBA Structured Communication.'))
876+ if self.check_bbacomm(reference):
877+ reference = re.sub('\D', '', reference)
878+ reference = '+++' + reference[0:3] + '/' + reference[3:7] + '/' + reference[7:] + '+++'
879+ if inv_type == 'out_invoice':
880+ same_ids = self.search(cr, uid,
881+ [('type', '=', 'out_invoice'), ('state', '!=', 'draft'),
882+ ('reference_type', '=', 'bba'), ('reference', '=', reference)])
883+ if same_ids:
884+ reference_type, reference = self.duplicate_bba(cr, uid, inv_type, reference, partner)
885+ vals.update({'reference_type': reference_type, 'reference': reference})
886+ return super(account_invoice, self).create(cr, uid, vals, context=context)
887+
888+ def write(self, cr, uid, ids, vals, context={}):
889+ if isinstance(ids, (int, long)):
890+ ids = [ids]
891+ for inv in self.browse(cr, uid, ids, context):
892+ if vals.has_key('reference_type'):
893+ reference_type = vals['reference_type']
894+ else:
895+ reference_type = inv.reference_type or ''
896+ if reference_type == 'bba':
897+ if vals.has_key('reference'):
898+ bbacomm = vals['reference']
899+ else:
900+ bbacomm = inv.reference or ''
901+ if self.check_bbacomm(bbacomm):
902+ reference = re.sub('\D', '', bbacomm)
903+ vals['reference'] = reference = '+++' + reference[0:3] + '/' + reference[3:7] + '/' + reference[7:] + '+++'
904+ if inv.type == 'out_invoice':
905+ same_ids = self.search(cr, uid,
906+ [('id', '!=', inv.id), ('type', '=', 'out_invoice'), ('state', '!=', 'draft'),
907+ ('reference_type', '=', 'bba'), ('reference', '=', reference)])
908+ if same_ids:
909+ reference_type, reference = self.duplicate_bba(cr, uid, inv.type, reference, inv.partner_id)
910+ vals.update({'reference_type': reference_type, 'reference': reference})
911+ return super(account_invoice, self).write(cr, uid, ids, vals, context)
912+
913+ _columns = {
914+ 'reference': fields.char('Communication', size=64, help="The partner reference of this invoice."),
915+ 'reference_type': fields.selection(_get_reference_type, 'Communication Type',
916+ required=True),
917+ }
918+
919+ _constraints = [
920+ (_check_communication, 'Invalid BBA Structured Communication !', ['Communication']),
921+ ]
922+
923+account_invoice()
924
925 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
926
927=== modified file 'l10n_be_invoice_bba/partner.py' (properties changed: -x to +x)
928--- l10n_be_invoice_bba/partner.py 2011-12-19 16:54:40 +0000
929+++ l10n_be_invoice_bba/partner.py 2012-10-11 16:56:43 +0000
930@@ -3,20 +3,19 @@
931 #
932 # OpenERP, Open Source Management Solution
933 #
934-# Created by Luc De Meyer
935-# Copyright (c) 2010 Noviat nv/sa (www.noviat.be). All rights reserved.
936+# Copyright (c) 2012 Noviat nv/sa (www.noviat.be). All rights reserved.
937 #
938 # This program is free software: you can redistribute it and/or modify
939-# it under the terms of the GNU General Public License as published by
940-# the Free Software Foundation, either version 3 of the License, or
941-# (at your option) any later version.
942+# it under the terms of the GNU Affero General Public License as
943+# published by the Free Software Foundation, either version 3 of the
944+# License, or (at your option) any later version.
945 #
946 # This program is distributed in the hope that it will be useful,
947 # but WITHOUT ANY WARRANTY; without even the implied warranty of
948 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
949-# GNU General Public License for more details.
950+# GNU Affero General Public License for more details.
951 #
952-# You should have received a copy of the GNU General Public License
953+# You should have received a copy of the GNU Affero General Public License
954 # along with this program. If not, see <http://www.gnu.org/licenses/>.
955 #
956 ##############################################################################
957@@ -24,8 +23,8 @@
958 from osv import fields, osv
959 import time
960 from tools.translate import _
961-import netsvc
962-logger=netsvc.Logger()
963+import logging
964+_logger = logging.getLogger(__name__)
965
966 class res_partner(osv.osv):
967 """ add field to indicate default 'Communication Type' on customer invoices """
968@@ -45,10 +44,6 @@
969 ], 'Communication Algorithm',
970 help='Select Algorithm to generate the Structured Communication on Outgoing Invoices.' ),
971 }
972-
973- _default = {
974- 'out_inv_comm_type': 'none',
975- }
976-res_partner()
977+res_partner()
978
979 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
980
981=== modified file 'l10n_be_invoice_bba/partner_view.xml' (properties changed: -x to +x)
982--- l10n_be_invoice_bba/partner_view.xml 2011-08-12 15:14:50 +0000
983+++ l10n_be_invoice_bba/partner_view.xml 2012-10-11 16:56:43 +0000
984@@ -11,7 +11,7 @@
985 <field name="arch" type="xml">
986 <field name="property_payment_term" position="after">
987 <field name="out_inv_comm_type" groups="base.group_extended"/>
988- <field name="out_inv_comm_algorithm" groups="base.group_extended" attrs="{'invisible':[('out_inv_comm_type','!=','bba')]}"/>
989+ <field name="out_inv_comm_algorithm" groups="base.group_extended" attrs="{'invisible':[('out_inv_comm_type','!=','bba')],'required':[('out_inv_comm_type','=','bba')]}"/>
990 </field>
991 </field>
992 </record>