mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[IMP] Add INVOICEMONTHNAME marker to line description
[FIX] contract: Set fixed date to check test correctly. We need to set a fixed date for teststest_check_month_name_marker to check against the month of the date we are set (otherwise it would check against the month of today).
This commit is contained in:
@@ -64,12 +64,13 @@ Usage
|
|||||||
|
|
||||||
- the product with a description, a quantity and a price
|
- the product with a description, a quantity and a price
|
||||||
- the recurrence parameters: interval (days, weeks, months, months
|
- the recurrence parameters: interval (days, weeks, months, months
|
||||||
last day or years), start date, date of next invoice (automatically
|
last day or years), start date, date of next invoice
|
||||||
computed, can be modified) and end date (optional)
|
(automatically computed, can be modified) and end date (optional)
|
||||||
- auto-price, for having a price automatically obtained from the
|
- auto-price, for having a price automatically obtained from the
|
||||||
price list
|
price list
|
||||||
- #START# or #END# in the description field to display the start/end
|
- #START# - #END# or #INVOICEMONTHNAME# in the description field to
|
||||||
date of the invoiced period in the invoice line description
|
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
|
- pre-paid (invoice at period start) or post-paid (invoice at start
|
||||||
of next period)
|
of next period)
|
||||||
|
|
||||||
|
|||||||
@@ -595,6 +595,23 @@ class ContractLine(models.Model):
|
|||||||
)
|
)
|
||||||
return first_date_invoiced, last_date_invoiced, recurring_next_date
|
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):
|
def _insert_markers(self, first_date_invoiced, last_date_invoiced):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
lang_obj = self.env["res.lang"]
|
lang_obj = self.env["res.lang"]
|
||||||
@@ -603,6 +620,12 @@ class ContractLine(models.Model):
|
|||||||
name = self.name
|
name = self.name
|
||||||
name = name.replace("#START#", first_date_invoiced.strftime(date_format))
|
name = name.replace("#START#", first_date_invoiced.strftime(date_format))
|
||||||
name = name.replace("#END#", last_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
|
return name
|
||||||
|
|
||||||
def _update_recurring_next_date(self):
|
def _update_recurring_next_date(self):
|
||||||
|
|||||||
@@ -11,9 +11,9 @@
|
|||||||
(automatically computed, can be modified) and end date (optional)
|
(automatically computed, can be modified) and end date (optional)
|
||||||
- auto-price, for having a price automatically obtained from the
|
- auto-price, for having a price automatically obtained from the
|
||||||
price list
|
price list
|
||||||
- \#START# or \#END# in the description field to display the
|
- \#START# - \#END# or \#INVOICEMONTHNAME# in the description field
|
||||||
start/end date of the invoiced period in the invoice line
|
to display the start/end date or the start month of the invoiced
|
||||||
description
|
period in the invoice line description
|
||||||
- pre-paid (invoice at period start) or post-paid (invoice at start
|
- pre-paid (invoice at period start) or post-paid (invoice at start
|
||||||
of next period)
|
of next period)
|
||||||
4. The "Generate Recurring Invoices from Contracts" cron runs daily to
|
4. The "Generate Recurring Invoices from Contracts" cron runs daily to
|
||||||
|
|||||||
@@ -410,12 +410,13 @@ parameters:<ul>
|
|||||||
<li>And add the lines to be invoiced with:<ul>
|
<li>And add the lines to be invoiced with:<ul>
|
||||||
<li>the product with a description, a quantity and a price</li>
|
<li>the product with a description, a quantity and a price</li>
|
||||||
<li>the recurrence parameters: interval (days, weeks, months, months
|
<li>the recurrence parameters: interval (days, weeks, months, months
|
||||||
last day or years), start date, date of next invoice (automatically
|
last day or years), start date, date of next invoice
|
||||||
computed, can be modified) and end date (optional)</li>
|
(automatically computed, can be modified) and end date (optional)</li>
|
||||||
<li>auto-price, for having a price automatically obtained from the
|
<li>auto-price, for having a price automatically obtained from the
|
||||||
price list</li>
|
price list</li>
|
||||||
<li>#START# or #END# in the description field to display the start/end
|
<li>#START# - #END# or #INVOICEMONTHNAME# in the description field to
|
||||||
date of the invoiced period in the invoice line description</li>
|
display the start/end date or the start month of the invoiced
|
||||||
|
period in the invoice line description</li>
|
||||||
<li>pre-paid (invoice at period start) or post-paid (invoice at start
|
<li>pre-paid (invoice at period start) or post-paid (invoice at start
|
||||||
of next period)</li>
|
of next period)</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from collections import namedtuple
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
from dateutil.relativedelta import relativedelta
|
from dateutil.relativedelta import relativedelta
|
||||||
|
from freezegun import freeze_time
|
||||||
|
|
||||||
from odoo import fields
|
from odoo import fields
|
||||||
from odoo.exceptions import UserError, ValidationError
|
from odoo.exceptions import UserError, ValidationError
|
||||||
@@ -141,7 +142,7 @@ class TestContractBase(common.TransactionCase):
|
|||||||
0,
|
0,
|
||||||
{
|
{
|
||||||
"product_id": False,
|
"product_id": False,
|
||||||
"name": "Header for Services",
|
"name": "Header for #INVOICEMONTHNAME# Services",
|
||||||
"display_type": "line_section",
|
"display_type": "line_section",
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@@ -2385,3 +2386,11 @@ class TestContract(TestContractBase):
|
|||||||
self.assertEqual(len(self.contract._get_related_invoices()), 4)
|
self.assertEqual(len(self.contract._get_related_invoices()), 4)
|
||||||
self.contract.recurring_create_invoice()
|
self.contract.recurring_create_invoice()
|
||||||
self.assertEqual(len(self.contract._get_related_invoices()), 4)
|
self.assertEqual(len(self.contract._get_related_invoices()), 4)
|
||||||
|
|
||||||
|
@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")
|
||||||
|
|||||||
@@ -478,6 +478,13 @@
|
|||||||
the
|
the
|
||||||
invoiced period
|
invoiced period
|
||||||
</p>
|
</p>
|
||||||
|
<p colspan="2">
|
||||||
|
<strong>#INVOICEMONTHNAME#</strong>
|
||||||
|
: Invoice month name
|
||||||
|
of
|
||||||
|
the
|
||||||
|
invoiced period
|
||||||
|
</p>
|
||||||
</group>
|
</group>
|
||||||
</page>
|
</page>
|
||||||
</notebook>
|
</notebook>
|
||||||
|
|||||||
@@ -76,6 +76,8 @@
|
|||||||
<p> <strong
|
<p> <strong
|
||||||
>#START#</strong>: Start date of the invoiced period</p>
|
>#START#</strong>: Start date of the invoiced period</p>
|
||||||
<p> <strong>#END#</strong>: End date of the invoiced period</p>
|
<p> <strong>#END#</strong>: End date of the invoiced period</p>
|
||||||
|
<p> <strong
|
||||||
|
>#INVOICEMONTHNAME#</strong>: Invoice month name of the invoiced period</p>
|
||||||
</div>
|
</div>
|
||||||
</group>
|
</group>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
Reference in New Issue
Block a user