← Back to team overview

openerp-community-reviewer team mailing list archive

[Merge] lp:~camptocamp/account-invoicing/6.1-add-invoice-merge-lep into lp:account-invoicing/6.1

 

Leonardo Pistone @ camptocamp has proposed merging lp:~camptocamp/account-invoicing/6.1-add-invoice-merge-lep into lp:account-invoicing/6.1.

Commit message:
[mrg] backport module account_invoice_merge

Requested reviews:
  Romain Deheele - Camptocamp (romaindeheele)
  Account Core Editors (account-core-editors)

For more details, see:
https://code.launchpad.net/~camptocamp/account-invoicing/6.1-add-invoice-merge-lep/+merge/197847

Backport of account_invoice_merge to 6.1. Credits go to OpenERP SA (merge PO feature on which this is based), Elico Corp (module for 7.0), Romain Deheele @ Camptocamp (initial work on the backport).

Thanks!
-- 
https://code.launchpad.net/~camptocamp/account-invoicing/6.1-add-invoice-merge-lep/+merge/197847
Your team Account Core Editors is requested to review the proposed merge of lp:~camptocamp/account-invoicing/6.1-add-invoice-merge-lep into lp:account-invoicing/6.1.
=== added directory 'account_invoice_merge'
=== added file 'account_invoice_merge/__init__.py'
--- account_invoice_merge/__init__.py	1970-01-01 00:00:00 +0000
+++ account_invoice_merge/__init__.py	2013-12-05 11:08:21 +0000
@@ -0,0 +1,29 @@
+# -*- coding: utf-8 -*-
+###############################################################################
+#                                                                             #
+#   Author: Leonardo Pistone <leonardo.pistone@xxxxxxxxxxxxxx>                #
+#   Copyright 2013 Camptocamp SA                                              #
+#                                                                             #
+#   Based on the merge Purchase Order functionality on OpenERP by OpenERP SA  #
+#   the account_invoice_merge for 7.0 by Elico Corp, and work by              #
+#   Romain Deheele, Camptocamp.                                               #
+#                                                                             #
+#   This program is free software: you can redistribute it and/or modify      #
+#   it under the terms of the GNU Affero General Public License as            #
+#   published by the Free Software Foundation, either version 3 of the        #
+#   License, or (at your option) any later version.                           #
+#                                                                             #
+#   This program is distributed in the hope that it will be useful,           #
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of            #
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             #
+#   GNU Affero General Public License for more details.                       #
+#                                                                             #
+#   You should have received a copy of the GNU Affero General Public License  #
+#   along with this program.  If not, see <http://www.gnu.org/licenses/>.     #
+#                                                                             #
+###############################################################################
+
+import invoice
+import wizard
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

=== added file 'account_invoice_merge/__openerp__.py'
--- account_invoice_merge/__openerp__.py	1970-01-01 00:00:00 +0000
+++ account_invoice_merge/__openerp__.py	2013-12-05 11:08:21 +0000
@@ -0,0 +1,53 @@
+# -*- coding: utf-8 -*-
+###############################################################################
+#                                                                             #
+#   Author: Leonardo Pistone <leonardo.pistone@xxxxxxxxxxxxxx>                #
+#   Copyright 2013 Camptocamp SA                                              #
+#                                                                             #
+#   Based on the merge Purchase Order functionality on OpenERP by OpenERP SA  #
+#   the account_invoice_merge for 7.0 by Elico Corp, and work by              #
+#   Romain Deheele, Camptocamp.                                               #
+#                                                                             #
+#   This program is free software: you can redistribute it and/or modify      #
+#   it under the terms of the GNU Affero General Public License as            #
+#   published by the Free Software Foundation, either version 3 of the        #
+#   License, or (at your option) any later version.                           #
+#                                                                             #
+#   This program is distributed in the hope that it will be useful,           #
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of            #
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             #
+#   GNU Affero General Public License for more details.                       #
+#                                                                             #
+#   You should have received a copy of the GNU Affero General Public License  #
+#   along with this program.  If not, see <http://www.gnu.org/licenses/>.     #
+#                                                                             #
+###############################################################################
+
+{
+    'name': 'Account Invoice Merge Wizard',
+    'version': '1.2',
+    'category': 'Finance',
+    'description': """
+This module adds an action in the invoices lists to merge of invoices. Here are
+the conditions to allow the merge:
+- Type should be the same (customer Invoice, supplier invoice, Customer or
+  Supplier Refund)
+- Partner should be the same
+- Currency should be the same
+- Account receivable account should be the same
+No merge is done at invoice line level.
+    """,
+    'author': 'Camptocamp',
+    'website': 'http://www.camptocamp.com',
+    'depends': ['base', 'account'],
+    'data': [
+        'wizard/invoice_merge_view.xml',
+    ],
+    'test': [
+    ],
+    'demo': [],
+    'installable': True,
+    'active': False,
+    'certificate': False,
+}
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

