diff --git a/contract_recurring_invoicing_marker/README.rst b/contract_recurring_invoicing_marker/README.rst new file mode 100644 index 00000000..a26d6936 --- /dev/null +++ b/contract_recurring_invoicing_marker/README.rst @@ -0,0 +1,79 @@ +.. 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 + +======================================= +Markers for contract recurring invoices +======================================= + +This module allows to include some markers on the lines of your recurring +invoices definition inside the contract so that the generated invoice lines +will contain a dynamic text depending on these markers. + +These markers are the supported ones: + +* #START#: Start date of the invoiced period. +* #END# End date of the invoiced period. + +Usage +===== + +On a contract (*Sales > Sales > Contracts*), mark "Generate recurring invoices +automatically" for enabling the creation of recurring invoices. + +In the "Invoice Lines" section, you can add lines with products. In the +*Description* field, you can now add any of the markers mentioned before +between the rest of the text. + +When you invoice this contract (automatically or manually), your invoice +will contain the corresponding text that replaces the marker. + +.. 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 + +Known issues / Roadmap +====================== + +* Add more markers, like #START_MONTH# or #END_MONTH#. + +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 `here `_. + +Credits +======= + +Contributors +------------ + +* Pedro M. Baeza + +Icon +---- + +* https://openclipart.org/detail/125071/pie-graph +* Subicon made by `Freepik _ from + www.flaticon.com + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://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_marker/__init__.py b/contract_recurring_invoicing_marker/__init__.py new file mode 100644 index 00000000..406086aa --- /dev/null +++ b/contract_recurring_invoicing_marker/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# (c) 2016 Serv. Tecnol. Avanzados - Pedro M. Baeza +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from . import models diff --git a/contract_recurring_invoicing_marker/__openerp__.py b/contract_recurring_invoicing_marker/__openerp__.py new file mode 100644 index 00000000..f2efc554 --- /dev/null +++ b/contract_recurring_invoicing_marker/__openerp__.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# (c) 2016 Serv. Tecnol. Avanzados - Pedro M. Baeza +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +{ + 'name': 'Markers for contract recurring invoices', + 'version': '8.0.1.0.0', + 'category': 'Contract Management', + 'author': 'Serv. Tecnol. Avanzados - Pedro M. Baeza, ' + 'Odoo Community Association (OCA)', + 'website': 'http://www.serviciosbaeza.com', + 'depends': [ + 'account_analytic_analysis', + ], + 'data': [ + 'views/account_analytic_account_view.xml', + ], + 'installable': True, +} diff --git a/contract_recurring_invoicing_marker/models/__init__.py b/contract_recurring_invoicing_marker/models/__init__.py new file mode 100644 index 00000000..9bde9c9b --- /dev/null +++ b/contract_recurring_invoicing_marker/models/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# (c) 2016 Serv. Tecnol. Avanzados - Pedro M. Baeza +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from . import account_analytic_account diff --git a/contract_recurring_invoicing_marker/models/account_analytic_account.py b/contract_recurring_invoicing_marker/models/account_analytic_account.py new file mode 100644 index 00000000..c2986655 --- /dev/null +++ b/contract_recurring_invoicing_marker/models/account_analytic_account.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +# (c) 2016 Serv. Tecnol. Avanzados - Pedro M. Baeza +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from openerp import api, fields, models +from dateutil.relativedelta import relativedelta + + +class AccountAnalyticAccount(models.Model): + _inherit = "account.analytic.account" + + @api.model + def _prepare_invoice(self, contract): + next_date = fields.Date.from_string( + contract.recurring_next_date or fields.Date.today()) + interval = contract.recurring_interval + old_date = next_date + if contract.recurring_rule_type == 'daily': + new_date = next_date + relativedelta(days=interval - 1) + elif contract.recurring_rule_type == 'weekly': + new_date = next_date + relativedelta(weeks=interval, days=-1) + else: + new_date = next_date + relativedelta(months=interval, days=-1) + obj = self.with_context(old_date=old_date, next_date=new_date) + return super(AccountAnalyticAccount, obj)._prepare_invoice(contract) + + @api.model + def _prepare_invoice_line(self, line, invoice_id): + res = super(AccountAnalyticAccount, self)._prepare_invoice_line( + line, invoice_id) + if 'old_date' in self.env.context and 'next_date' in self.env.context: + lang_obj = self.env['res.lang'] + contract = line.analytic_account_id + lang = lang_obj.search( + [('code', '=', contract.partner_id.lang)]) + date_format = lang.date_format + res['name'] = res['name'].replace( + '#START#', self.env.context['old_date'].strftime(date_format)) + res['name'] = res['name'].replace( + '#END#', self.env.context['next_date'].strftime(date_format)) + return res diff --git a/contract_recurring_invoicing_marker/static/description/icon.png b/contract_recurring_invoicing_marker/static/description/icon.png new file mode 100644 index 00000000..d4d85b46 Binary files /dev/null and b/contract_recurring_invoicing_marker/static/description/icon.png differ diff --git a/contract_recurring_invoicing_marker/static/description/icon.svg b/contract_recurring_invoicing_marker/static/description/icon.svg new file mode 100644 index 00000000..4290f73b --- /dev/null +++ b/contract_recurring_invoicing_marker/static/description/icon.svg @@ -0,0 +1,320 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + Openclipart + + + Pile of Golden Coins + 2010-04-09T03:27:45 + A pile of hypothetical golden coins, drawn in Inkscape. + https://openclipart.org/detail/43969/pile-of-golden-coins-by-j_alves + + + J_Alves + + + + + coin + currency + gold + money + thaler + + + + + + + + + + + diff --git a/contract_recurring_invoicing_marker/tests/__init__.py b/contract_recurring_invoicing_marker/tests/__init__.py new file mode 100644 index 00000000..6e03ad9f --- /dev/null +++ b/contract_recurring_invoicing_marker/tests/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# (c) 2016 Serv. Tecnol. Avanzados - Pedro M. Baeza +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from . import test_contract_recurring_invoicing_marker diff --git a/contract_recurring_invoicing_marker/tests/test_contract_recurring_invoicing_marker.py b/contract_recurring_invoicing_marker/tests/test_contract_recurring_invoicing_marker.py new file mode 100644 index 00000000..607bb7db --- /dev/null +++ b/contract_recurring_invoicing_marker/tests/test_contract_recurring_invoicing_marker.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +# (c) 2016 Serv. Tecnol. Avanzados - Pedro M. Baeza +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +import openerp.tests.common as common + + +class TestContractRecurringInvoicingMarker(common.TransactionCase): + + def setUp(self): + super(TestContractRecurringInvoicingMarker, self).setUp() + self.partner = self.env['res.partner'].create({ + 'name': 'Test', + 'lang': 'en_US', + }) + self.product = self.env.ref('product.product_product_consultant') + self.uom = self.env.ref('product.product_uom_hour') + self.contract = self.env['account.analytic.account'].create({ + 'name': 'Test contract', + 'partner_id': self.partner.id, + 'type': 'contract', + 'recurring_invoices': 1, + 'recurring_next_date': '2016-01-01', + 'recurring_rule_type': 'monthly', + 'recurring_interval': 1, + 'recurring_invoice_line_ids': [ + (0, 0, {'quantity': 2.0, + 'price_unit': 100.0, + 'name': '#START# - #END#', + 'product_id': self.product.id, + 'uom_id': self.uom.id})], + }) + + def test_invoice_with_marker(self): + self.contract.recurring_create_invoice() + invoice = self.env['account.invoice'].search( + [('partner_id', '=', self.partner.id)]) + self.assertEqual( + invoice.invoice_line[0].name, u'01/01/2016 - 01/31/2016') diff --git a/contract_recurring_invoicing_marker/views/account_analytic_account_view.xml b/contract_recurring_invoicing_marker/views/account_analytic_account_view.xml new file mode 100644 index 00000000..5bc87358 --- /dev/null +++ b/contract_recurring_invoicing_marker/views/account_analytic_account_view.xml @@ -0,0 +1,20 @@ + + + + + + Contract form (with markers) + account.analytic.account + + + + +

#START#: Start date of the invoiced period

+

#END#: End date of the invoiced period

+
+
+
+
+ +
+