From ec860d5e6198977f52de889ba73128ff241737d4 Mon Sep 17 00:00:00 2001 From: Bilel Jouini Date: Fri, 16 May 2025 13:39:08 +0100 Subject: [PATCH 1/2] [MIG] contract: Migration to 18.0 --- contract/README.rst | 64 ++++++------- contract/models/contract_line.py | 9 ++ contract/static/description/index.html | 4 +- contract_line_successor/README.rst | 92 +++++++++---------- .../static/description/index.html | 6 +- contract_termination/README.rst | 60 ++++++------ .../static/description/index.html | 16 ++-- 7 files changed, 126 insertions(+), 125 deletions(-) diff --git a/contract/README.rst b/contract/README.rst index a724c0e36e..2d4236a444 100644 --- a/contract/README.rst +++ b/contract/README.rst @@ -57,22 +57,22 @@ Usage 2. When creating a contract, fill fields for selecting the invoicing parameters: - - a journal - - a price list (optional) + - a journal + - a price list (optional) 3. And add the lines to be invoiced with: - - the product with a description, a quantity and a price - - 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# - #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 product with a description, a quantity and a price + - 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# - #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) 4. The "Generate Recurring Invoices from Contracts" cron runs daily to generate the invoices. If you are in debug mode, you can click on the @@ -86,7 +86,7 @@ Usage price list and lines when creating a contract. To use it, just select the template on the contract and fields will be filled automatically. -- Contracts appear in portal to following users in every contract: +- Contracts appear in portal to following users in every contract: |image| @@ -101,8 +101,8 @@ Usage Known issues / Roadmap ====================== -- Recover states and others functional fields in Contracts. -- Add recurrence flag at template level. +- Recover states and others functional fields in Contracts. +- Add recurrence flag at template level. Bug Tracker =========== @@ -126,33 +126,33 @@ Authors Contributors ------------ -- Angel Moya +- Angel Moya -- Dave Lasley +- Dave Lasley -- Miquel Raïch +- Miquel Raïch -- Souheil Bejaoui +- Souheil Bejaoui -- Thomas Binsfeld +- Thomas Binsfeld -- Guillaume Vandamme +- Guillaume Vandamme -- Raphaël Reverdy +- Raphaël Reverdy -- `Tecnativa `__: +- `Tecnativa `__: - - Pedro M. Baeza - - Carlos Dauden - - Vicent Cubells - - Rafael Blasco - - Víctor Martínez + - Pedro M. Baeza + - Carlos Dauden + - Vicent Cubells + - Rafael Blasco + - Víctor Martínez -- Iván Antón +- Iván Antón -- `APSL `__: +- `APSL `__: - - Antoni Marroig + - Antoni Marroig Maintainers ----------- diff --git a/contract/models/contract_line.py b/contract/models/contract_line.py index ef6ac07412..57df9860a2 100644 --- a/contract/models/contract_line.py +++ b/contract/models/contract_line.py @@ -40,6 +40,7 @@ class ContractLine(models.Model): store=True, readonly=True, ) + product_id = fields.Many2one(index=True) @api.model def _compute_first_recurring_next_date( @@ -307,3 +308,11 @@ def _compute_price_unit(self): line.price_unit = pricelist._get_product_price(product, quantity=1) else: line.price_unit = line.specific_price + + @api.constrains("is_auto_renew", "auto_renew_interval") + def _check_auto_renew_interval(self): + for rec in self: + if rec.is_auto_renew and not rec.auto_renew_interval: + raise ValidationError( + _("Auto renew interval should be different then 0") + ) diff --git a/contract/static/description/index.html b/contract/static/description/index.html index 6950abf79a..2ec673c056 100644 --- a/contract/static/description/index.html +++ b/contract/static/description/index.html @@ -410,8 +410,8 @@