=== added directory 'account_invoice_merge/i18n'
=== added file 'account_invoice_merge/i18n/account_invoice_merge.pot'
--- account_invoice_merge/i18n/account_invoice_merge.pot	1970-01-01 00:00:00 +0000
+++ account_invoice_merge/i18n/account_invoice_merge.pot	2013-12-05 11:08:21 +0000
@@ -0,0 +1,76 @@
+# Translation of OpenERP Server.
+# This file contains the translation of the following modules:
+#	* account_invoice_merge
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: OpenERP Server 6.0.3\n"
+"Report-Msgid-Bugs-To: support@xxxxxxxxxxx\n"
+"POT-Creation-Date: 2012-05-07 02:54+0000\n"
+"PO-Revision-Date: 2012-05-07 02:54+0000\n"
+"Last-Translator: <>\n"
+"Language-Team: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: \n"
+"Plural-Forms: \n"
+
+#. module: account_invoice_merge
+#: model:ir.model,name:account_invoice_merge.model_account_invoice
+msgid "Invoice"
+msgstr ""
+
+#. module: account_invoice_merge
+#: code:addons/account_invoice_merge/wizard/invoice_merge.py:86
+#, python-format
+msgid "Partner Invoice"
+msgstr ""
+
+#. module: account_invoice_merge
+#: view:invoice.merge:0
+msgid " Please note that: \n"
+" \n"
+" Invoices will only be merged if: \n"
+" * Invoices are in draft \n"
+" * Invoices belong to the same partner \n"
+" * Invoices are have same company, partner, address, currency, journal, salesman, account, type \n"
+" \n"
+" Lines will only be merged if: \n"
+" * Invoice lines are exactly the same except for the product,quantity and unit \n"
+" "
+msgstr ""
+
+#. module: account_invoice_merge
+#: code:addons/account_invoice_merge/wizard/invoice_merge.py:48
+#, python-format
+msgid "Please select multiple invoice to merge in the list view."
+msgstr ""
+
+#. module: account_invoice_merge
+#: view:invoice.merge:0
+msgid "Merge Invoices"
+msgstr ""
+
+#. module: account_invoice_merge
+#: code:addons/account_invoice_merge/wizard/invoice_merge.py:47
+#, python-format
+msgid "Warning"
+msgstr ""
+
+#. module: account_invoice_merge
+#: view:invoice.merge:0
+#: model:ir.actions.act_window,name:account_invoice_merge.action_view_invoice_merge
+#: model:ir.model,name:account_invoice_merge.model_invoice_merge
+msgid "Merge Partner Invoice"
+msgstr ""
+
+#. module: account_invoice_merge
+#: view:invoice.merge:0
+msgid "Cancel"
+msgstr ""
+
+#. module: account_invoice_merge
+#: view:invoice.merge:0
+msgid "Are you sure you want to merge these invoices ?"
+msgstr ""
+

