[FIX] contract_invoice_merge_by_partner: Fix merge method

This commit is contained in:
Pedro M. Baeza
2016-07-22 01:37:24 +02:00
parent e488a87eba
commit a28a892926
4 changed files with 39 additions and 32 deletions

View File

@@ -1,33 +1,37 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * contract_invoice_merge_by_partner
# * contract_invoice_merge_by_partner
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 8.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-06-14 13:16+0000\n"
"PO-Revision-Date: 2016-06-14 15:19+0100\n"
"Last-Translator: Carlos Dauden <carlos.dauden@tecnativa.com>\n"
"Language-Team: Tecnativa <info@tecnativa.com>\n"
"POT-Creation-Date: 2016-07-21 23:35+0000\n"
"PO-Revision-Date: 2016-07-21 23:35+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 1.5.4\n"
"Language: es_ES\n"
"X-Poedit-SourceCharset: UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: contract_invoice_merge_by_partner
#: model:ir.model,name:contract_invoice_merge_by_partner.model_account_analytic_account
msgid "Analytic Account"
msgstr "Cuenta analítica"
#. module: contract_invoice_merge_by_partner
#: help:res.partner,contract_invoice_merge:0
msgid "If checked, all the recurring invoices generated by the contracts of this partner will be merged on each run."
msgstr "Si está marcado, todas las facturas recurrentes generadas por los contratos de esta empresa serán fusionados en cada generación."
#. module: contract_invoice_merge_by_partner
#: field:res.partner,contract_invoice_merge:0
msgid "Contract invoice merge"
msgstr "Fusionar facturas de contratos"
msgid "Merge contracts invoices"
msgstr "Fusionar las facturas de los contratos"
#. module: contract_invoice_merge_by_partner
#: model:ir.model,name:contract_invoice_merge_by_partner.model_res_partner
msgid "Partner"
msgstr "Empresa"

View File

@@ -1,30 +1,29 @@
# -*- coding: utf-8 -*-
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# © 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import api, models
class PurchaseOrderLine(models.Model):
class AccountAnalyticAccount(models.Model):
_inherit = 'account.analytic.account'
@api.multi
def _recurring_create_invoice(self, automatic=False):
invoice_obj = self.env['account.invoice']
invoices = invoice_obj.browse(
super(PurchaseOrderLine, self)._recurring_create_invoice(
automatic))
invoice_ids = super(
AccountAnalyticAccount, self)._recurring_create_invoice(automatic)
invoices = self.env['account.invoice'].browse(invoice_ids)
res = []
unlink_list = []
invoices2unlink = self.env['account.invoice']
for partner in invoices.mapped('partner_id'):
inv_to_merge = invoices.filtered(
lambda x: x.partner_id.id == partner)
if partner.contract_invoice_merge and len(inv_to_merge) > 1:
invoices_merged = inv_to_merge.do_merge()
res.extend(invoices_merged)
unlink_list.extend(inv_to_merge)
invoices2merge = invoices.filtered(
lambda x: x.partner_id == partner)
if partner.contract_invoice_merge and len(invoices2merge) > 1:
result = invoices2merge.do_merge()
res += result.keys()
invoices2unlink += invoices2merge
else:
res.extend(inv_to_merge)
if unlink_list:
invoice_obj.browse(unlink_list).unlink()
res += invoices2merge.ids
invoices2unlink.unlink()
return res

View File

@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# © 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import fields, models
@@ -8,4 +9,7 @@ from openerp import fields, models
class ResPartner(models.Model):
_inherit = 'res.partner'
contract_invoice_merge = fields.Boolean()
contract_invoice_merge = fields.Boolean(
string="Merge contracts invoices",
help="If checked, all the recurring invoices generated by the "
"contracts of this partner will be merged on each run.")

View File

@@ -9,11 +9,11 @@ class TestContractInvoiceMergeByPartner(TransactionCase):
""" Use case : Prepare some data for current test case """
def setUp(self):
super(TestContractInvoiceMergeByPartner, self).setUp()
self.partner = self.env['res.partner'].create(
{'customer': True,
'name': "Test Customer",
'contract_invoice_merge': True,
})
self.partner = self.env['res.partner'].create({
'customer': True,
'name': "Test Customer",
'contract_invoice_merge': True,
})
self.product = self.env.ref('product.product_product_consultant')
self.uom = self.env.ref('product.product_uom_hour')
self.contract1 = self.env['account.analytic.account'].create({