Merge lp:~zhenit/openobject-addons/zs-extra-6.1 into lp:openobject-addons/extra-trunk

Proposed by mikel
Status: Needs review
Proposed branch: lp:~zhenit/openobject-addons/zs-extra-6.1
Merge into: lp:openobject-addons/extra-trunk
Diff against target: 534 lines (+479/-0) (has conflicts)
10 files modified
.bzrignore (+4/-0)
account_invoice_merge/__init__.py (+20/-0)
account_invoice_merge/__openerp__.py (+35/-0)
account_invoice_merge/i18n/account_invoice_merge.pot (+92/-0)
account_invoice_merge/i18n/es.po (+92/-0)
account_invoice_merge/invoice.py (+100/-0)
account_invoice_merge/invoice_merge.xml (+12/-0)
account_invoice_merge/wizard/__init__.py (+19/-0)
account_invoice_merge/wizard/invoice_merge.py (+70/-0)
account_invoice_merge/wizard/invoice_merge_view.xml (+35/-0)
Conflict adding file .bzrignore.  Moved existing file to .bzrignore.moved.
To merge this branch: bzr merge lp:~zhenit/openobject-addons/zs-extra-6.1
Reviewer Review Type Date Requested Status
OpenERP Committers Pending
Review via email: mp+120263@code.launchpad.net

Description of the change

[add]
account_invoice_merge for 6.1

Allows mergins draft invoices froms the same partner. You can also merge in/out refund invoices with in/out invoices

To post a comment you must log in.
2. By mikel <mikel@pcl2>

[add] i18n

3. By mikel <mikel@pcl2>

[merge] i18n

4. By mikel <mikel@pcl2>

[add] Merge name,comment,origin

Unmerged revisions

4. By mikel <mikel@pcl2>

[add] Merge name,comment,origin

3. By mikel <mikel@pcl2>

[merge] i18n

2. By mikel <mikel@pcl2>

[add] i18n

1. By mikel <mikel@pcl2>

