Browse Source

[FIX] contract_invoice_merge_by_partner: Fix merge method

pull/33/head
Pedro M. Baeza 8 years ago
parent
commit
b1d1b3200d
  1. 26
      contract_invoice_merge_by_partner/i18n/es.po
  2. 29
      contract_invoice_merge_by_partner/models/account_analytic_analysis.py
  3. 6
      contract_invoice_merge_by_partner/models/res_partner.py
  4. 10
      contract_invoice_merge_by_partner/tests/test_contract_invoice_merge_by_partner.py

26
contract_invoice_merge_by_partner/i18n/es.po

@ -1,33 +1,37 @@
# Translation of Odoo Server. # Translation of Odoo Server.
# This file contains the translation of the following modules: # This file contains the translation of the following modules:
# * contract_invoice_merge_by_partner
# * contract_invoice_merge_by_partner
# #
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Odoo Server 8.0\n" "Project-Id-Version: Odoo Server 8.0\n"
"Report-Msgid-Bugs-To: \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" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\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 #. module: contract_invoice_merge_by_partner
#: model:ir.model,name:contract_invoice_merge_by_partner.model_account_analytic_account #: model:ir.model,name:contract_invoice_merge_by_partner.model_account_analytic_account
msgid "Analytic Account" msgid "Analytic Account"
msgstr "Cuenta analítica" 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 #. module: contract_invoice_merge_by_partner
#: field:res.partner,contract_invoice_merge:0 #: 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 #. module: contract_invoice_merge_by_partner
#: model:ir.model,name:contract_invoice_merge_by_partner.model_res_partner #: model:ir.model,name:contract_invoice_merge_by_partner.model_res_partner
msgid "Partner" msgid "Partner"
msgstr "Empresa" msgstr "Empresa"

29
contract_invoice_merge_by_partner/models/account_analytic_analysis.py

@ -1,30 +1,29 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com> # © 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). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import api, models from openerp import api, models
class PurchaseOrderLine(models.Model):
class AccountAnalyticAccount(models.Model):
_inherit = 'account.analytic.account' _inherit = 'account.analytic.account'
@api.multi @api.multi
def _recurring_create_invoice(self, automatic=False): 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 = [] res = []
unlink_list = []
invoices2unlink = self.env['account.invoice']
for partner in invoices.mapped('partner_id'): 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: else:
res.extend(inv_to_merge)
if unlink_list:
invoice_obj.browse(unlink_list).unlink()
res += invoices2merge.ids
invoices2unlink.unlink()
return res return res

6
contract_invoice_merge_by_partner/models/res_partner.py

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com> # © 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). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import fields, models from openerp import fields, models
@ -8,4 +9,7 @@ from openerp import fields, models
class ResPartner(models.Model): class ResPartner(models.Model):
_inherit = 'res.partner' _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.")

10
contract_invoice_merge_by_partner/tests/test_contract_invoice_merge_by_partner.py

@ -9,11 +9,11 @@ class TestContractInvoiceMergeByPartner(TransactionCase):
""" Use case : Prepare some data for current test case """ """ Use case : Prepare some data for current test case """
def setUp(self): def setUp(self):
super(TestContractInvoiceMergeByPartner, self).setUp() 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.product = self.env.ref('product.product_product_consultant')
self.uom = self.env.ref('product.product_uom_hour') self.uom = self.env.ref('product.product_uom_hour')
self.contract1 = self.env['account.analytic.account'].create({ self.contract1 = self.env['account.analytic.account'].create({

Loading…
Cancel
Save