Browse Source

[MIG][9.0] contract_invoice_merge_by_partner module

pull/57/head
cubells 8 years ago
parent
commit
5499e6842e
  1. 11
      contract_invoice_merge_by_partner/README.rst
  2. 2
      contract_invoice_merge_by_partner/__init__.py
  3. 10
      contract_invoice_merge_by_partner/__openerp__.py
  4. 2
      contract_invoice_merge_by_partner/models/__init__.py
  5. 31
      contract_invoice_merge_by_partner/models/account_analytic_analysis.py
  6. 4
      contract_invoice_merge_by_partner/models/res_partner.py
  7. 2
      contract_invoice_merge_by_partner/tests/__init__.py
  8. 43
      contract_invoice_merge_by_partner/tests/test_contract_invoice_merge_by_partner.py
  9. 9
      contract_invoice_merge_by_partner/views/res_partner_view.xml
  10. 2
      oca_dependencies.txt

11
contract_invoice_merge_by_partner/README.rst

@ -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.

2
contract_invoice_merge_by_partner/__init__.py

@ -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

10
contract_invoice_merge_by_partner/__openerp__.py

@ -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',
], ],

2
contract_invoice_merge_by_partner/models/__init__.py

@ -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

31
contract_invoice_merge_by_partner/models/account_analytic_analysis.py

@ -1,29 +1,34 @@
# -*- coding: utf-8 -*- # -*- 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). # 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):
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'] 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()
res += result.keys()
invoices2merge.do_merge()
invoices2unlink += invoices2merge invoices2unlink += invoices2merge
else:
res += invoices2merge.ids
invoices2unlink.unlink() invoices2unlink.unlink()
return res
return True

4
contract_invoice_merge_by_partner/models/res_partner.py

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- 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). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import fields, models from openerp import fields, models

2
contract_invoice_merge_by_partner/tests/__init__.py

@ -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

43
contract_invoice_merge_by_partner/tests/test_contract_invoice_merge_by_partner.py

@ -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):
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, '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')
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', '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_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()
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( 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')

9
contract_invoice_merge_by_partner/views/res_partner_view.xml

@ -1,8 +1,8 @@
<?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>
<data>
<odoo>
<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>
@ -15,5 +15,4 @@
</field> </field>
</record> </record>
</data>
</openerp>
</odoo>

2
oca_dependencies.txt

@ -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
Loading…
Cancel
Save