Usage

  • And add the lines to be invoiced with:
    • the product with a description, a quantity and a price
    • 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)
    • +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# - #END# or #INVOICEMONTHNAME# in the description field to diff --git a/contract_line_successor/README.rst b/contract_line_successor/README.rst index 58f012ad4e..c53f34085d 100644 --- a/contract_line_successor/README.rst +++ b/contract_line_successor/README.rst @@ -37,48 +37,47 @@ Contract Line Successor Features -------- -- **Successor and Predecessor Management** +- **Successor and Predecessor Management** - - Link contract lines with successor and predecessor lines. - - Plan successors automatically or manually after a stop or - suspension. + - Link contract lines with successor and predecessor lines. + - Plan successors automatically or manually after a stop or + suspension. -- **Contract Line Lifecycle States** +- **Contract Line Lifecycle States** - - Manage contract lines with the following computed states: + - Manage contract lines with the following computed states: - - ``Upcoming`` - - ``In-Progress`` - - ``To Renew`` - - ``Upcoming Close`` - - ``Closed`` - - ``Canceled`` + - ``Upcoming`` + - ``In-Progress`` + - ``To Renew`` + - ``Upcoming Close`` + - ``Closed`` + - ``Canceled`` -- **Lifecycle Operations** +- **Lifecycle Operations** - - Stop a contract line. - - Plan a successor for a contract line. - - Stop and plan a successor in one operation (useful for - suspensions). - - Cancel and un-cancel contract lines. - - Renew contract lines automatically (new line or extension). + - Stop a contract line. + - Plan a successor for a contract line. + - Stop and plan a successor in one operation (useful for suspensions). + - Cancel and un-cancel contract lines. + - Renew contract lines automatically (new line or extension). -- **Auto-Renewal Handling** +- **Auto-Renewal Handling** - - Auto-renewal based on company settings (extend existing line or - create a new one). - - Cron job to automate renewal of eligible contract lines. + - Auto-renewal based on company settings (extend existing line or + create a new one). + - Cron job to automate renewal of eligible contract lines. -- **Data Integrity and Validation** +- **Data Integrity and Validation** - - Prevent invalid successor or predecessor configurations. - - Validate state transitions and date overlaps. - - Ensure clean renewal and cancellation workflows. + - Prevent invalid successor or predecessor configurations. + - Validate state transitions and date overlaps. + - Ensure clean renewal and cancellation workflows. -- **Audit Trail** +- **Audit Trail** - - Automatic posting of chatter messages for lifecycle events like - stops, renewals, suspensions, cancellations, etc. + - Automatic posting of chatter messages for lifecycle events like + stops, renewals, suspensions, cancellations, etc. **Table of contents** @@ -88,19 +87,18 @@ Features Configuration ============= -- | **Auto-Renewal Strategy** - | In the company settings, define whether renewing a contract line: +- | **Auto-Renewal Strategy** + | In the company settings, define whether renewing a contract line: - - Extends the current line (updates ``date_end``), - - or creates a new successor contract line. + - Extends the current line (updates ``date_end``), + - or creates a new successor contract line. - | Field: - | ``Company > Configuration > Contracts > Create new contract line at renewal`` + | Field: + | ``Company > Configuration > Contracts > Create new contract line at renewal`` -- | **Scheduled Actions** - | Ensure the scheduled action ``Contract Line: Auto Renew`` is - activated if you want automatic renewal without manual - intervention. +- | **Scheduled Actions** + | Ensure the scheduled action ``Contract Line: Auto Renew`` is + activated if you want automatic renewal without manual intervention. Usage ===== @@ -110,12 +108,12 @@ Usage 2. Once enabled, you will have access to several actions at the contract line level: - - **Stop** a contract line and optionally **plan a successor**. - - **Handle temporary suspensions** and **resume** the contract line - after the suspension period. - - **Cancel** and **un-cancel** contract lines if necessary. - - **Renew** contract lines either by **extending** the current line - or by **creating a new successor line** automatically. + - **Stop** a contract line and optionally **plan a successor**. + - **Handle temporary suspensions** and **resume** the contract line + after the suspension period. + - **Cancel** and **un-cancel** contract lines if necessary. + - **Renew** contract lines either by **extending** the current line + or by **creating a new successor line** automatically. Bug Tracker =========== @@ -138,7 +136,7 @@ Authors Contributors ------------ -- Souheil Bejaoui souheil.bejaoui@acsone.eu (ACSONE SA/NV) +- Souheil Bejaoui souheil.bejaoui@acsone.eu (ACSONE SA/NV) Maintainers ----------- diff --git a/contract_line_successor/static/description/index.html b/contract_line_successor/static/description/index.html index b4131545fc..811be4ca93 100644 --- a/contract_line_successor/static/description/index.html +++ b/contract_line_successor/static/description/index.html @@ -401,8 +401,7 @@

      Features

    • Lifecycle Operations
      • Stop a contract line.
      • Plan a successor for a contract line.
      • -
      • Stop and plan a successor in one operation (useful for -suspensions).
      • +
      • Stop and plan a successor in one operation (useful for suspensions).
      • Cancel and un-cancel contract lines.
      • Renew contract lines automatically (new line or extension).
      @@ -453,8 +452,7 @@

      Configuration

    • Scheduled Actions
      Ensure the scheduled action Contract Line: Auto Renew is -activated if you want automatic renewal without manual -intervention.
      +activated if you want automatic renewal without manual intervention.
    diff --git a/contract_termination/README.rst b/contract_termination/README.rst index 75c4594474..d976e42fda 100644 --- a/contract_termination/README.rst +++ b/contract_termination/README.rst @@ -37,28 +37,28 @@ Contract Termination Features -------- -- **Terminate Contracts** +- **Terminate Contracts** - - Users with the appropriate rights can terminate active contracts. - - Capture a termination reason, comment, and termination date. + - Users with the appropriate rights can terminate active contracts. + - Capture a termination reason, comment, and termination date. -- **Update or Cancel Termination** +- **Update or Cancel Termination** - - Update termination details if needed. - - Cancel (reactivate) a terminated contract. + - Update termination details if needed. + - Cancel (reactivate) a terminated contract. -- **Contract Form Enhancements** +- **Contract Form Enhancements** - - Display an alert on terminated contracts with the reason and - comment. - - Hide or disable contract actions (e.g., Send) and fields on - terminated contracts. - - Set contract fields as read-only after termination. + - Display an alert on terminated contracts with the reason and + comment. + - Hide or disable contract actions (e.g., Send) and fields on + terminated contracts. + - Set contract fields as read-only after termination. -- **Permissions** +- **Permissions** - - Only users with the group ``Contract: Can Terminate Contracts`` - can terminate or cancel termination of contracts. + - Only users with the group ``Contract: Can Terminate Contracts`` can + terminate or cancel termination of contracts. **Table of contents** @@ -68,21 +68,20 @@ Features Configuration ============= -- **Define Termination Reasons** +- **Define Termination Reasons** - - Go to **Contracts > Configuration > Termination Reasons**. - - Create reasons for contract termination (e.g., Customer decision, - End of service). + - Go to **Contracts > Configuration > Termination Reasons**. + - Create reasons for contract termination (e.g., Customer decision, + End of service). -- **Assign Rights** +- **Assign Rights** - - Assign the group ``Can terminate contracts`` to users who should - be allowed to terminate contracts. + - Assign the group ``Can terminate contracts`` to users who should be + allowed to terminate contracts. -- **Optional** +- **Optional** - - Define whether a termination comment should be required per - reason. + - Define whether a termination comment should be required per reason. Usage ===== @@ -92,8 +91,8 @@ Usage 3. Provide the termination reason, comment, and date. 4. After termination: - - The contract becomes read-only. - - An alert banner shows the termination details. + - The contract becomes read-only. + - An alert banner shows the termination details. 5. If necessary, you can **Update Termination Details** or **Cancel Contract Termination** to reactivate the contract. @@ -119,10 +118,9 @@ Authors Contributors ------------ -- Firstname Lastname email.address@example.org (optional company - website url) -- Second Person second.person@example.org (optional company website - url) +- Firstname Lastname email.address@example.org (optional company website + url) +- Second Person second.person@example.org (optional company website url) Maintainers ----------- diff --git a/contract_termination/static/description/index.html b/contract_termination/static/description/index.html index bc811d68d0..cede1a3287 100644 --- a/contract_termination/static/description/index.html +++ b/contract_termination/static/description/index.html @@ -399,8 +399,8 @@

    Features

  • Permissions
      -
    • Only users with the group Contract: Can Terminate Contracts -can terminate or cancel termination of contracts.
    • +
    • Only users with the group Contract: Can Terminate Contracts can +terminate or cancel termination of contracts.
  • @@ -423,13 +423,12 @@

    Configuration

  • Assign Rights
      -
    • Assign the group Can terminate contracts to users who should -be allowed to terminate contracts.
    • +
    • Assign the group Can terminate contracts to users who should be +allowed to terminate contracts.
  • Optional
      -
    • Define whether a termination comment should be required per -reason.
    • +
    • Define whether a termination comment should be required per reason.
  • @@ -470,10 +469,9 @@

    Authors

    Contributors

    From 0e629a102958567a4194ca81ccfbb42b8d3d4950 Mon Sep 17 00:00:00 2001 From: Bilel Jouini Date: Mon, 26 May 2025 14:40:12 +0100 Subject: [PATCH 2/2] [FIX] contract_line_successor: Adding markup to messages --- .../models/contract_line.py | 49 ++++++++++++------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/contract_line_successor/models/contract_line.py b/contract_line_successor/models/contract_line.py index 2c4be20c15..f79bccfbbc 100644 --- a/contract_line_successor/models/contract_line.py +++ b/contract_line_successor/models/contract_line.py @@ -4,6 +4,7 @@ from datetime import timedelta from dateutil.relativedelta import relativedelta +from markupsafe import Markup from odoo import _, api, fields, models from odoo.exceptions import ValidationError @@ -433,11 +434,13 @@ def stop(self, date_end, manual_renew_needed=False, post_message=True): rec._prepare_value_for_stop(date_end, manual_renew_needed) ) if post_message: - msg = _( - """Contract line for %(product)s + msg = Markup( + _( + """Contract line for %(product)s stopped:
    - End: %(old_end)s -- %(new_end)s """ + ) ) % { "product": rec.name, "old_end": old_date_end, @@ -507,13 +510,15 @@ def plan_successor( rec.successor_contract_line_id = new_line contract_line |= new_line if post_message: - msg = _( - """Contract line for %(product)s + msg = Markup( + _( + """Contract line for %(product)s planned a successor:
    - Start: %(new_date_start)s
    - End: %(new_date_end)s """ + ) ) % { "product": rec.name, "new_date_start": new_line.date_start, @@ -610,13 +615,15 @@ def stop_plan_successor(self, date_start, date_end, is_auto_renew): is_auto_renew, post_message=False, ) - msg = _( - """Contract line for %(product)s + msg = Markup( + _( + """Contract line for %(product)s suspended:
    - Suspension Start: %(new_date_start)s
    - Suspension End: %(new_date_end)s """ + ) ) % { "product": rec.name, "new_date_start": date_start, @@ -630,11 +637,13 @@ def cancel(self): raise ValidationError(_("Cancel not allowed for this line")) for contract in self.mapped("contract_id"): lines = self.filtered(lambda line, c=contract: line.contract_id == c) - msg = _( - "Contract line canceled: %s", - "
    - ".join( - [f"{name}" for name in lines.mapped("name")] - ), + msg = Markup( + _( + "Contract line canceled: %s", + "
    - ".join( + [f"{name}" for name in lines.mapped("name")] + ), + ) ) contract.message_post(body=msg) self.mapped("predecessor_contract_line_id").write( @@ -647,11 +656,13 @@ def uncancel(self, recurring_next_date): raise ValidationError(_("Un-cancel not allowed for this line")) for contract in self.mapped("contract_id"): lines = self.filtered(lambda line, c=contract: line.contract_id == c) - msg = _( - "Contract line Un-canceled: %s", - "
    - ".join( - [f"{name}" for name in lines.mapped("name")] - ), + msg = Markup( + _( + "Contract line Un-canceled: %s", + "
    - ".join( + [f"{name}" for name in lines.mapped("name")] + ), + ) ) contract.message_post(body=msg) for rec in self: @@ -777,13 +788,15 @@ def renew(self): else: new_line = rec._renew_extend_line(date_end) res |= new_line - msg = _( - """Contract line for %(product)s + msg = Markup( + _( + """Contract line for %(product)s renewed:
    - Start: %(new_date_start)s
    - End: %(new_date_end)s """ + ) ) % { "product": rec.name, "new_date_start": date_start,