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. 25
      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 "
#. 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.

2
contract_invoice_merge_by_partner/__init__.py

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

10
contract_invoice_merge_by_partner/__openerp__.py

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

2
contract_invoice_merge_by_partner/models/__init__.py

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

31
contract_invoice_merge_by_partner/models/account_analytic_analysis.py

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

4
contract_invoice_merge_by_partner/models/res_partner.py

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

2
contract_invoice_merge_by_partner/tests/__init__.py

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

43
contract_invoice_merge_by_partner/tests/test_contract_invoice_merge_by_partner.py

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

25
contract_invoice_merge_by_partner/views/res_partner_view.xml

@ -1,19 +1,18 @@
<?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>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<field name="user_id" position="after">
<field name="contract_invoice_merge"/>
<record id="view_partner_form" model="ir.ui.view">
<field name="name">Partner Form Contract Invoice Merge</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<field name="user_id" position="after">
<field name="contract_invoice_merge"/>
</field>
</field>
</field>
</record>
</data>
</openerp>
</odoo>

2
oca_dependencies.txt

@ -13,3 +13,5 @@
#
# To provide both the URL and a branch, use:
# sale-workflow https://github.com/OCA/sale-workflow branchname
account-invoicing
Loading…
Cancel
Save