=== added file 'account_invoice_merge/i18n/fr.po'
--- account_invoice_merge/i18n/fr.po	1970-01-01 00:00:00 +0000
+++ account_invoice_merge/i18n/fr.po	2013-12-05 11:08:21 +0000
@@ -0,0 +1,83 @@
+# Translation of OpenERP Server.
+# This file contains the translation of the following modules:
+#	* account_invoice_merge
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: OpenERP Server 6.0.3\n"
+"Report-Msgid-Bugs-To: support@xxxxxxxxxxx\n"
+"POT-Creation-Date: 2012-05-07 02:54+0000\n"
+"PO-Revision-Date: 2013-06-23 19:40+0200\n"
+"Last-Translator: <>\n"
+"Language-Team: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: \n"
+"Plural-Forms: \n"
+
+#. module: account_invoice_merge
+#: model:ir.model,name:account_invoice_merge.model_account_invoice
+msgid "Invoice"
+msgstr "Facture"
+
+#. module: account_invoice_merge
+#: code:addons/account_invoice_merge/wizard/invoice_merge.py:86
+#, python-format
+msgid "Partner Invoice"
+msgstr "Facture client"
+
+#. module: account_invoice_merge
+#: view:invoice.merge:0
+msgid " Please note that: \n"
+" \n"
+" Invoices will only be merged if: \n"
+" * Invoices are in draft \n"
+" * Invoices belong to the same partner \n"
+" * Invoices are have same company, partner, address, currency, journal, salesman, account, type \n"
+" \n"
+" Lines will only be merged if: \n"
+" * Invoice lines are exactly the same except for the product,quantity and unit \n"
+" "
+msgstr ""
+"Les factures seront fusionnées uniquement si :\n"
+"\n"
+"* elles sont en Brouillon et du même type\n"
+"* elles ont les mêmes caractéristiques de partenaire, société,\n"
+"  adresse, devise, journal, vendeur, compte. \n"
+"\n"
+"Les lignes de factures ne sont pas fusionnées"
+
+#. module: account_invoice_merge
+#: code:addons/account_invoice_merge/wizard/invoice_merge.py:48
+#, python-format
+msgid "Please select multiple invoice to merge in the list view."
+msgstr "Veuillez choisir plusieurs factures à fusionner dans la vue liste"
+
+#. module: account_invoice_merge
+#: view:invoice.merge:0
+msgid "Merge Invoices"
+msgstr "Fusion de factures"
+
+#. module: account_invoice_merge
+#: code:addons/account_invoice_merge/wizard/invoice_merge.py:47
+#, python-format
+msgid "Warning"
+msgstr "Avertissement"
+
+#. module: account_invoice_merge
+#: view:invoice.merge:0
+#: model:ir.actions.act_window,name:account_invoice_merge.action_view_invoice_merge
+#: model:ir.model,name:account_invoice_merge.model_invoice_merge
+msgid "Merge Partner Invoice"
+msgstr "Fusion de factures"
+
+#. module: account_invoice_merge
+#: view:invoice.merge:0
+msgid "Cancel"
+msgstr "Annuler"
+
+#. module: account_invoice_merge
+#: view:invoice.merge:0
+msgid "Are you sure you want to merge these invoices ?"
+msgstr "Êtes-vous certain de vouloir fusionner ces factures ?"
+