[add] Module account_invoice_merge

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file '.bzrignore'
2--- .bzrignore 1970-01-01 00:00:00 +0000
3+++ .bzrignore 2012-08-19 18:29:22 +0000
4@@ -0,0 +1,4 @@
5+*.pyc
6+*~
7+*swp
8+*bak
9
10=== renamed file '.bzrignore' => '.bzrignore.moved'
11=== added directory 'account_invoice_merge'
12=== added file 'account_invoice_merge/__init__.py'
13--- account_invoice_merge/__init__.py 1970-01-01 00:00:00 +0000
14+++ account_invoice_merge/__init__.py 2012-08-19 18:29:22 +0000
15@@ -0,0 +1,20 @@
16+# -*- encoding: utf-8 -*-
17+#################################################################################
18+# Autor: Mikel Martin (mikel@zhenit.com)
19+# Copyright (C) 2012 ZhenIT Software (<http://ZhenIT.com>). All Rights Reserved
20+#
21+# This program is free software: you can redistribute it and/or modify
22+# it under the terms of the GNU General Public License as published by
23+# the Free Software Foundation, either version 3 of the License, or
24+# (at your option) any later version.
25+#
26+# This program is distributed in the hope that it will be useful,
27+# but WITHOUT ANY WARRANTY; without even the implied warranty of
28+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29+# GNU General Public License for more details.
30+#
31+# You should have received a copy of the GNU General Public License
32+# along with this program. If not, see <http://www.gnu.org/licenses/>.
33+#################################################################################
34+import wizard
35+import invoice
36
37=== added file 'account_invoice_merge/__openerp__.py'
38--- account_invoice_merge/__openerp__.py 1970-01-01 00:00:00 +0000
39+++ account_invoice_merge/__openerp__.py 2012-08-19 18:29:22 +0000
40@@ -0,0 +1,35 @@
41+# -*- encoding: utf-8 -*-
42+#################################################################################
43+# Autor: Mikel Martin (mikel@zhenit.com)
44+# Copyright (C) 2012 ZhenIT Software (<http://ZhenIT.com>). All Rights Reserved
45+#
46+# This program is free software: you can redistribute it and/or modify
47+# it under the terms of the GNU General Public License as published by
48+# the Free Software Foundation, either version 3 of the License, or
49+# (at your option) any later version.
50+#
51+# This program is distributed in the hope that it will be useful,
52+# but WITHOUT ANY WARRANTY; without even the implied warranty of
53+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
54+# GNU General Public License for more details.
55+#
56+# You should have received a copy of the GNU General Public License
57+# along with this program. If not, see <http://www.gnu.org/licenses/>.
58+#################################################################################
59+{
60+ 'name': 'Invoice Merge',
61+ 'version': '1.0',
62+ 'category': 'Accounting Modules',
63+ 'description': """
64+ Merge draft invoices from the same partner
65+ """,
66+ 'author': 'Mikel Martin (http://ZhenIT.com)',
67+ 'depends': ['base','account'],
68+ 'init_xml': [],
69+ 'update_xml': [
70+ "wizard/invoice_merge_view.xml",
71+ "invoice_merge.xml",
72+ ],
73+ 'installable': True,
74+ 'active': False,
75+}
76
77=== added directory 'account_invoice_merge/i18n'
78=== added file 'account_invoice_merge/i18n/account_invoice_merge.pot'
79--- account_invoice_merge/i18n/account_invoice_merge.pot 1970-01-01 00:00:00 +0000
80+++ account_invoice_merge/i18n/account_invoice_merge.pot 2012-08-19 18:29:22 +0000
81@@ -0,0 +1,92 @@
82+# Translation of OpenERP Server.
83+# This file contains the translation of the following modules:
84+# * account_invoice_merge
85+#
86+msgid ""
87+msgstr ""
88+"Project-Id-Version: OpenERP Server 6.1\n"
89+"Report-Msgid-Bugs-To: \n"
90+"POT-Creation-Date: 2012-08-18 18:16+0000\n"
91+"PO-Revision-Date: 2012-08-18 18:16+0000\n"
92+"Last-Translator: Mikel Martin <mikel@zhenit.com>\n"
93+"Language-Team: \n"
94+"MIME-Version: 1.0\n"
95+"Content-Type: text/plain; charset=UTF-8\n"
96+"Content-Transfer-Encoding: \n"
97+"Plural-Forms: \n"
98+
99+#. module: account_invoice_merge
100+#: view:invoice.merge:0
101+msgid "_Merge invoces"
102+msgstr ""
103+
104+#. module: account_invoice_merge
105+#: code:addons/account_invoice_merge/invoice.py:44
106+#, python-format
107+msgid "You can merge only invoices in draft state."
108+msgstr ""
109+
110+#. module: account_invoice_merge
111+#: sql_constraint:account.invoice:0
112+msgid "Invoice Number must be unique per Company!"
113+msgstr ""
114+
115+#. module: account_invoice_merge
116+#: view:invoice.merge:0
117+msgid "Facturas"
118+msgstr ""
119+
120+#. module: account_invoice_merge
121+#: view:invoice.merge:0
122+msgid "_Cancel"
123+msgstr ""
124+
125+#. module: account_invoice_merge
126+#: field:invoice.merge,invoices:0
127+msgid "Invoices"
128+msgstr ""
129+
130+#. module: account_invoice_merge
131+#: model:ir.model,name:account_invoice_merge.model_account_invoice_line
132+msgid "Invoice Line"
133+msgstr ""
134+
135+#. module: account_invoice_merge
136+#: model:ir.model,name:account_invoice_merge.model_invoice_merge
137+msgid "Use this wizard to merge draft invoices from the same partner"
138+msgstr ""
139+
140+#. module: account_invoice_merge
141+#: code:addons/account_invoice_merge/invoice.py:41
142+#, python-format
143+msgid "Can not merge invoice(s) on different partners or states !."
144+msgstr ""
145+
146+#. module: account_invoice_merge
147+#: code:addons/account_invoice_merge/invoice.py:41
148+#, python-format
149+msgid "Partners don't match!"
150+msgstr ""
151+
152+#. module: account_invoice_merge
153+#: model:ir.actions.act_window,name:account_invoice_merge.action_invoice_merge
154+#: model:ir.actions.act_window,name:account_invoice_merge.product_margin_act_window
155+msgid "Merge invoices"
156+msgstr ""
157+
158+#. module: account_invoice_merge
159+#: view:invoice.merge:0
160+msgid "Search Invoices"
161+msgstr ""
162+
163+#. module: account_invoice_merge
164+#: model:ir.model,name:account_invoice_merge.model_account_invoice
165+msgid "Invoice"
166+msgstr ""
167+
168+#. module: account_invoice_merge
169+#: code:addons/account_invoice_merge/invoice.py:44
170+#, python-format
171+msgid "Invalid action !"
172+msgstr ""
173+
174
175=== added file 'account_invoice_merge/i18n/es.po'
176--- account_invoice_merge/i18n/es.po 1970-01-01 00:00:00 +0000
177+++ account_invoice_merge/i18n/es.po 2012-08-19 18:29:22 +0000
178@@ -0,0 +1,92 @@
179+# Translation of OpenERP Server.
180+# This file contains the translation of the following modules:
181+# * account_invoice_merge
182+#
183+msgid ""
184+msgstr ""
185+"Project-Id-Version: OpenERP Server 6.1\n"
186+"Report-Msgid-Bugs-To: \n"
187+"POT-Creation-Date: 2012-08-18 18:16+0000\n"
188+"PO-Revision-Date: 2012-08-18 18:16+0000\n"
189+"Last-Translator: <>\n"
190+"Language-Team: \n"
191+"MIME-Version: 1.0\n"
192+"Content-Type: text/plain; charset=UTF-8\n"
193+"Content-Transfer-Encoding: \n"
194+"Plural-Forms: \n"
195+
196+#. module: account_invoice_merge
197+#: view:invoice.merge:0
198+msgid "_Merge invoces"
199+msgstr "_Fusionar facturas"
200+
201+#. module: account_invoice_merge
202+#: code:addons/account_invoice_merge/invoice.py:44
203+#, python-format
204+msgid "You can merge only invoices in draft state."
205+msgstr "Sólo se pueden fusionar facturas en borrador."
206+
207+#. module: account_invoice_merge
208+#: sql_constraint:account.invoice:0
209+msgid "Invoice Number must be unique per Company!"
210+msgstr "¡El número de factura debe ser único por empresa!"
211+
212+#. module: account_invoice_merge
213+#: view:invoice.merge:0
214+msgid "Facturas"
215+msgstr "Facturas"
216+
217+#. module: account_invoice_merge
218+#: view:invoice.merge:0
219+msgid "_Cancel"
220+msgstr "_Cancelar"
221+
222+#. module: account_invoice_merge
223+#: field:invoice.merge,invoices:0
224+msgid "Invoices"
225+msgstr "Facturas"
226+
227+#. module: account_invoice_merge
228+#: model:ir.model,name:account_invoice_merge.model_account_invoice_line
229+msgid "Invoice Line"
230+msgstr "Línea de factura"
231+
232+#. module: account_invoice_merge
233+#: model:ir.model,name:account_invoice_merge.model_invoice_merge
234+msgid "Use this wizard to merge draft invoices from the same partner"
235+msgstr "Use este asistente para fusionar facturas de la misma empresa"
236+
237+#. module: account_invoice_merge
238+#: code:addons/account_invoice_merge/invoice.py:41
239+#, python-format
240+msgid "Can not merge invoice(s) on different partners or states !."
241+msgstr "¡ No es posible fusionar facturas de diferentes empresas o estados!."
242+
243+#. module: account_invoice_merge
244+#: code:addons/account_invoice_merge/invoice.py:41
245+#, python-format
246+msgid "Partners don't match!"
247+msgstr "¡Las empresas no coinciden!"
248+
249+#. module: account_invoice_merge
250+#: model:ir.actions.act_window,name:account_invoice_merge.action_invoice_merge
251+#: model:ir.actions.act_window,name:account_invoice_merge.product_margin_act_window
252+msgid "Merge invoices"
253+msgstr "Fusionar facturas"
254+
255+#. module: account_invoice_merge
256+#: view:invoice.merge:0
257+msgid "Search Invoices"
258+msgstr "Buscar facturas"
259+
260+#. module: account_invoice_merge
261+#: model:ir.model,name:account_invoice_merge.model_account_invoice
262+msgid "Invoice"
263+msgstr "Factura"
264+
265+#. module: account_invoice_merge
266+#: code:addons/account_invoice_merge/invoice.py:44
267+#, python-format
268+msgid "Invalid action !"
269+msgstr "¡ Acción inválida !"
270+
271
272=== added file 'account_invoice_merge/invoice.py'
273--- account_invoice_merge/invoice.py 1970-01-01 00:00:00 +0000
274+++ account_invoice_merge/invoice.py 2012-08-19 18:29:22 +0000
275@@ -0,0 +1,100 @@
276+# -*- coding: utf-8 -*-
277+
278+#################################################################################
279+# Autor: Mikel Martin (mikel@zhenit.com)
280+# Copyright (C) 2012 ZhenIT Software (<http://ZhenIT.com>). All Rights Reserved
281+# $Id$
282+#
283+# This program is free software: you can redistribute it and/or modify
284+# it under the terms of the GNU General Public License as published by
285+# the Free Software Foundation, either version 3 of the License, or
286+# (at your option) any later version.
287+#
288+# This program is distributed in the hope that it will be useful,
289+# but WITHOUT ANY WARRANTY; without even the implied warranty of
290+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
291+# GNU General Public License for more details.
292+#
293+# You should have received a copy of the GNU General Public License
294+# along with this program. If not, see <http://www.gnu.org/licenses/>.
295+#
296+##############################################################################
297+
298+from osv import fields, osv
299+from tools.translate import _
300+
301+
302+class account_invoice(osv.osv):
303+ _inherit = "account.invoice"
304+
305+ def merge_invoice(self, cr, uid, invoices, context=None):
306+ """ Merge draft invoices. Work only with same partner.
307+ You can merge invoices and refund invoices with echa other.
308+ Moves all lines on the first invoice.
309+ """
310+
311+ if len(invoices) <= 1:
312+ return False
313+ parent = self.pool.get('account.invoice').browse(cr,uid,context['active_id'])
314+ for inv in invoices :
315+ if parent.partner_id != inv.partner_id :
316+ raise osv.except_osv(_("Partners don't match!"),_("Can not merge invoice(s) on different partners or states !."))
317+
318+ if inv.state != 'draft' :
319+ raise osv.except_osv(_("Invalid action !"),_("You can merge only invoices in draft state."))
320+
321+ # Merge invoices that are in draft state
322+ inv_line_obj = self.pool.get('account.invoice.line')
323+ name = parent.name
324+ comment = parent.comment
325+ origin = parent.origin
326+ for inv in invoices:
327+ if inv.id == parent.id:
328+ continue
329+
330+ # check if a line with the same product already exist. if so add quantity. else hang up invoice line to first invoice head.
331+ if inv.name:
332+ name += ', %s' % inv.name
333+ if inv.comment:
334+ comment += ', %s' % inv.comment
335+ if inv.origin:
336+ origin += ', %s' % inv.origin
337+ line_ids = inv_line_obj.search(cr, uid, [('invoice_id','=',inv.id)])
338+ for inv_lin in inv_line_obj.browse(cr, uid, line_ids):
339+ mrg_pdt_ids = inv_line_obj.search(cr, uid, [('invoice_id','=',parent.id),('product_id','=',inv_lin.product_id.id)])
340+ if len(mrg_pdt_ids) == 1 and inv.type == parent.type: # product found --> add quantity
341+ inv_line_obj.write(cr, uid, mrg_pdt_ids, {'quantity': inv_line_obj._can_merge_quantity(cr, uid, mrg_pdt_ids[0], inv_lin.id)})
342+ inv_line_obj.unlink(cr, uid, inv_lin.id)
343+ elif inv.type == parent.type:
344+ inv_line_obj.write(cr, uid, inv_lin.id, {'invoice_id': parent.id})
345+ else:
346+ inv_line_obj.write(cr, uid, inv_lin.id, {'invoice_id': parent.id,'quantity':-inv_lin.quantity})
347+
348+ self.write(cr, uid, parent.id,{'origin':origin,'name':name,'comment':comment})
349+ self.unlink(cr, uid, [inv.id])
350+
351+ self.button_reset_taxes(cr, uid, [parent.id])
352+ return parent.id
353+
354+account_invoice()
355+
356+
357+class account_invoice_line(osv.osv):
358+ _inherit = "account.invoice.line"
359+
360+ def _can_merge_quantity(self, cr, uid, id1, id2, context=None):
361+ qty = False
362+ invl1 = self.browse(cr, uid, id1)
363+ invl2 = self.browse(cr, uid, id2)
364+
365+ if invl1.product_id.id == invl2.product_id.id \
366+ and invl1.price_unit == invl2.price_unit \
367+ and invl1.uos_id.id == invl2.uos_id.id \
368+ and invl1.account_id.id == invl2.account_id.id \
369+ and invl1.discount == invl2.discount:
370+ qty = invl1.quantity + invl2.quantity
371+ return qty
372+
373+account_invoice_line()
374+
375+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
376\ No newline at end of file
377
378=== added file 'account_invoice_merge/invoice_merge.xml'
379--- account_invoice_merge/invoice_merge.xml 1970-01-01 00:00:00 +0000
380+++ account_invoice_merge/invoice_merge.xml 2012-08-19 18:29:22 +0000
381@@ -0,0 +1,12 @@
382+<?xml version="1.0" encoding="utf-8"?>
383+<openerp>
384+ <data>
385+ <act_window name="Merge invoices"
386+ res_model="invoice.merge"
387+ src_model="account.invoice"
388+ view_mode="form"
389+ target="new"
390+ key2="client_action_multi"
391+ id="product_margin_act_window"/>
392+ </data>
393+</openerp>
394\ No newline at end of file
395
396=== added directory 'account_invoice_merge/wizard'
397=== added file 'account_invoice_merge/wizard/__init__.py'
398--- account_invoice_merge/wizard/__init__.py 1970-01-01 00:00:00 +0000
399+++ account_invoice_merge/wizard/__init__.py 2012-08-19 18:29:22 +0000
400@@ -0,0 +1,19 @@
401+# -*- encoding: utf-8 -*-
402+#################################################################################
403+# Autor: Mikel Martin (mikel@zhenit.com)
404+# Copyright (C) 2012 ZhenIT Software (<http://ZhenIT.com>). All Rights Reserved
405+#
406+# This program is free software: you can redistribute it and/or modify
407+# it under the terms of the GNU General Public License as published by
408+# the Free Software Foundation, either version 3 of the License, or
409+# (at your option) any later version.
410+#
411+# This program is distributed in the hope that it will be useful,
412+# but WITHOUT ANY WARRANTY; without even the implied warranty of
413+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
414+# GNU General Public License for more details.
415+#
416+# You should have received a copy of the GNU General Public License
417+# along with this program. If not, see <http://www.gnu.org/licenses/>.
418+#################################################################################
419+import invoice_merge
420
421=== added file 'account_invoice_merge/wizard/invoice_merge.py'
422--- account_invoice_merge/wizard/invoice_merge.py 1970-01-01 00:00:00 +0000
423+++ account_invoice_merge/wizard/invoice_merge.py 2012-08-19 18:29:22 +0000
424@@ -0,0 +1,70 @@
425+# -*- coding: utf-8 -*-
426+
427+#################################################################################
428+# Autor: Mikel Martin (mikel@zhenit.com)
429+# Copyright (C) 2012 ZhenIT Software (<http://ZhenIT.com>). All Rights Reserved
430+# $Id$
431+#
432+# This program is free software: you can redistribute it and/or modify
433+# it under the terms of the GNU General Public License as published by
434+# the Free Software Foundation, either version 3 of the License, or
435+# (at your option) any later version.
436+#
437+# This program is distributed in the hope that it will be useful,
438+# but WITHOUT ANY WARRANTY; without even the implied warranty of
439+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
440+# GNU General Public License for more details.
441+#
442+# You should have received a copy of the GNU General Public License
443+# along with this program. If not, see <http://www.gnu.org/licenses/>.
444+#
445+##############################################################################
446+
447+from osv import fields, osv
448+import time
449+from lxml import etree
450+from tools.translate import _
451+
452+
453+class invoice_merge(osv.osv_memory):
454+ """
455+ Merge invoices
456+ """
457+
458+ _name = 'invoice.merge'
459+ _description = 'Use this wizard to merge draft invoices from the same partner'
460+
461+ _columns={
462+ 'invoices':fields.many2many('account.invoice', 'account_invoice_merge_rel', 'merge_id', 'invoice_id', 'Invoices')
463+ }
464+ def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
465+ res = super(invoice_merge, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=False)
466+ parent = self.pool.get('account.invoice').browse(cr,uid,context['active_id'])
467+
468+ doc = etree.XML(res['arch'])
469+ nodes = doc.xpath("//field[@name='invoices']")
470+ for node in nodes:
471+ node.set('domain', '["&",("partner_id", "=", '+ str(parent.partner_id.id) +'),("state", "=","draft")]')
472+ res['arch'] = etree.tostring(doc)
473+ context['partner'] = parent.partner_id.id
474+ return res
475+
476+ def default_get(self, cr, uid, fields, context=None):
477+ """
478+ """
479+ res = super(invoice_merge, self).default_get(cr, uid, fields, context=context)
480+ if context and 'active_ids' in context and context['active_ids']:
481+ res.update({'invoices': context['active_ids']})
482+
483+ return res
484+
485+ def merge_invoices(self, cr, uid, ids, context):
486+
487+ data = self.browse(cr, uid, ids, context=context)[0]
488+ self.pool.get('account.invoice').merge_invoice(cr, uid, data.invoices, context)
489+
490+ return {'type': 'ir.actions.act_window_close'}
491+
492+invoice_merge()
493+
494+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
495
496=== added file 'account_invoice_merge/wizard/invoice_merge_view.xml'
497--- account_invoice_merge/wizard/invoice_merge_view.xml 1970-01-01 00:00:00 +0000
498+++ account_invoice_merge/wizard/invoice_merge_view.xml 2012-08-19 18:29:22 +0000
499@@ -0,0 +1,35 @@
500+<?xml version="1.0" encoding="utf-8"?>
501+<openerp>
502+ <data>
503+ <!-- FORM SEARCH-->
504+ <record id="view_invoice_merge_form" model="ir.ui.view">
505+ <field name="name">account.invoice.merge.form</field>
506+ <field name="model">invoice.merge</field>
507+ <field name="type">form</field>
508+ <field name="arch" type="xml">
509+ <form string="Search Invoices">
510+ <group col="4" colspan="4">
511+ <separator colspan="4" string="Facturas"/>
512+ <field name="invoices" nolabel="1"/>
513+ </group>
514+ <separator colspan="4"/>
515+ <group col="2" colspan="4">
516+ <button special="cancel" string="_Cancel" icon='gtk-cancel'/>
517+ <button name="merge_invoices" string="_Merge invoces" colspan="1" type="object" icon="gtk-execute"/>
518+ </group>
519+ </form>
520+ </field>
521+ </record>
522+
523+ <!-- ACCION -->
524+ <record id="action_invoice_merge" model="ir.actions.act_window">
525+ <field name="name">Merge invoices</field>
526+ <field name="type">ir.actions.act_window</field>
527+ <field name="res_model">invoice.merge</field>
528+ <field name="view_type">form</field>
529+ <field name="view_mode">form</field>
530+ <field name="view_id" ref="view_invoice_merge_form"/>
531+ <field name="target">new</field>
532+ </record>
533+ </data>
534+</openerp>

Subscribers

People subscribed via source and target branches