diff --git a/contract_recurring_invoicing_monthly_last_day/README.rst b/contract_recurring_invoicing_monthly_last_day/README.rst new file mode 100644 index 00000000..7aa4965b --- /dev/null +++ b/contract_recurring_invoicing_monthly_last_day/README.rst @@ -0,0 +1,65 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +=========================================== +Contract Recurring Invoice Monthly Last Day +=========================================== + +This module extends the functionality of contracts to support a recurring type +of monthly - last day. + +This changes the next contract recurring invoice date computation, so that if +recurring type is "Monthly - Last day", next invoice date is computed to be the +last day of the corresponding month. + +Configuration +============= + +Just select the new recurring type in the contract. + +Usage +===== + +To use this module, you need to: + +* Go to ... + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/110/8.0 + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smashing it by providing a detailed and welcomed `feedback +`_. + +Credits +======= + +Contributors +------------ + +* Eneko Lacunza + + +Maintainer +---------- + +.. image:: http://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: http://odoo-community.org + +This module is maintained by the OCA. + +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. diff --git a/contract_recurring_invoicing_monthly_last_day/__init__.py b/contract_recurring_invoicing_monthly_last_day/__init__.py new file mode 100644 index 00000000..935b05bc --- /dev/null +++ b/contract_recurring_invoicing_monthly_last_day/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2016 Binovo IT Human Project SL +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/contract_recurring_invoicing_monthly_last_day/__openerp__.py b/contract_recurring_invoicing_monthly_last_day/__openerp__.py new file mode 100644 index 00000000..42620af8 --- /dev/null +++ b/contract_recurring_invoicing_monthly_last_day/__openerp__.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# © 2016 Binovo IT Human Project SL +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + 'name': "Contract recurring invoice type monthly - last day", + 'summary': ''' + Adds a new invoice recurring period for contracts - month(s) last day. + ''', + 'author': 'Binovo IT Human Project SL - Eneko Lacunza, ' + 'Odoo Community Association (OCA)', + 'website': 'http://www.binovo.es', + 'category': 'Sales Management', + 'version': '8.0.1.0.0', + 'depends': ['account_analytic_analysis'], + 'license': 'AGPL-3', + 'test': [ + 'test/contract_recurring_invoicing_monthly_last_day.yml' + ], + 'installable': True, +} diff --git a/contract_recurring_invoicing_monthly_last_day/i18n/es.po b/contract_recurring_invoicing_monthly_last_day/i18n/es.po new file mode 100644 index 00000000..f4330749 --- /dev/null +++ b/contract_recurring_invoicing_monthly_last_day/i18n/es.po @@ -0,0 +1,23 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * contract_recurring_invoice_monthly_last_day +# elacunza , 2016. +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2016-03-14 12:20+0000\n" +"PO-Revision-Date: 2016-03-14 12:20+0100\n" +"Last-Translator: elacunza \n" +"Language-Team: Binovo\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Generator: Poedit 1.5.4\n" + +#. module: contract_recurring_invoice_monthly_last_day +#: selection:account.analytic.account,recurring_rule_type:0 +msgid "Month(s) - Last day" +msgstr "Mes(es) - último día" diff --git a/contract_recurring_invoicing_monthly_last_day/models/__init__.py b/contract_recurring_invoicing_monthly_last_day/models/__init__.py new file mode 100644 index 00000000..02035ca0 --- /dev/null +++ b/contract_recurring_invoicing_monthly_last_day/models/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2016 Binovo IT Human Project SL +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import contract diff --git a/contract_recurring_invoicing_monthly_last_day/models/contract.py b/contract_recurring_invoicing_monthly_last_day/models/contract.py new file mode 100644 index 00000000..8ab0c6a9 --- /dev/null +++ b/contract_recurring_invoicing_monthly_last_day/models/contract.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# © 2016 Binovo IT Human Project SL +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp import models, fields, api +from dateutil.relativedelta import relativedelta +import datetime +import time + + +class AccountAnalyticAccount(models.Model): + _inherit = 'account.analytic.account' + + recurring_rule_type = fields.Selection( + selection_add=[('monthlylastday', 'Month(s) - Last day')]) + + @api.multi + def _recurring_create_invoice(self, automatic=False): + invoice_ids = [] + current_date = time.strftime('%Y-%m-%d') + if self.ids: + contracts = self + else: + contracts = self.search( + [('recurring_next_date', '<=', current_date), + ('state', '=', 'open'), + ('recurring_invoices', '=', True), + ('type', '=', 'contract')]) + for contract in contracts: + is_monthlylastday = False + orig_next_date = contract.recurring_next_date + if contract.recurring_rule_type == 'monthlylastday': + is_monthlylastday = True + contract.recurring_rule_type = 'monthly' + try: + invoice_ids.append(super(AccountAnalyticAccount, contract) + ._recurring_create_invoice(automatic)) + finally: + if is_monthlylastday: + contract.recurring_rule_type = 'monthlylastday' + # Note: recurring_next_day has been already incremented by super if + # invoice was created. Adjust it to month's last day + if is_monthlylastday \ + and contract.recurring_next_date != orig_next_date: + next_date = datetime.datetime.strptime( + contract.recurring_next_date, + "%Y-%m-%d") + new_date = next_date + relativedelta(day=31) + contract.write( + {'recurring_next_date': new_date.strftime('%Y-%m-%d')}) + return invoice_ids diff --git a/contract_recurring_invoicing_monthly_last_day/test/contract_recurring_invoicing_monthly_last_day.yml b/contract_recurring_invoicing_monthly_last_day/test/contract_recurring_invoicing_monthly_last_day.yml new file mode 100644 index 00000000..6031a3b6 --- /dev/null +++ b/contract_recurring_invoicing_monthly_last_day/test/contract_recurring_invoicing_monthly_last_day.yml @@ -0,0 +1,30 @@ +- + Create new contract with recurring type monthly last day +- + !record {model: account.analytic.account, id: contract_main}: + name: Recurring monthly last day + company_id: base.main_company + partner_id: base.main_partner + type: contract + recurring_invoices : 1 + recurring_interval : 1 + recurring_rule_type: 'monthlylastday' + recurring_next_date: '2016-02-29' + recurring_invoice_line_ids: + - quantity: 2.0 + price_unit: 100.0 + name: Database Administration 25 + product_id: product.product_product_consultant + uom_id: product.product_uom_hour +- + Generate all invoices from contracts having recurring invoicing +- + !python {model: account.analytic.account}: | + self.recurring_create_invoice(cr, uid, []) +- + Check contracts new recurring_next_date +- + !python {model: account.analytic.account}: | + contract_id = ref('contract_recurring_invoicing_monthly_last_day.contract_main') + contract = self.browse(cr, uid, [contract_id], context=context) + assert contract.recurring_next_date == '2016-03-31', "Next recurring date for the contract must be 2016-03-31, but got (%s)"%(contract.recurring_next_date,)