=== added file 'account_invoice_merge/i18n/zh_CN.po'
--- account_invoice_merge/i18n/zh_CN.po	1970-01-01 00:00:00 +0000
+++ account_invoice_merge/i18n/zh_CN.po	2013-12-05 11:08:21 +0000
@@ -0,0 +1,85 @@
+# Translation of OpenERP Server.
+# This file contains the translation of the following modules:
+#	* account_invoice_merge
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: OpenERP Server 6.0.3\n"
+"Report-Msgid-Bugs-To: support@xxxxxxxxxxx\n"
+"POT-Creation-Date: 2012-05-07 02:54+0000\n"
+"PO-Revision-Date: 2012-05-07 02:54+0000\n"
+"Last-Translator: <>\n"
+"Language-Team: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: \n"
+"Plural-Forms: \n"
+
+#. module: account_invoice_merge
+#: model:ir.model,name:account_invoice_merge.model_account_invoice
+msgid "Invoice"
+msgstr "发票"
+
+#. module: account_invoice_merge
+#: code:addons/account_invoice_merge/wizard/invoice_merge.py:86
+#, python-format
+msgid "Partner Invoice"
+msgstr "合作伙伴发票"
+
+#. module: account_invoice_merge
+#: view:invoice.merge:0
+msgid " Please note that: \n"
+" \n"
+" Invoices will only be merged if: \n"
+" * Invoices are in draft \n"
+" * Invoices belong to the same partner \n"
+" * Invoices are have same company, partner, address, currency, journal, salesman, account, type \n"
+" \n"
+" Lines will only be merged if: \n"
+" * Invoice lines are exactly the same except for the product,quantity and unit \n"
+" "
+msgstr " 请注意: \n"
+" \n"
+"仅符合下列条件的发票,才会被合并: \n"
+" * 发票确认之前,还在草稿状态。 \n"
+" * 发票属于同一合作伙伴。 \n"
+" * 发票属于同一公司,有相同币别,账簿,业务员,科目及类型等。 \n"
+" \n"
+" 发票明细仅在符合下列条件才被合并: \n"
+" * 发票明细除了产品,数量,价格,金额等字段相同才被合并。 \n"
+" "
+
+#. module: account_invoice_merge
+#: code:addons/account_invoice_merge/wizard/invoice_merge.py:48
+#, python-format
+msgid "Please select multiple invoice to merge in the list view."
+msgstr "请在列表里选择多个发票来合并。"
+
+#. module: account_invoice_merge
+#: view:invoice.merge:0
+msgid "Merge Invoices"
+msgstr "合并发票"
+
+#. module: account_invoice_merge
+#: code:addons/account_invoice_merge/wizard/invoice_merge.py:47
+#, python-format
+msgid "Warning"
+msgstr "警告"
+
+#. module: account_invoice_merge
+#: view:invoice.merge:0
+#: model:ir.actions.act_window,name:account_invoice_merge.action_view_invoice_merge
+#: model:ir.model,name:account_invoice_merge.model_invoice_merge
+msgid "Merge Partner Invoice"
+msgstr "合并合作伙伴发票"
+
+#. module: account_invoice_merge
+#: view:invoice.merge:0
+msgid "Cancel"
+msgstr "取消"
+
+#. module: account_invoice_merge
+#: view:invoice.merge:0
+msgid "Are you sure you want to merge these invoices ?"
+msgstr "您确认合并这些发票?"
+

