Pedro M. Baeza
9 years ago
committed by
cubells
4 changed files with 39 additions and 32 deletions
-
24contract_invoice_merge_by_partner/i18n/es.po
-
29contract_invoice_merge_by_partner/models/account_analytic_analysis.py
-
6contract_invoice_merge_by_partner/models/res_partner.py
-
4contract_invoice_merge_by_partner/tests/test_contract_invoice_merge_by_partner.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 |
Write
Preview
Loading…
Cancel
Save
Reference in new issue