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