=== added file 'account_invoice_merge/invoice.py'
--- account_invoice_merge/invoice.py	1970-01-01 00:00:00 +0000
+++ account_invoice_merge/invoice.py	2013-12-05 11:08:21 +0000
@@ -0,0 +1,166 @@
+# -*- coding: utf-8 -*-
+###############################################################################
+#                                                                             #
+#   Author: Leonardo Pistone <leonardo.pistone@xxxxxxxxxxxxxx>                #
+#   Copyright 2013 Camptocamp SA                                              #
+#                                                                             #
+#   Based on the merge Purchase Order functionality on OpenERP by OpenERP SA  #
+#   the account_invoice_merge for 7.0 by Elico Corp, and work by              #
+#   Romain Deheele, Camptocamp.                                               #
+#                                                                             #
+#   This program is free software: you can redistribute it and/or modify      #
+#   it under the terms of the GNU Affero General Public License as            #
+#   published by the Free Software Foundation, either version 3 of the        #
+#   License, or (at your option) any later version.                           #
+#                                                                             #
+#   This program is distributed in the hope that it will be useful,           #
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of            #
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             #
+#   GNU Affero General Public License for more details.                       #
+#                                                                             #
+#   You should have received a copy of the GNU Affero General Public License  #
+#   along with this program.  If not, see <http://www.gnu.org/licenses/>.     #
+#                                                                             #
+###############################################################################
+
+from openerp.osv import orm
+from openerp import netsvc
+from osv.orm import browse_record, browse_null
+
+
+class account_invoice(orm.Model):
+    _inherit = "account.invoice"
+
+    def _get_first_invoice_fields(self, cr, uid, invoice):
+        return {'origin': '%s' % (invoice.origin or '',),
+                'partner_id': invoice.partner_id.id,
+                'address_invoice_id': invoice.address_invoice_id.id,
+                'journal_id': invoice.journal_id.id,
+                'user_id': invoice.user_id.id,
+                'currency_id': invoice.currency_id.id,
+                'company_id': invoice.company_id.id,
+                'type': invoice.type,
+                'account_id': invoice.account_id.id,
+                'state': 'draft',
+                'reference': '%s' % (invoice.reference or '',),
+                'name': '%s' % (invoice.name or '',),
+                'fiscal_position': invoice.fiscal_position and invoice.fiscal_position.id or False,
+                'payment_term': invoice.payment_term and invoice.payment_term.id or False,
+                'period_id': invoice.period_id and invoice.period_id.id or False,
+                'invoice_line': [],
+                }
+
+    def _get_invoice_key_cols(self, cr, uid, invoice):
+        return ('partner_id', 'address_invoice_id',
+                'user_id', 'type',
+                'account_id', 'currency_id',
+                'journal_id', 'company_id')
+
+    def _get_invoice_line_key_cols(self, cr, uid, invoice_line):
+        return ('name', 'origin', 'discount',
+                'invoice_line_tax_id', 'price_unit',
+                'product_id', 'account_id', 'quantity',
+                'account_analytic_id')
+
+    def do_merge(self, cr, uid, ids, context=None):
+        """
+        To merge similar type of account invoices.
+        Invoices will only be merged if:
+        * Account invoices are in draft
+        * Account invoices belong to the same partner
+        * Account invoices are have same company, partner, currency, journal,
+          currency, salesman, account, type
+        Lines will only be merged if:
+        * Invoice lines are exactly the same except for the quantity and unit
+
+         @param self: The object pointer.
+         @param cr: A database cursor
+         @param uid: ID of the user currently logged in
+         @param ids: the ID or list of IDs
+         @param context: A standard dictionary
+
+         @return: new account invoice id
+
+        """
+        wf_service = netsvc.LocalService("workflow")
+
+        def make_key(br, fields):
+            list_key = []
+            for field in fields:
+                field_val = getattr(br, field)
+                if field in ('product_id', 'account_id'):
+                    if not field_val:
+                        field_val = False
+                if isinstance(field_val, browse_record):
+                    field_val = field_val.id
+                elif isinstance(field_val, browse_null):
+                    field_val = False
+                elif isinstance(field_val, list):
+                    field_val = ((6, 0, tuple([v.id for v in field_val])),)
+                list_key.append((field, field_val))
+            list_key.sort()
+            return tuple(list_key)
+
+        # compute what the new invoices should contain
+        new_invoices = {}
+        draft_invoices = [
+            invoice
+            for invoice in self.browse(cr, uid, ids, context=context)
+            if invoice.state == 'draft'
+        ]
+        seen_origins = {}
+        seen_client_refs = {}
+        for invoice in draft_invoices:
+            invoice_key = make_key(
+                invoice, self._get_invoice_key_cols(cr, uid, invoice)
+            )
+            new_invoice = new_invoices.setdefault(invoice_key, ({}, []))
+            origins = seen_origins.setdefault(invoice_key, set())
+            client_refs = seen_client_refs.setdefault(invoice_key, set())
+            new_invoice[1].append(invoice.id)
+            invoice_infos = new_invoice[0]
+            if not invoice_infos:
+                invoice_infos.update(
+                    self._get_first_invoice_fields(cr, uid, invoice)
+                )
+                origins.add(invoice.origin)
+                client_refs.add(invoice.reference)
+            else:
+                if invoice.name:
+                    invoice_infos['name'] = (invoice_infos['name'] or '') + (' %s' % (invoice.name,))
+                if invoice.origin and invoice.origin not in origins:
+                    invoice_infos['origin'] = (invoice_infos['origin'] or '') + ' ' + invoice.origin
+                    origins.add(invoice.origin)
+                if invoice.reference and invoice.reference not in client_refs:
+                    invoice_infos['reference'] = (invoice_infos['reference'] or '') + (' %s' % (invoice.reference,))
+                    client_refs.add(invoice.reference)
+            for inv_line in invoice.invoice_line:
+                line_key = make_key(inv_line, self._get_invoice_line_key_cols(cr, uid, inv_line))
+                line_key = list(line_key)
+                if inv_line.uos_id:
+                    line_key.append(('uos_id', inv_line.uos_id.id))
+                if invoice.origin:
+                    line_key.append(('origin', invoice.origin))
+                invoice_infos['invoice_line'].append((0, 0, dict(line_key)))
+
+        allinvoices = []
+        invoices_info = {}
+        for invoice_key, (invoice_data, old_ids) in new_invoices.iteritems():
+            # skip merges with only one invoice
+            if len(old_ids) < 2:
+                allinvoices += (old_ids or [])
+                continue
+
+            # create the new invoice
+            newinvoice_id = self.create(cr, uid, invoice_data)
+            invoices_info.update({newinvoice_id: old_ids})
+            allinvoices.append(newinvoice_id)
+
+            # make triggers pointing to the old invoices point to the new invoice
+            for old_id in old_ids:
+                wf_service.trg_redirect(uid, 'account.invoice', old_id, newinvoice_id, cr)
+                wf_service.trg_validate(uid, 'account.invoice', old_id, 'invoice_cancel', cr)
+
+        return invoices_info
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

