mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[MIG][9.0] contract_invoice_merge_by_partner module
This commit is contained in:
@@ -22,6 +22,8 @@ Usage
|
||||
activate checkbox " Merge contracts invoices "
|
||||
#. Go to *Sales > Contracts* and create some contracts with same partner you
|
||||
activated checkbox " Merge contracts invoices "
|
||||
#. Click on **Generate recurring invoices automatically** checkbox and add a
|
||||
product to invoice line.
|
||||
#. Go to *Settings > Automation > Scheduled Actions*
|
||||
#. Select *Generate Recurring Invoices from Contracts*
|
||||
#. Set previous time that now in *Next Execution Date*
|
||||
@@ -29,7 +31,7 @@ Usage
|
||||
|
||||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
|
||||
:alt: Try me on Runbot
|
||||
:target: https://runbot.odoo-community.org/runbot/95/8.0
|
||||
:target: https://runbot.odoo-community.org/runbot/95/9.0
|
||||
|
||||
|
||||
Bug Tracker
|
||||
@@ -48,13 +50,14 @@ Contributors
|
||||
* Carlos Dauden <carlos.dauden@tecnativa.com>
|
||||
* Pedro M. Baeza <pedro.baeza@tecnativa.com>
|
||||
* Rafael Blasco <rafael.blasco@tecnativa.com>
|
||||
* Vicent Cubells <vicent.cubells@tecnativa.com>
|
||||
|
||||
Maintainer
|
||||
----------
|
||||
|
||||
.. image:: http://odoo-community.org/logo.png
|
||||
.. image:: https://odoo-community.org/logo.png
|
||||
:alt: Odoo Community Association
|
||||
:target: http://odoo-community.org
|
||||
:target: https://odoo-community.org
|
||||
|
||||
This module is maintained by the OCA.
|
||||
|
||||
@@ -62,4 +65,4 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
|
||||
mission is to support the collaborative development of Odoo features and
|
||||
promote its widespread use.
|
||||
|
||||
To contribute to this module, please visit http://odoo-community.org.
|
||||
To contribute to this module, please visit https://odoo-community.org.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
|
||||
# Copyright 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from . import models
|
||||
|
||||
@@ -1,18 +1,22 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
|
||||
# Copyright 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
|
||||
# Copyright 2017 Vicent Cubells <vicent.cubells@tecnativa.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
{
|
||||
'name': 'Contract Invoice Merge By Partner',
|
||||
'summary': 'This module merges same partner invoices generated by '
|
||||
'contracts',
|
||||
'version': '8.0.1.0.0',
|
||||
'version': '9.0.1.0.0',
|
||||
'category': 'Account',
|
||||
'license': 'AGPL-3',
|
||||
'author': "Tecnativa, "
|
||||
"Odoo Community Association (OCA)",
|
||||
'website': 'http://www.tecnativa.com',
|
||||
'depends': ['account_analytic_analysis', 'account_invoice_merge'],
|
||||
'depends': [
|
||||
'contract',
|
||||
'account_invoice_merge',
|
||||
],
|
||||
'data': [
|
||||
'views/res_partner_view.xml',
|
||||
],
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
|
||||
# Copyright 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from . import account_analytic_analysis
|
||||
|
||||
@@ -1,29 +1,34 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
|
||||
# © 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
|
||||
# Copyright 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
|
||||
# Copyright 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
|
||||
# Copyright 2017 Vicent Cubells <vicent.cubells@tecnativa.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from openerp import api, models
|
||||
from openerp import api, fields, models
|
||||
|
||||
|
||||
class AccountAnalyticAccount(models.Model):
|
||||
_inherit = 'account.analytic.account'
|
||||
|
||||
@api.multi
|
||||
def _recurring_create_invoice(self, automatic=False):
|
||||
invoice_ids = super(
|
||||
AccountAnalyticAccount, self)._recurring_create_invoice(automatic)
|
||||
invoices = self.env['account.invoice'].browse(invoice_ids)
|
||||
res = []
|
||||
def recurring_create_invoice(self):
|
||||
contracts = self.search(
|
||||
[('recurring_next_date', '<=', fields.Date.today()),
|
||||
('account_type', '=', 'normal'),
|
||||
('recurring_invoices', '=', True)]
|
||||
)
|
||||
res = super(AccountAnalyticAccount, self).recurring_create_invoice()
|
||||
if not contracts:
|
||||
return res
|
||||
invoices = self.env['account.invoice'].search([
|
||||
('contract_id', 'in', contracts.ids)
|
||||
])
|
||||
invoices2unlink = self.env['account.invoice']
|
||||
for partner in invoices.mapped('partner_id'):
|
||||
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()
|
||||
invoices2merge.do_merge()
|
||||
invoices2unlink += invoices2merge
|
||||
else:
|
||||
res += invoices2merge.ids
|
||||
invoices2unlink.unlink()
|
||||
return res
|
||||
return True
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
|
||||
# © 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
|
||||
# Copyright 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
|
||||
# Copyright 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
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
|
||||
# Copyright 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from . import test_contract_invoice_merge_by_partner
|
||||
|
||||
@@ -1,25 +1,39 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
|
||||
# Copyright 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
|
||||
# Copyright 2017 Vicent Cubells <vicent.cubells@tecnativa.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from openerp.tests.common import TransactionCase
|
||||
from openerp.tests import common
|
||||
|
||||
|
||||
class TestContractInvoiceMergeByPartner(TransactionCase):
|
||||
class TestContractInvoiceMergeByPartner(common.SavepointCase):
|
||||
""" Use case : Prepare some data for current test case """
|
||||
def setUp(self):
|
||||
super(TestContractInvoiceMergeByPartner, self).setUp()
|
||||
self.partner = self.env['res.partner'].create({
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestContractInvoiceMergeByPartner, cls).setUpClass()
|
||||
cls.partner = cls.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({
|
||||
cls.uom = cls.env.ref('product.product_uom_hour')
|
||||
cls.product = cls.env['product.product'].create({
|
||||
'name': 'Custom Service',
|
||||
'type': 'service',
|
||||
'uom_id': cls.uom.id,
|
||||
'uom_po_id': cls.uom.id,
|
||||
'sale_ok': True,
|
||||
})
|
||||
cls.contract1 = cls.env['account.analytic.account'].create({
|
||||
'name': 'Test contract',
|
||||
'partner_id': self.partner.id,
|
||||
'type': 'contract',
|
||||
'partner_id': cls.partner.id,
|
||||
'recurring_invoices': False,
|
||||
})
|
||||
|
||||
def test_invoices_merged(self):
|
||||
res = self.env['account.analytic.account'].recurring_create_invoice()
|
||||
self.assertEqual(res, True)
|
||||
self.contract1.write({
|
||||
'recurring_invoices': True,
|
||||
'recurring_rule_type': 'monthly',
|
||||
'recurring_interval': 1,
|
||||
@@ -33,9 +47,10 @@ class TestContractInvoiceMergeByPartner(TransactionCase):
|
||||
self.contract2 = self.contract1.copy()
|
||||
self.contract3 = self.contract1.copy()
|
||||
self.contract4 = self.contract1.copy()
|
||||
|
||||
def test_invoices_merged(self):
|
||||
self.env['account.analytic.account']._recurring_create_invoice()
|
||||
contracts = self.env['account.analytic.account'].search([
|
||||
('partner_id', '=', self.partner.id)
|
||||
])
|
||||
contracts.recurring_create_invoice()
|
||||
invoices = self.env['account.invoice'].search(
|
||||
[('partner_id', '=', self.partner.id)])
|
||||
inv_draft = invoices.filtered(lambda x: x.state == 'draft')
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
|
||||
<!-- Copyright 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
|
||||
Copyright 2017 Vicent Cubells <vicent.cubells@tecnativa.com>
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
||||
<openerp>
|
||||
<data>
|
||||
<odoo>
|
||||
|
||||
<record id="view_partner_form" model="ir.ui.view">
|
||||
<field name="name">Partner Form Contract Invoice Merge</field>
|
||||
@@ -15,5 +15,4 @@
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
</odoo>
|
||||
|
||||
@@ -13,3 +13,5 @@
|
||||
#
|
||||
# To provide both the URL and a branch, use:
|
||||
# sale-workflow https://github.com/OCA/sale-workflow branchname
|
||||
|
||||
account-invoicing
|
||||
|
||||
Reference in New Issue
Block a user