diff --git a/contract/README.rst b/contract/README.rst
index 84b6a6ba1..694e69915 100644
--- a/contract/README.rst
+++ b/contract/README.rst
@@ -63,8 +63,8 @@ Usage
* the recurrence parameters: interval (days, weeks, months, months last day or years),
start date, date of next invoice (automatically computed, can be modified) and end date (optional)
* auto-price, for having a price automatically obtained from the price list
- * #START# or #END# in the description field to display the start/end date of
- the invoiced period in the invoice line description
+ * #START# - #END# or #INVOICEMONTHNAME# in the description field to display
+ the start/end date or the start month of the invoiced period in the invoice line description
* pre-paid (invoice at period start) or post-paid (invoice at start of next period)
#. The "Generate Recurring Invoices from Contracts" cron runs daily to generate the invoices.
diff --git a/contract/models/contract_line.py b/contract/models/contract_line.py
index f1ca6f46e..ff4fbc4aa 100644
--- a/contract/models/contract_line.py
+++ b/contract/models/contract_line.py
@@ -596,6 +596,23 @@ class ContractLine(models.Model):
)
return first_date_invoiced, last_date_invoiced, recurring_next_date
+ def _translate_marker_month_name(self, month_name):
+ months = {
+ "January": _("January"),
+ "February": _("February"),
+ "March": _("March"),
+ "April": _("April"),
+ "May": _("May"),
+ "June": _("June"),
+ "July": _("July"),
+ "August": _("August"),
+ "September": _("September"),
+ "October": _("October"),
+ "November": _("November"),
+ "December": _("December"),
+ }
+ return months[month_name]
+
def _insert_markers(self, first_date_invoiced, last_date_invoiced):
self.ensure_one()
lang_obj = self.env["res.lang"]
@@ -604,6 +621,12 @@ class ContractLine(models.Model):
name = self.name
name = name.replace("#START#", first_date_invoiced.strftime(date_format))
name = name.replace("#END#", last_date_invoiced.strftime(date_format))
+ name = name.replace(
+ "#INVOICEMONTHNAME#",
+ self.with_context(lang=lang.code)._translate_marker_month_name(
+ first_date_invoiced.strftime("%B")
+ ),
+ )
return name
def _update_recurring_next_date(self):
diff --git a/contract/readme/USAGE.rst b/contract/readme/USAGE.rst
index 7257cf153..072e87e68 100644
--- a/contract/readme/USAGE.rst
+++ b/contract/readme/USAGE.rst
@@ -10,8 +10,8 @@
* the recurrence parameters: interval (days, weeks, months, months last day or years),
start date, date of next invoice (automatically computed, can be modified) and end date (optional)
* auto-price, for having a price automatically obtained from the price list
- * #START# or #END# in the description field to display the start/end date of
- the invoiced period in the invoice line description
+ * #START# - #END# or #INVOICEMONTHNAME# in the description field to display
+ the start/end date or the start month of the invoiced period in the invoice line description
* pre-paid (invoice at period start) or post-paid (invoice at start of next period)
#. The "Generate Recurring Invoices from Contracts" cron runs daily to generate the invoices.
diff --git a/contract/static/description/index.html b/contract/static/description/index.html
index d15721f88..6a22f0b38 100644
--- a/contract/static/description/index.html
+++ b/contract/static/description/index.html
@@ -8,11 +8,10 @@
/*
:Author: David Goodger (goodger@python.org)
-:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
+:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
-Despite the name, some widely supported CSS2 features are used.
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
@@ -275,7 +274,7 @@ pre.literal-block, pre.doctest-block, pre.math, pre.code {
margin-left: 2em ;
margin-right: 2em }
-pre.code .ln { color: gray; } /* line numbers */
+pre.code .ln { color: grey; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
@@ -301,7 +300,7 @@ span.option {
span.pre {
white-space: pre }
-span.problematic, pre.problematic {
+span.problematic {
color: red }
span.section-subtitle {
@@ -409,8 +408,8 @@ user access rights.
the recurrence parameters: interval (days, weeks, months, months last day or years),
start date, date of next invoice (automatically computed, can be modified) and end date (optional)
auto-price, for having a price automatically obtained from the price list
-#START# or #END# in the description field to display the start/end date of
-the invoiced period in the invoice line description
+#START# - #END# or #INVOICEMONTHNAME# in the description field to display
+the start/end date or the start month of the invoiced period in the invoice line description
pre-paid (invoice at period start) or post-paid (invoice at start of next period)
@@ -497,9 +496,7 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
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.
diff --git a/contract/tests/test_contract.py b/contract/tests/test_contract.py
index 8f756b4f2..8004c4158 100644
--- a/contract/tests/test_contract.py
+++ b/contract/tests/test_contract.py
@@ -8,6 +8,7 @@ from collections import namedtuple
from datetime import timedelta
from dateutil.relativedelta import relativedelta
+from freezegun import freeze_time
from odoo import fields
from odoo.exceptions import UserError, ValidationError
@@ -141,7 +142,7 @@ class TestContractBase(common.TransactionCase):
0,
{
"product_id": False,
- "name": "Header for Services",
+ "name": "Header for #INVOICEMONTHNAME# Services",
"display_type": "line_section",
},
),
@@ -2395,3 +2396,11 @@ class TestContract(TestContractBase):
action = self.contract.action_preview()
self.assertIn("/my/contracts/", action["url"])
self.assertIn("access_token=", action["url"])
+
+ @freeze_time("2023-05-01")
+ def test_check_month_name_marker(self):
+ """Set fixed date to check test correctly."""
+ self.contract3.contract_line_ids.date_start = fields.Date.today()
+ self.contract3.contract_line_ids.recurring_next_date = fields.Date.today()
+ invoice_id = self.contract3.recurring_create_invoice()
+ self.assertEqual(invoice_id.invoice_line_ids[0].name, "Header for May Services")
diff --git a/contract/views/contract.xml b/contract/views/contract.xml
index e4c9521ba..30d51f58c 100644
--- a/contract/views/contract.xml
+++ b/contract/views/contract.xml
@@ -452,6 +452,13 @@
the
invoiced period
+
+ #INVOICEMONTHNAME#
+ : Invoice month name
+ of
+ the
+ invoiced period
+
diff --git a/contract/views/contract_template.xml b/contract/views/contract_template.xml
index 75e6a0926..841bb5248 100644
--- a/contract/views/contract_template.xml
+++ b/contract/views/contract_template.xml
@@ -74,6 +74,8 @@
#START#: Start date of the invoiced period
#END#: End date of the invoiced period
+
#INVOICEMONTHNAME#: Invoice month name of the invoiced period