=== added directory 'account_invoice_merge/wizard'
=== added file 'account_invoice_merge/wizard/__init__.py'
--- account_invoice_merge/wizard/__init__.py	1970-01-01 00:00:00 +0000
+++ account_invoice_merge/wizard/__init__.py	2013-12-05 11:08:21 +0000
@@ -0,0 +1,27 @@
+# -*- coding: utf-8 -*-
+###############################################################################
+#                                                                             #
+#   Author: Leonardo Pistone <leonardo.pistone@xxxxxxxxxxxxxx>                #
+#   Copyright 2013 Camptocamp SA                                              #
+#                                                                             #
+#   Based on the merge Purchase Order functionality on OpenERP by OpenERP SA  #
+#   the account_invoice_merge for 7.0 by Elico Corp, and work by              #
+#   Romain Deheele, Camptocamp.                                               #
+#                                                                             #
+#   This program is free software: you can redistribute it and/or modify      #
+#   it under the terms of the GNU Affero General Public License as            #
+#   published by the Free Software Foundation, either version 3 of the        #
+#   License, or (at your option) any later version.                           #
+#                                                                             #
+#   This program is distributed in the hope that it will be useful,           #
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of            #
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             #
+#   GNU Affero General Public License for more details.                       #
+#                                                                             #
+#   You should have received a copy of the GNU Affero General Public License  #
+#   along with this program.  If not, see <http://www.gnu.org/licenses/>.     #
+#                                                                             #
+###############################################################################
+
+import invoice_merge
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

