Merge lp:~camptocamp/account-invoicing/6.1-add-invoice-merge-lep into lp:~account-core-editors/account-invoicing/6.1
- 6.1-add-invoice-merge-lep
- Merge into 6.1
Proposed by
Leonardo Pistone
Status: | Merged |
---|---|
Merged at revision: | 16 |
Proposed branch: | lp:~camptocamp/account-invoicing/6.1-add-invoice-merge-lep |
Merge into: | lp:~account-core-editors/account-invoicing/6.1 |
Diff against target: |
736 lines (+689/-0) 9 files modified
account_invoice_merge/__init__.py (+29/-0) account_invoice_merge/__openerp__.py (+53/-0) account_invoice_merge/i18n/account_invoice_merge.pot (+76/-0) account_invoice_merge/i18n/fr.po (+83/-0) account_invoice_merge/i18n/zh_CN.po (+85/-0) account_invoice_merge/invoice.py (+166/-0) account_invoice_merge/wizard/__init__.py (+27/-0) account_invoice_merge/wizard/invoice_merge.py (+129/-0) account_invoice_merge/wizard/invoice_merge_view.xml (+41/-0) |
To merge this branch: | bzr merge lp:~camptocamp/account-invoicing/6.1-add-invoice-merge-lep |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Joël Grand-Guillaume @ camptocamp | code review, no tests | Approve | |
Yannick Vaucher @ Camptocamp | code review, no tests | Approve | |
Romain Deheele - Camptocamp | Pending | ||
Review via email: mp+197847@code.launchpad.net |
Commit message
[mrg] backport module account_
Description of the change
Backport of account_
Thanks!
To post a comment you must log in.
Revision history for this message
Leonardo Pistone (lepistone) wrote : | # |
Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote : | # |
LGTM
Thanks!
review:
Approve
(code review, no tests)
Revision history for this message
Joël Grand-Guillaume @ camptocamp (jgrandguillaume-c2c) wrote : | # |
Hi,
LGTM, except you may have used full import path using from . import XYZ, but won't block this MP for that.
Thanks,
Joel
review:
Approve
(code review, no tests)
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added directory 'account_invoice_merge' |
2 | === added file 'account_invoice_merge/__init__.py' |
3 | --- account_invoice_merge/__init__.py 1970-01-01 00:00:00 +0000 |
4 | +++ account_invoice_merge/__init__.py 2013-12-05 11:08:21 +0000 |
5 | @@ -0,0 +1,29 @@ |
6 | +# -*- coding: utf-8 -*- |
7 | +############################################################################### |
8 | +# # |
9 | +# Author: Leonardo Pistone <leonardo.pistone@camptocamp.com> # |
10 | +# Copyright 2013 Camptocamp SA # |
11 | +# # |
12 | +# Based on the merge Purchase Order functionality on OpenERP by OpenERP SA # |
13 | +# the account_invoice_merge for 7.0 by Elico Corp, and work by # |
14 | +# Romain Deheele, Camptocamp. # |
15 | +# # |
16 | +# This program is free software: you can redistribute it and/or modify # |
17 | +# it under the terms of the GNU Affero General Public License as # |
18 | +# published by the Free Software Foundation, either version 3 of the # |
19 | +# License, or (at your option) any later version. # |
20 | +# # |
21 | +# This program is distributed in the hope that it will be useful, # |
22 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of # |
23 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # |
24 | +# GNU Affero General Public License for more details. # |
25 | +# # |
26 | +# You should have received a copy of the GNU Affero General Public License # |
27 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. # |
28 | +# # |
29 | +############################################################################### |
30 | + |
31 | +import invoice |
32 | +import wizard |
33 | + |
34 | +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: |
35 | |
36 | === added file 'account_invoice_merge/__openerp__.py' |
37 | --- account_invoice_merge/__openerp__.py 1970-01-01 00:00:00 +0000 |
38 | +++ account_invoice_merge/__openerp__.py 2013-12-05 11:08:21 +0000 |
39 | @@ -0,0 +1,53 @@ |
40 | +# -*- coding: utf-8 -*- |
41 | +############################################################################### |
42 | +# # |
43 | +# Author: Leonardo Pistone <leonardo.pistone@camptocamp.com> # |
44 | +# Copyright 2013 Camptocamp SA # |
45 | +# # |
46 | +# Based on the merge Purchase Order functionality on OpenERP by OpenERP SA # |
47 | +# the account_invoice_merge for 7.0 by Elico Corp, and work by # |
48 | +# Romain Deheele, Camptocamp. # |
49 | +# # |
50 | +# This program is free software: you can redistribute it and/or modify # |
51 | +# it under the terms of the GNU Affero General Public License as # |
52 | +# published by the Free Software Foundation, either version 3 of the # |
53 | +# License, or (at your option) any later version. # |
54 | +# # |
55 | +# This program is distributed in the hope that it will be useful, # |
56 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of # |
57 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # |
58 | +# GNU Affero General Public License for more details. # |
59 | +# # |
60 | +# You should have received a copy of the GNU Affero General Public License # |
61 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. # |
62 | +# # |
63 | +############################################################################### |
64 | + |
65 | +{ |
66 | + 'name': 'Account Invoice Merge Wizard', |
67 | + 'version': '1.2', |
68 | + 'category': 'Finance', |
69 | + 'description': """ |
70 | +This module adds an action in the invoices lists to merge of invoices. Here are |
71 | +the conditions to allow the merge: |
72 | +- Type should be the same (customer Invoice, supplier invoice, Customer or |
73 | + Supplier Refund) |
74 | +- Partner should be the same |
75 | +- Currency should be the same |
76 | +- Account receivable account should be the same |
77 | +No merge is done at invoice line level. |
78 | + """, |
79 | + 'author': 'Camptocamp', |
80 | + 'website': 'http://www.camptocamp.com', |
81 | + 'depends': ['base', 'account'], |
82 | + 'data': [ |
83 | + 'wizard/invoice_merge_view.xml', |
84 | + ], |
85 | + 'test': [ |
86 | + ], |
87 | + 'demo': [], |
88 | + 'installable': True, |
89 | + 'active': False, |
90 | + 'certificate': False, |
91 | +} |
92 | +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: |
93 | |
94 | === added directory 'account_invoice_merge/i18n' |
95 | === added file 'account_invoice_merge/i18n/account_invoice_merge.pot' |
96 | --- account_invoice_merge/i18n/account_invoice_merge.pot 1970-01-01 00:00:00 +0000 |
97 | +++ account_invoice_merge/i18n/account_invoice_merge.pot 2013-12-05 11:08:21 +0000 |
98 | @@ -0,0 +1,76 @@ |
99 | +# Translation of OpenERP Server. |
100 | +# This file contains the translation of the following modules: |
101 | +# * account_invoice_merge |
102 | +# |
103 | +msgid "" |
104 | +msgstr "" |
105 | +"Project-Id-Version: OpenERP Server 6.0.3\n" |
106 | +"Report-Msgid-Bugs-To: support@openerp.com\n" |
107 | +"POT-Creation-Date: 2012-05-07 02:54+0000\n" |
108 | +"PO-Revision-Date: 2012-05-07 02:54+0000\n" |
109 | +"Last-Translator: <>\n" |
110 | +"Language-Team: \n" |
111 | +"MIME-Version: 1.0\n" |
112 | +"Content-Type: text/plain; charset=UTF-8\n" |
113 | +"Content-Transfer-Encoding: \n" |
114 | +"Plural-Forms: \n" |
115 | + |
116 | +#. module: account_invoice_merge |
117 | +#: model:ir.model,name:account_invoice_merge.model_account_invoice |
118 | +msgid "Invoice" |
119 | +msgstr "" |
120 | + |
121 | +#. module: account_invoice_merge |
122 | +#: code:addons/account_invoice_merge/wizard/invoice_merge.py:86 |
123 | +#, python-format |
124 | +msgid "Partner Invoice" |
125 | +msgstr "" |
126 | + |
127 | +#. module: account_invoice_merge |
128 | +#: view:invoice.merge:0 |
129 | +msgid " Please note that: \n" |
130 | +" \n" |
131 | +" Invoices will only be merged if: \n" |
132 | +" * Invoices are in draft \n" |
133 | +" * Invoices belong to the same partner \n" |
134 | +" * Invoices are have same company, partner, address, currency, journal, salesman, account, type \n" |
135 | +" \n" |
136 | +" Lines will only be merged if: \n" |
137 | +" * Invoice lines are exactly the same except for the product,quantity and unit \n" |
138 | +" " |
139 | +msgstr "" |
140 | + |
141 | +#. module: account_invoice_merge |
142 | +#: code:addons/account_invoice_merge/wizard/invoice_merge.py:48 |
143 | +#, python-format |
144 | +msgid "Please select multiple invoice to merge in the list view." |
145 | +msgstr "" |
146 | + |
147 | +#. module: account_invoice_merge |
148 | +#: view:invoice.merge:0 |
149 | +msgid "Merge Invoices" |
150 | +msgstr "" |
151 | + |
152 | +#. module: account_invoice_merge |
153 | +#: code:addons/account_invoice_merge/wizard/invoice_merge.py:47 |
154 | +#, python-format |
155 | +msgid "Warning" |
156 | +msgstr "" |
157 | + |
158 | +#. module: account_invoice_merge |
159 | +#: view:invoice.merge:0 |
160 | +#: model:ir.actions.act_window,name:account_invoice_merge.action_view_invoice_merge |
161 | +#: model:ir.model,name:account_invoice_merge.model_invoice_merge |
162 | +msgid "Merge Partner Invoice" |
163 | +msgstr "" |
164 | + |
165 | +#. module: account_invoice_merge |
166 | +#: view:invoice.merge:0 |
167 | +msgid "Cancel" |
168 | +msgstr "" |
169 | + |
170 | +#. module: account_invoice_merge |
171 | +#: view:invoice.merge:0 |
172 | +msgid "Are you sure you want to merge these invoices ?" |
173 | +msgstr "" |
174 | + |
175 | |
176 | === added file 'account_invoice_merge/i18n/fr.po' |
177 | --- account_invoice_merge/i18n/fr.po 1970-01-01 00:00:00 +0000 |
178 | +++ account_invoice_merge/i18n/fr.po 2013-12-05 11:08:21 +0000 |
179 | @@ -0,0 +1,83 @@ |
180 | +# Translation of OpenERP Server. |
181 | +# This file contains the translation of the following modules: |
182 | +# * account_invoice_merge |
183 | +# |
184 | +msgid "" |
185 | +msgstr "" |
186 | +"Project-Id-Version: OpenERP Server 6.0.3\n" |
187 | +"Report-Msgid-Bugs-To: support@openerp.com\n" |
188 | +"POT-Creation-Date: 2012-05-07 02:54+0000\n" |
189 | +"PO-Revision-Date: 2013-06-23 19:40+0200\n" |
190 | +"Last-Translator: <>\n" |
191 | +"Language-Team: \n" |
192 | +"MIME-Version: 1.0\n" |
193 | +"Content-Type: text/plain; charset=UTF-8\n" |
194 | +"Content-Transfer-Encoding: \n" |
195 | +"Plural-Forms: \n" |
196 | + |
197 | +#. module: account_invoice_merge |
198 | +#: model:ir.model,name:account_invoice_merge.model_account_invoice |
199 | +msgid "Invoice" |
200 | +msgstr "Facture" |
201 | + |
202 | +#. module: account_invoice_merge |
203 | +#: code:addons/account_invoice_merge/wizard/invoice_merge.py:86 |
204 | +#, python-format |
205 | +msgid "Partner Invoice" |
206 | +msgstr "Facture client" |
207 | + |
208 | +#. module: account_invoice_merge |
209 | +#: view:invoice.merge:0 |
210 | +msgid " Please note that: \n" |
211 | +" \n" |
212 | +" Invoices will only be merged if: \n" |
213 | +" * Invoices are in draft \n" |
214 | +" * Invoices belong to the same partner \n" |
215 | +" * Invoices are have same company, partner, address, currency, journal, salesman, account, type \n" |
216 | +" \n" |
217 | +" Lines will only be merged if: \n" |
218 | +" * Invoice lines are exactly the same except for the product,quantity and unit \n" |
219 | +" " |
220 | +msgstr "" |
221 | +"Les factures seront fusionnées uniquement si :\n" |
222 | +"\n" |
223 | +"* elles sont en Brouillon et du même type\n" |
224 | +"* elles ont les mêmes caractéristiques de partenaire, société,\n" |
225 | +" adresse, devise, journal, vendeur, compte. \n" |
226 | +"\n" |
227 | +"Les lignes de factures ne sont pas fusionnées" |
228 | + |
229 | +#. module: account_invoice_merge |
230 | +#: code:addons/account_invoice_merge/wizard/invoice_merge.py:48 |
231 | +#, python-format |
232 | +msgid "Please select multiple invoice to merge in the list view." |
233 | +msgstr "Veuillez choisir plusieurs factures à fusionner dans la vue liste" |
234 | + |
235 | +#. module: account_invoice_merge |
236 | +#: view:invoice.merge:0 |
237 | +msgid "Merge Invoices" |
238 | +msgstr "Fusion de factures" |
239 | + |
240 | +#. module: account_invoice_merge |
241 | +#: code:addons/account_invoice_merge/wizard/invoice_merge.py:47 |
242 | +#, python-format |
243 | +msgid "Warning" |
244 | +msgstr "Avertissement" |
245 | + |
246 | +#. module: account_invoice_merge |
247 | +#: view:invoice.merge:0 |
248 | +#: model:ir.actions.act_window,name:account_invoice_merge.action_view_invoice_merge |
249 | +#: model:ir.model,name:account_invoice_merge.model_invoice_merge |
250 | +msgid "Merge Partner Invoice" |
251 | +msgstr "Fusion de factures" |
252 | + |
253 | +#. module: account_invoice_merge |
254 | +#: view:invoice.merge:0 |
255 | +msgid "Cancel" |
256 | +msgstr "Annuler" |
257 | + |
258 | +#. module: account_invoice_merge |
259 | +#: view:invoice.merge:0 |
260 | +msgid "Are you sure you want to merge these invoices ?" |
261 | +msgstr "Êtes-vous certain de vouloir fusionner ces factures ?" |
262 | + |
263 | |
264 | === added file 'account_invoice_merge/i18n/zh_CN.po' |
265 | --- account_invoice_merge/i18n/zh_CN.po 1970-01-01 00:00:00 +0000 |
266 | +++ account_invoice_merge/i18n/zh_CN.po 2013-12-05 11:08:21 +0000 |
267 | @@ -0,0 +1,85 @@ |
268 | +# Translation of OpenERP Server. |
269 | +# This file contains the translation of the following modules: |
270 | +# * account_invoice_merge |
271 | +# |
272 | +msgid "" |
273 | +msgstr "" |
274 | +"Project-Id-Version: OpenERP Server 6.0.3\n" |
275 | +"Report-Msgid-Bugs-To: support@openerp.com\n" |
276 | +"POT-Creation-Date: 2012-05-07 02:54+0000\n" |
277 | +"PO-Revision-Date: 2012-05-07 02:54+0000\n" |
278 | +"Last-Translator: <>\n" |
279 | +"Language-Team: \n" |
280 | +"MIME-Version: 1.0\n" |
281 | +"Content-Type: text/plain; charset=UTF-8\n" |
282 | +"Content-Transfer-Encoding: \n" |
283 | +"Plural-Forms: \n" |
284 | + |
285 | +#. module: account_invoice_merge |
286 | +#: model:ir.model,name:account_invoice_merge.model_account_invoice |
287 | +msgid "Invoice" |
288 | +msgstr "发票" |
289 | + |
290 | +#. module: account_invoice_merge |
291 | +#: code:addons/account_invoice_merge/wizard/invoice_merge.py:86 |
292 | +#, python-format |
293 | +msgid "Partner Invoice" |
294 | +msgstr "合作伙伴发票" |
295 | + |
296 | +#. module: account_invoice_merge |
297 | +#: view:invoice.merge:0 |
298 | +msgid " Please note that: \n" |
299 | +" \n" |
300 | +" Invoices will only be merged if: \n" |
301 | +" * Invoices are in draft \n" |
302 | +" * Invoices belong to the same partner \n" |
303 | +" * Invoices are have same company, partner, address, currency, journal, salesman, account, type \n" |
304 | +" \n" |
305 | +" Lines will only be merged if: \n" |
306 | +" * Invoice lines are exactly the same except for the product,quantity and unit \n" |
307 | +" " |
308 | +msgstr " 请注意: \n" |
309 | +" \n" |
310 | +"仅符合下列条件的发票,才会被合并: \n" |
311 | +" * 发票确认之前,还在草稿状态。 \n" |
312 | +" * 发票属于同一合作伙伴。 \n" |
313 | +" * 发票属于同一公司,有相同币别,账簿,业务员,科目及类型等。 \n" |
314 | +" \n" |
315 | +" 发票明细仅在符合下列条件才被合并: \n" |
316 | +" * 发票明细除了产品,数量,价格,金额等字段相同才被合并。 \n" |
317 | +" " |
318 | + |
319 | +#. module: account_invoice_merge |
320 | +#: code:addons/account_invoice_merge/wizard/invoice_merge.py:48 |
321 | +#, python-format |
322 | +msgid "Please select multiple invoice to merge in the list view." |
323 | +msgstr "请在列表里选择多个发票来合并。" |
324 | + |
325 | +#. module: account_invoice_merge |
326 | +#: view:invoice.merge:0 |
327 | +msgid "Merge Invoices" |
328 | +msgstr "合并发票" |
329 | + |
330 | +#. module: account_invoice_merge |
331 | +#: code:addons/account_invoice_merge/wizard/invoice_merge.py:47 |
332 | +#, python-format |
333 | +msgid "Warning" |
334 | +msgstr "警告" |
335 | + |
336 | +#. module: account_invoice_merge |
337 | +#: view:invoice.merge:0 |
338 | +#: model:ir.actions.act_window,name:account_invoice_merge.action_view_invoice_merge |
339 | +#: model:ir.model,name:account_invoice_merge.model_invoice_merge |
340 | +msgid "Merge Partner Invoice" |
341 | +msgstr "合并合作伙伴发票" |
342 | + |
343 | +#. module: account_invoice_merge |
344 | +#: view:invoice.merge:0 |
345 | +msgid "Cancel" |
346 | +msgstr "取消" |
347 | + |
348 | +#. module: account_invoice_merge |
349 | +#: view:invoice.merge:0 |
350 | +msgid "Are you sure you want to merge these invoices ?" |
351 | +msgstr "您确认合并这些发票?" |
352 | + |
353 | |
354 | === added file 'account_invoice_merge/invoice.py' |
355 | --- account_invoice_merge/invoice.py 1970-01-01 00:00:00 +0000 |
356 | +++ account_invoice_merge/invoice.py 2013-12-05 11:08:21 +0000 |
357 | @@ -0,0 +1,166 @@ |
358 | +# -*- coding: utf-8 -*- |
359 | +############################################################################### |
360 | +# # |
361 | +# Author: Leonardo Pistone <leonardo.pistone@camptocamp.com> # |
362 | +# Copyright 2013 Camptocamp SA # |
363 | +# # |
364 | +# Based on the merge Purchase Order functionality on OpenERP by OpenERP SA # |
365 | +# the account_invoice_merge for 7.0 by Elico Corp, and work by # |
366 | +# Romain Deheele, Camptocamp. # |
367 | +# # |
368 | +# This program is free software: you can redistribute it and/or modify # |
369 | +# it under the terms of the GNU Affero General Public License as # |
370 | +# published by the Free Software Foundation, either version 3 of the # |
371 | +# License, or (at your option) any later version. # |
372 | +# # |
373 | +# This program is distributed in the hope that it will be useful, # |
374 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of # |
375 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # |
376 | +# GNU Affero General Public License for more details. # |
377 | +# # |
378 | +# You should have received a copy of the GNU Affero General Public License # |
379 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. # |
380 | +# # |
381 | +############################################################################### |
382 | + |
383 | +from openerp.osv import orm |
384 | +from openerp import netsvc |
385 | +from osv.orm import browse_record, browse_null |
386 | + |
387 | + |
388 | +class account_invoice(orm.Model): |
389 | + _inherit = "account.invoice" |
390 | + |
391 | + def _get_first_invoice_fields(self, cr, uid, invoice): |
392 | + return {'origin': '%s' % (invoice.origin or '',), |
393 | + 'partner_id': invoice.partner_id.id, |
394 | + 'address_invoice_id': invoice.address_invoice_id.id, |
395 | + 'journal_id': invoice.journal_id.id, |
396 | + 'user_id': invoice.user_id.id, |
397 | + 'currency_id': invoice.currency_id.id, |
398 | + 'company_id': invoice.company_id.id, |
399 | + 'type': invoice.type, |
400 | + 'account_id': invoice.account_id.id, |
401 | + 'state': 'draft', |
402 | + 'reference': '%s' % (invoice.reference or '',), |
403 | + 'name': '%s' % (invoice.name or '',), |
404 | + 'fiscal_position': invoice.fiscal_position and invoice.fiscal_position.id or False, |
405 | + 'payment_term': invoice.payment_term and invoice.payment_term.id or False, |
406 | + 'period_id': invoice.period_id and invoice.period_id.id or False, |
407 | + 'invoice_line': [], |
408 | + } |
409 | + |
410 | + def _get_invoice_key_cols(self, cr, uid, invoice): |
411 | + return ('partner_id', 'address_invoice_id', |
412 | + 'user_id', 'type', |
413 | + 'account_id', 'currency_id', |
414 | + 'journal_id', 'company_id') |
415 | + |
416 | + def _get_invoice_line_key_cols(self, cr, uid, invoice_line): |
417 | + return ('name', 'origin', 'discount', |
418 | + 'invoice_line_tax_id', 'price_unit', |
419 | + 'product_id', 'account_id', 'quantity', |
420 | + 'account_analytic_id') |
421 | + |
422 | + def do_merge(self, cr, uid, ids, context=None): |
423 | + """ |
424 | + To merge similar type of account invoices. |
425 | + Invoices will only be merged if: |
426 | + * Account invoices are in draft |
427 | + * Account invoices belong to the same partner |
428 | + * Account invoices are have same company, partner, currency, journal, |
429 | + currency, salesman, account, type |
430 | + Lines will only be merged if: |
431 | + * Invoice lines are exactly the same except for the quantity and unit |
432 | + |
433 | + @param self: The object pointer. |
434 | + @param cr: A database cursor |
435 | + @param uid: ID of the user currently logged in |
436 | + @param ids: the ID or list of IDs |
437 | + @param context: A standard dictionary |
438 | + |
439 | + @return: new account invoice id |
440 | + |
441 | + """ |
442 | + wf_service = netsvc.LocalService("workflow") |
443 | + |
444 | + def make_key(br, fields): |
445 | + list_key = [] |
446 | + for field in fields: |
447 | + field_val = getattr(br, field) |
448 | + if field in ('product_id', 'account_id'): |
449 | + if not field_val: |
450 | + field_val = False |
451 | + if isinstance(field_val, browse_record): |
452 | + field_val = field_val.id |
453 | + elif isinstance(field_val, browse_null): |
454 | + field_val = False |
455 | + elif isinstance(field_val, list): |
456 | + field_val = ((6, 0, tuple([v.id for v in field_val])),) |
457 | + list_key.append((field, field_val)) |
458 | + list_key.sort() |
459 | + return tuple(list_key) |
460 | + |
461 | + # compute what the new invoices should contain |
462 | + new_invoices = {} |
463 | + draft_invoices = [ |
464 | + invoice |
465 | + for invoice in self.browse(cr, uid, ids, context=context) |
466 | + if invoice.state == 'draft' |
467 | + ] |
468 | + seen_origins = {} |
469 | + seen_client_refs = {} |
470 | + for invoice in draft_invoices: |
471 | + invoice_key = make_key( |
472 | + invoice, self._get_invoice_key_cols(cr, uid, invoice) |
473 | + ) |
474 | + new_invoice = new_invoices.setdefault(invoice_key, ({}, [])) |
475 | + origins = seen_origins.setdefault(invoice_key, set()) |
476 | + client_refs = seen_client_refs.setdefault(invoice_key, set()) |
477 | + new_invoice[1].append(invoice.id) |
478 | + invoice_infos = new_invoice[0] |
479 | + if not invoice_infos: |
480 | + invoice_infos.update( |
481 | + self._get_first_invoice_fields(cr, uid, invoice) |
482 | + ) |
483 | + origins.add(invoice.origin) |
484 | + client_refs.add(invoice.reference) |
485 | + else: |
486 | + if invoice.name: |
487 | + invoice_infos['name'] = (invoice_infos['name'] or '') + (' %s' % (invoice.name,)) |
488 | + if invoice.origin and invoice.origin not in origins: |
489 | + invoice_infos['origin'] = (invoice_infos['origin'] or '') + ' ' + invoice.origin |
490 | + origins.add(invoice.origin) |
491 | + if invoice.reference and invoice.reference not in client_refs: |
492 | + invoice_infos['reference'] = (invoice_infos['reference'] or '') + (' %s' % (invoice.reference,)) |
493 | + client_refs.add(invoice.reference) |
494 | + for inv_line in invoice.invoice_line: |
495 | + line_key = make_key(inv_line, self._get_invoice_line_key_cols(cr, uid, inv_line)) |
496 | + line_key = list(line_key) |
497 | + if inv_line.uos_id: |
498 | + line_key.append(('uos_id', inv_line.uos_id.id)) |
499 | + if invoice.origin: |
500 | + line_key.append(('origin', invoice.origin)) |
501 | + invoice_infos['invoice_line'].append((0, 0, dict(line_key))) |
502 | + |
503 | + allinvoices = [] |
504 | + invoices_info = {} |
505 | + for invoice_key, (invoice_data, old_ids) in new_invoices.iteritems(): |
506 | + # skip merges with only one invoice |
507 | + if len(old_ids) < 2: |
508 | + allinvoices += (old_ids or []) |
509 | + continue |
510 | + |
511 | + # create the new invoice |
512 | + newinvoice_id = self.create(cr, uid, invoice_data) |
513 | + invoices_info.update({newinvoice_id: old_ids}) |
514 | + allinvoices.append(newinvoice_id) |
515 | + |
516 | + # make triggers pointing to the old invoices point to the new invoice |
517 | + for old_id in old_ids: |
518 | + wf_service.trg_redirect(uid, 'account.invoice', old_id, newinvoice_id, cr) |
519 | + wf_service.trg_validate(uid, 'account.invoice', old_id, 'invoice_cancel', cr) |
520 | + |
521 | + return invoices_info |
522 | + |
523 | +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: |
524 | |
525 | === added directory 'account_invoice_merge/wizard' |
526 | === added file 'account_invoice_merge/wizard/__init__.py' |
527 | --- account_invoice_merge/wizard/__init__.py 1970-01-01 00:00:00 +0000 |
528 | +++ account_invoice_merge/wizard/__init__.py 2013-12-05 11:08:21 +0000 |
529 | @@ -0,0 +1,27 @@ |
530 | +# -*- coding: utf-8 -*- |
531 | +############################################################################### |
532 | +# # |
533 | +# Author: Leonardo Pistone <leonardo.pistone@camptocamp.com> # |
534 | +# Copyright 2013 Camptocamp SA # |
535 | +# # |
536 | +# Based on the merge Purchase Order functionality on OpenERP by OpenERP SA # |
537 | +# the account_invoice_merge for 7.0 by Elico Corp, and work by # |
538 | +# Romain Deheele, Camptocamp. # |
539 | +# # |
540 | +# This program is free software: you can redistribute it and/or modify # |
541 | +# it under the terms of the GNU Affero General Public License as # |
542 | +# published by the Free Software Foundation, either version 3 of the # |
543 | +# License, or (at your option) any later version. # |
544 | +# # |
545 | +# This program is distributed in the hope that it will be useful, # |
546 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of # |
547 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # |
548 | +# GNU Affero General Public License for more details. # |
549 | +# # |
550 | +# You should have received a copy of the GNU Affero General Public License # |
551 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. # |
552 | +# # |
553 | +############################################################################### |
554 | + |
555 | +import invoice_merge |
556 | +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: |
557 | |
558 | === added file 'account_invoice_merge/wizard/invoice_merge.py' |
559 | --- account_invoice_merge/wizard/invoice_merge.py 1970-01-01 00:00:00 +0000 |
560 | +++ account_invoice_merge/wizard/invoice_merge.py 2013-12-05 11:08:21 +0000 |
561 | @@ -0,0 +1,129 @@ |
562 | +# -*- coding: utf-8 -*- |
563 | +############################################################################### |
564 | +# # |
565 | +# Author: Leonardo Pistone <leonardo.pistone@camptocamp.com> # |
566 | +# Copyright 2013 Camptocamp SA # |
567 | +# # |
568 | +# Based on the merge Purchase Order functionality on OpenERP by OpenERP SA # |
569 | +# the account_invoice_merge for 7.0 by Elico Corp, and work by # |
570 | +# Romain Deheele, Camptocamp. # |
571 | +# # |
572 | +# This program is free software: you can redistribute it and/or modify # |
573 | +# it under the terms of the GNU Affero General Public License as # |
574 | +# published by the Free Software Foundation, either version 3 of the # |
575 | +# License, or (at your option) any later version. # |
576 | +# # |
577 | +# This program is distributed in the hope that it will be useful, # |
578 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of # |
579 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # |
580 | +# GNU Affero General Public License for more details. # |
581 | +# # |
582 | +# You should have received a copy of the GNU Affero General Public License # |
583 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. # |
584 | +# # |
585 | +############################################################################### |
586 | + |
587 | +from openerp.osv import osv, orm |
588 | +from openerp.tools.translate import _ |
589 | + |
590 | + |
591 | +class invoice_merge(orm.TransientModel): |
592 | + _name = "invoice.merge" |
593 | + _description = "Merge Partner Invoice" |
594 | + |
595 | + def fields_view_get(self, cr, uid, view_id=None, view_type='form', |
596 | + context=None, toolbar=False, submenu=False): |
597 | + """Changes the view dynamically |
598 | + |
599 | + @param self: The object pointer. |
600 | + @param cr: A database cursor |
601 | + @param uid: ID of the user currently logged in |
602 | + @param context: A standard dictionary |
603 | + |
604 | + @return: New arch of view. |
605 | + |
606 | + """ |
607 | + if context is None: |
608 | + context = {} |
609 | + res = super(invoice_merge, self).fields_view_get( |
610 | + cr, uid, view_id=view_id, view_type=view_type, context=context, |
611 | + toolbar=toolbar, submenu=False) |
612 | + |
613 | + if ( |
614 | + context.get('active_model') == 'account.invoice' |
615 | + and len(context['active_ids']) < 2 |
616 | + ): |
617 | + raise osv.except_osv( |
618 | + _('Warning'), |
619 | + _('Please select multiple invoice to merge in the list view.') |
620 | + ) |
621 | + return res |
622 | + |
623 | + def merge_invoices(self, cr, uid, _ids, context=None): |
624 | + """To merge similar type of account invoices. |
625 | + |
626 | + @param self: The object pointer. |
627 | + @param cr: A database cursor |
628 | + @param uid: ID of the user currently logged in |
629 | + @param ids: the ID or list of IDs |
630 | + @param context: A standard dictionary |
631 | + |
632 | + @return: account invoice view |
633 | + |
634 | + """ |
635 | + invoice_obj = self.pool.get('account.invoice') |
636 | + mod_obj = self.pool.get('ir.model.data') |
637 | + # None if sale is not installed |
638 | + so_obj = self.pool.get('sale.order') |
639 | + # None if purchase is not installed |
640 | + po_obj = self.pool.get('purchase.order') |
641 | + |
642 | + if context is None: |
643 | + context = {} |
644 | + try: |
645 | + search_view_id = mod_obj.get_object( |
646 | + cr, uid, 'account', 'view_account_invoice_filter' |
647 | + ).id |
648 | + except ValueError: |
649 | + search_view_id = False |
650 | + allinvoices = invoice_obj.do_merge( |
651 | + cr, uid, context.get('active_ids', []), context) |
652 | + |
653 | + for new_invoice in allinvoices: |
654 | + if so_obj is not None: |
655 | + todo_ids = so_obj.search(cr, uid, [ |
656 | + ('invoice_ids', 'in', allinvoices[new_invoice]) |
657 | + ], context=context) |
658 | + for org_invoice in so_obj.browse( |
659 | + cr, uid, todo_ids, context=context |
660 | + ): |
661 | + so_obj.write(cr, uid, [org_invoice.id], { |
662 | + 'invoice_ids': [(4, new_invoice)] |
663 | + }, context) |
664 | + if po_obj is not None: |
665 | + todo_ids = po_obj.search(cr, uid, [ |
666 | + ('invoice_ids', 'in', allinvoices[new_invoice]) |
667 | + ], context=context) |
668 | + for org_invoice in po_obj.browse( |
669 | + cr, uid, todo_ids, context=context |
670 | + ): |
671 | + po_obj.write(cr, uid, [org_invoice.id], { |
672 | + 'invoice_ids': [(4, new_invoice)] |
673 | + }, context) |
674 | + |
675 | + return { |
676 | + 'domain': "[('id', 'in', [%s])]" % ','.join( |
677 | + str(inv_id) for inv_id in allinvoices |
678 | + ), |
679 | + 'name': _('Partner Invoice'), |
680 | + 'view_type': 'form', |
681 | + 'view_mode': 'tree,form', |
682 | + 'res_model': 'account.invoice', |
683 | + #'view_id': [view_id], |
684 | + 'view_id': False, |
685 | + 'type': 'ir.actions.act_window', |
686 | + 'search_view_id': search_view_id, |
687 | + #'target': 'current', |
688 | + } |
689 | + |
690 | +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: |
691 | |
692 | === added file 'account_invoice_merge/wizard/invoice_merge_view.xml' |
693 | --- account_invoice_merge/wizard/invoice_merge_view.xml 1970-01-01 00:00:00 +0000 |
694 | +++ account_invoice_merge/wizard/invoice_merge_view.xml 2013-12-05 11:08:21 +0000 |
695 | @@ -0,0 +1,41 @@ |
696 | +<?xml version="1.0" encoding="utf-8"?> |
697 | +<openerp> |
698 | + <data> |
699 | + <record id="view_invoice_merge" model="ir.ui.view"> |
700 | + <field name="name">Merger Partner Invoice</field> |
701 | + <field name="model">invoice.merge</field> |
702 | + <field name="type">form</field> |
703 | + <field name="arch" type="xml"> |
704 | + <form string="Merge Partner Invoice"> |
705 | + <separator string="Are you sure you want to merge these invoices ?" colspan="4"/> |
706 | + <newline/> |
707 | + <label string=" |
708 | +Please note that: |
709 | +Invoices will only be merged if: |
710 | +* Invoices are in draft |
711 | +* Invoices belong to the same partner |
712 | +* Invoices are have same company, partner, address, currency, journal, salesman, account, type |
713 | +Lines will only be merged if: |
714 | +* Invoice lines are exactly the same except for the product,quantity and unit |
715 | +" colspan="4"/> |
716 | + <newline/> |
717 | + <separator string="" colspan="4" /> |
718 | + <button special="cancel" string="Cancel" icon="gtk-cancel"/> |
719 | + <button name="merge_invoices" string="Merge Invoices" type="object" icon="gtk-convert"/> |
720 | + </form> |
721 | + </field> |
722 | + </record> |
723 | + |
724 | + <act_window name="Merge Partner Invoice" |
725 | + res_model="invoice.merge" |
726 | + src_model="account.invoice" |
727 | + view_mode="form" |
728 | + target="new" |
729 | + multi="True" |
730 | + key2="client_action_multi" |
731 | + groups="account.group_account_invoice" |
732 | + id="action_view_invoice_merge"/> |
733 | + |
734 | + </data> |
735 | +</openerp> |
736 | + |
Apparently many people worked on ancestors of that, including Panos Christeas and Laetitia Gangloff.
I didn't follow the discussion on that module at the time, so please speak out if you feel like.
Thanks