mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
Add new module for monthly recurring invoices, on month's last day (#25)
[ADD] contract_recurring_invoicing_monthly_last_day New module for monthly recurring invoices, on month's last day
This commit is contained in:
65
contract_recurring_invoicing_monthly_last_day/README.rst
Normal file
65
contract_recurring_invoicing_monthly_last_day/README.rst
Normal file
@@ -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
|
||||||
|
<https://github.com/OCA/contract/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
|
||||||
|
<https://github.com/OCA/contract/issues/new?body=module:%20
|
||||||
|
contract_recurring_invoicing_monthly_last_day%0Aversion:%20
|
||||||
|
8.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
|
||||||
|
|
||||||
|
Credits
|
||||||
|
=======
|
||||||
|
|
||||||
|
Contributors
|
||||||
|
------------
|
||||||
|
|
||||||
|
* Eneko Lacunza <elacunza@binovo.es>
|
||||||
|
|
||||||
|
|
||||||
|
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.
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# © 2016 Binovo IT Human Project SL <elacunza@binovo.es>
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
|
from . import models
|
||||||
20
contract_recurring_invoicing_monthly_last_day/__openerp__.py
Normal file
20
contract_recurring_invoicing_monthly_last_day/__openerp__.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# © 2016 Binovo IT Human Project SL <elacunza@binovo.es>
|
||||||
|
# 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,
|
||||||
|
}
|
||||||
23
contract_recurring_invoicing_monthly_last_day/i18n/es.po
Normal file
23
contract_recurring_invoicing_monthly_last_day/i18n/es.po
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# Translation of Odoo Server.
|
||||||
|
# This file contains the translation of the following modules:
|
||||||
|
# * contract_recurring_invoice_monthly_last_day
|
||||||
|
# elacunza <elacunza@binovo.es>, 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 <elacunza@binovo.es>\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"
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# © 2016 Binovo IT Human Project SL <elacunza@binovo.es>
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
|
from . import contract
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# © 2016 Binovo IT Human Project SL <elacunza@binovo.es>
|
||||||
|
# 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
|
||||||
@@ -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,)
|
||||||
Reference in New Issue
Block a user