=== added file 'account_invoice_merge/wizard/invoice_merge.py'
--- account_invoice_merge/wizard/invoice_merge.py	1970-01-01 00:00:00 +0000
+++ account_invoice_merge/wizard/invoice_merge.py	2013-12-05 11:08:21 +0000
@@ -0,0 +1,129 @@
+# -*- coding: utf-8 -*-
+###############################################################################
+#                                                                             #
+#   Author: Leonardo Pistone <leonardo.pistone@xxxxxxxxxxxxxx>                #
+#   Copyright 2013 Camptocamp SA                                              #
+#                                                                             #
+#   Based on the merge Purchase Order functionality on OpenERP by OpenERP SA  #
+#   the account_invoice_merge for 7.0 by Elico Corp, and work by              #
+#   Romain Deheele, Camptocamp.                                               #
+#                                                                             #
+#   This program is free software: you can redistribute it and/or modify      #
+#   it under the terms of the GNU Affero General Public License as            #
+#   published by the Free Software Foundation, either version 3 of the        #
+#   License, or (at your option) any later version.                           #
+#                                                                             #
+#   This program is distributed in the hope that it will be useful,           #
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of            #
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             #
+#   GNU Affero General Public License for more details.                       #
+#                                                                             #
+#   You should have received a copy of the GNU Affero General Public License  #
+#   along with this program.  If not, see <http://www.gnu.org/licenses/>.     #
+#                                                                             #
+###############################################################################
+
+from openerp.osv import osv, orm
+from openerp.tools.translate import _
+
+
+class invoice_merge(orm.TransientModel):
+    _name = "invoice.merge"
+    _description = "Merge Partner Invoice"
+
+    def fields_view_get(self, cr, uid, view_id=None, view_type='form',
+                        context=None, toolbar=False, submenu=False):
+        """Changes the view dynamically
+
+        @param self: The object pointer.
+        @param cr: A database cursor
+        @param uid: ID of the user currently logged in
+        @param context: A standard dictionary
+
+        @return: New arch of view.
+
+        """
+        if context is None:
+            context = {}
+        res = super(invoice_merge, self).fields_view_get(
+            cr, uid, view_id=view_id, view_type=view_type, context=context,
+            toolbar=toolbar, submenu=False)
+
+        if (
+            context.get('active_model') == 'account.invoice'
+            and len(context['active_ids']) < 2
+        ):
+            raise osv.except_osv(
+                _('Warning'),
+                _('Please select multiple invoice to merge in the list view.')
+            )
+        return res
+
+    def merge_invoices(self, cr, uid, _ids, context=None):
+        """To merge similar type of account invoices.
+
+        @param self: The object pointer.
+        @param cr: A database cursor
+        @param uid: ID of the user currently logged in
+        @param ids: the ID or list of IDs
+        @param context: A standard dictionary
+
+        @return: account invoice view
+
+        """
+        invoice_obj = self.pool.get('account.invoice')
+        mod_obj = self.pool.get('ir.model.data')
+        # None if sale is not installed
+        so_obj = self.pool.get('sale.order')
+        # None if purchase is not installed
+        po_obj = self.pool.get('purchase.order')
+
+        if context is None:
+            context = {}
+        try:
+            search_view_id = mod_obj.get_object(
+                cr, uid, 'account', 'view_account_invoice_filter'
+            ).id
+        except ValueError:
+            search_view_id = False
+        allinvoices = invoice_obj.do_merge(
+            cr, uid, context.get('active_ids', []), context)
+
+        for new_invoice in allinvoices:
+            if so_obj is not None:
+                todo_ids = so_obj.search(cr, uid, [
+                    ('invoice_ids', 'in', allinvoices[new_invoice])
+                ], context=context)
+                for org_invoice in so_obj.browse(
+                    cr, uid, todo_ids, context=context
+                ):
+                    so_obj.write(cr, uid, [org_invoice.id], {
+                        'invoice_ids': [(4, new_invoice)]
+                    }, context)
+            if po_obj is not None:
+                todo_ids = po_obj.search(cr, uid, [
+                    ('invoice_ids', 'in', allinvoices[new_invoice])
+                ], context=context)
+                for org_invoice in po_obj.browse(
+                    cr, uid, todo_ids, context=context
+                ):
+                    po_obj.write(cr, uid, [org_invoice.id], {
+                        'invoice_ids': [(4, new_invoice)]
+                    }, context)
+
+        return {
+            'domain': "[('id', 'in', [%s])]" % ','.join(
+                str(inv_id) for inv_id in allinvoices
+            ),
+            'name': _('Partner Invoice'),
+            'view_type': 'form',
+            'view_mode': 'tree,form',
+            'res_model': 'account.invoice',
+            #'view_id': [view_id],
+            'view_id': False,
+            'type': 'ir.actions.act_window',
+            'search_view_id': search_view_id,
+            #'target': 'current',
+        }
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

=== added file 'account_invoice_merge/wizard/invoice_merge_view.xml'
--- account_invoice_merge/wizard/invoice_merge_view.xml	1970-01-01 00:00:00 +0000
+++ account_invoice_merge/wizard/invoice_merge_view.xml	2013-12-05 11:08:21 +0000
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data>
+        <record id="view_invoice_merge" model="ir.ui.view">
+            <field name="name">Merger Partner Invoice</field>
+            <field name="model">invoice.merge</field>
+            <field name="type">form</field>
+            <field name="arch" type="xml">
+               <form string="Merge Partner Invoice">
+                    <separator string="Are you sure you want to merge these invoices ?" colspan="4"/>
+                       <newline/>
+                    <label string="
+Please note that: &#10; &#10;
+Invoices will only be merged if: &#10;
+* Invoices are in draft &#10;
+* Invoices belong to the same partner &#10;
+* Invoices are have same company, partner, address, currency, journal, salesman, account, type &#10; &#10;
+Lines will only be merged if: &#10;
+* Invoice lines are exactly the same except for the product,quantity and unit &#10;
+" colspan="4"/>
+                    <newline/>
+                    <separator string="" colspan="4" />
+                    <button special="cancel" string="Cancel" icon="gtk-cancel"/>
+                    <button name="merge_invoices" string="Merge Invoices" type="object" icon="gtk-convert"/>
+                </form>
+            </field>
+        </record>
+
+        <act_window name="Merge Partner Invoice"
+            res_model="invoice.merge"
+            src_model="account.invoice"
+            view_mode="form"
+            target="new"
+            multi="True"
+            key2="client_action_multi"
+            groups="account.group_account_invoice"
+            id="action_view_invoice_merge"/>
+
+    </data>
+</openerp>
+