Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions contract_min_duration/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

=========================
Contract Minimum Duration
=========================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:204d88cac556f56f9ea4f02945e1d0197b6507d0996b25137a9c4cda58a69c80
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fcontract-lightgray.png?logo=github
:target: https://github.com/OCA/contract/tree/19.0/contract_min_duration
:alt: OCA/contract
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/contract-19-0/contract-19-0-contract_min_duration
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/contract&target_branch=19.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module extends the **Contract** module to enforce a minimum
contract duration.

It adds a ``min_contract_end_date`` field to contracts. If a user
attempts to set an end date (e.g., via termination) that is earlier than
this minimum date, the system automatically extends the end date to the
minimum required date, ensuring the customer is invoiced for the full
minimum period.

**Table of contents**

.. contents::
:local:

Usage
=====

To use this module:

1. Go to **Accounting > Customers > Contracts**.
2. Open or create a contract.
3. In the **Dates** section (or wherever the field is placed), set the
**Minimum End Date**.
4. If you try to terminate the contract or set a **Date End** that is
**before** this minimum date, the system will automatically correct
the **Date End** to match the **Minimum End Date**.

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 to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/contract/issues/new?body=module:%20contract_min_duration%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* bosd

Contributors
------------

- bosd emiel.vanbokhoven@obs-solutions.com

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

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.

This module is part of the `OCA/contract <https://github.com/OCA/contract/tree/19.0/contract_min_duration>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions contract_min_duration/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
16 changes: 16 additions & 0 deletions contract_min_duration/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "Contract Minimum Duration",
"summary": "Enforce minimum contract duration",
"version": "19.0.1.0.0",
"category": "Accounting",
"website": "https://github.com/OCA/contract",
"author": "bosd, Odoo Community Association (OCA)",
"license": "AGPL-3",
"depends": [
"contract",
],
"data": [
"views/contract_view.xml",
],
"installable": True,
}
1 change: 1 addition & 0 deletions contract_min_duration/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import contract
50 changes: 50 additions & 0 deletions contract_min_duration/models/contract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright 2025 bosd
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class ContractContract(models.Model):
_inherit = "contract.contract"

min_contract_end_date = fields.Date(
string="Minimum End Date",
help="The contract cannot end before this date. "
"If a termination or end date is set earlier, "
"it will be automatically extended to this date.",
)

def write(self, vals):
if "date_end" not in vals and "min_contract_end_date" not in vals:
return super().write(vals)

for contract in self:
_vals = vals.copy()
min_date_str = (
_vals["min_contract_end_date"]
if "min_contract_end_date" in _vals
else contract.min_contract_end_date
)
end_date_str = (
_vals["date_end"] if "date_end" in _vals else contract.date_end
)

if min_date_str and end_date_str:
min_date = fields.Date.to_date(min_date_str)
end_date = fields.Date.to_date(end_date_str)
if end_date < min_date:
_vals["date_end"] = min_date_str
super(ContractContract, contract).write(_vals)
return True

@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
min_date_str = vals.get("min_contract_end_date")
end_date_str = vals.get("date_end")
if min_date_str and end_date_str:
min_date = fields.Date.to_date(min_date_str)
end_date = fields.Date.to_date(end_date_str)
if min_date and end_date and end_date < min_date:
vals["date_end"] = min_date_str
return super().create(vals_list)
3 changes: 3 additions & 0 deletions contract_min_duration/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
1 change: 1 addition & 0 deletions contract_min_duration/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* bosd <emiel.vanbokhoven@obs-solutions.com>
3 changes: 3 additions & 0 deletions contract_min_duration/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This module extends the **Contract** module to enforce a minimum contract duration.

It adds a `min_contract_end_date` field to contracts. If a user attempts to set an end date (e.g., via termination) that is earlier than this minimum date, the system automatically extends the end date to the minimum required date, ensuring the customer is invoiced for the full minimum period.
6 changes: 6 additions & 0 deletions contract_min_duration/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
To use this module:

1. Go to **Accounting > Customers > Contracts**.
2. Open or create a contract.
3. In the **Dates** section (or wherever the field is placed), set the **Minimum End Date**.
4. If you try to terminate the contract or set a **Date End** that is **before** this minimum date, the system will automatically correct the **Date End** to match the **Minimum End Date**.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading