-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add contract_forecast and its sibling module commown_contract_forecast
- Loading branch information
Showing
15 changed files
with
199 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
**This file is going to be generated by oca-gen-addon-readme.** | ||
|
||
*Manual changes will be overwritten.* | ||
|
||
Please provide content in the ``readme`` directory: | ||
|
||
* **DESCRIPTION.rst** (required) | ||
* INSTALL.rst (optional) | ||
* CONFIGURE.rst (optional) | ||
* **USAGE.rst** (optional, highly recommended) | ||
* DEVELOP.rst (optional) | ||
* ROADMAP.rst (optional) | ||
* HISTORY.rst (optional, recommended) | ||
* **CONTRIBUTORS.rst** (optional, highly recommended) | ||
* CREDITS.rst (optional) | ||
|
||
Content of this README will also be drawn from the addon manifest, | ||
from keys such as name, authors, maintainers, development_status, | ||
and license. | ||
|
||
A good, one sentence summary in the manifest is also highly recommended. | ||
|
||
|
||
Automatic changelog generation | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
`HISTORY.rst` can be auto generated using `towncrier <https://pypi.org/project/towncrier>`_. | ||
|
||
Just put towncrier compatible changelog fragments into `readme/newsfragments` | ||
and the changelog file will be automatically generated and updated when a new fragment is added. | ||
|
||
Please refer to `towncrier` documentation to know more. | ||
|
||
NOTE: the changelog will be automatically generated when using `/ocabot merge $option`. | ||
If you need to run it manually, refer to `OCA/maintainer-tools README <https://github.com/OCA/maintainer-tools>`_. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright 2023 Commown SCIC | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0) | ||
|
||
{ | ||
"name": "Commown contract forecast integration", | ||
"summary": "Integrate the contract_forecast module into Commown odoo-based management software", | ||
"version": "12.0.1.0.0", | ||
"development_status": "Alpha", | ||
"category": "Accounting/Accounting", | ||
"website": "https://commown.coop", | ||
"author": "Commown SCIC", | ||
"maintainers": ["fcayre"], | ||
"license": "AGPL-3", | ||
"installable": True, | ||
"depends": [ | ||
"contract_forecast", | ||
"commown_contract_variable_discount", | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import contract_line | ||
from . import contract_line_forecast_period |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from odoo import _, api, models | ||
|
||
|
||
class ContractLine(models.Model): | ||
|
||
_inherit = "contract.line" | ||
|
||
@api.multi | ||
def _prepare_contract_line_forecast_period( | ||
self, period_date_start, period_date_end, recurring_next_date | ||
): | ||
values = super()._prepare_contract_line_forecast_period( | ||
period_date_start, | ||
period_date_end, | ||
recurring_next_date, | ||
) | ||
|
||
# By-pass cooperative campaigns discount computations | ||
discount_values = self.with_context(is_simulation=True).compute_discount( | ||
period_date_start | ||
) | ||
|
||
values["discount"] = discount_values["total"] | ||
if discount_values["descriptions"]: | ||
values["name"] += "\n" + ( | ||
_("Applied discounts:\n- %s") | ||
% "\n- ".join(discount_values["descriptions"]) | ||
) | ||
|
||
return values | ||
|
||
@api.model | ||
def _get_forecast_update_trigger_fields(self): | ||
fields = super()._get_forecast_update_trigger_fields() | ||
fields.remove("recurring_next_date") | ||
return fields |
15 changes: 15 additions & 0 deletions
15
commown_contract_forecast/models/contract_line_forecast_period.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from odoo import fields, models | ||
|
||
|
||
class ContractLineForecastPeriod(models.Model): | ||
|
||
_inherit = "contract.line.forecast.period" | ||
|
||
contract_template_id = fields.Many2one( | ||
comodel_name="contract.template", | ||
string="Contract template", | ||
readonly=True, | ||
related="contract_line_id.contract_id.contract_template_id", | ||
store=True, | ||
index=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
See contract_forecast setup instructions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* Florent Cayré <florent@commown.coop> https://commown.coop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
The development of this module has been financially supported by: | ||
|
||
* Commown SCIC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
This module extends the functionality of contract_forecast to integrate it with | ||
other Commown-specific modules and practices. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import test_contract_line |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Copyright 2023 Commown SCIC | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0) | ||
|
||
from odoo import fields | ||
|
||
from odoo.addons.contract.tests.test_contract import TestContractBase | ||
from odoo.addons.queue_job.tests.common import trap_jobs | ||
|
||
|
||
class ContractLineComputeForecastTC(TestContractBase): | ||
"""XXX maybe use a mixin from the contract_variable_discount module | ||
Also wondering if commown_contract_variable_discount would not be required here as | ||
cooperative campaigns have a specific behaviour in forecasts. | ||
""" | ||
|
||
def cdiscount(self, c_line=None, **kwargs): | ||
kwargs.setdefault("contract_line_id", (c_line or self.acct_line).id) | ||
return self.env["contract.discount.line"].create(kwargs) | ||
|
||
def set_cdiscounts(self, discounts): | ||
self.acct_line.specific_discount_line_ids = discounts | ||
|
||
def test_forecast_with_discount(self): | ||
"Check that forecast take discounts into account" | ||
|
||
self.set_cdiscounts( | ||
self.cdiscount( | ||
name="1 year loyalty", | ||
amount_type="percent", | ||
amount_value=10.0, | ||
start_reference="date_start", | ||
start_value=1, | ||
start_unit="years", | ||
end_type="relative", | ||
end_reference="date_start", | ||
end_value=2, | ||
end_unit="years", | ||
) | ||
| self.cdiscount( | ||
name="2 year loyalty", | ||
amount_type="percent", | ||
amount_value=20.0, | ||
start_reference="date_start", | ||
start_value=2, | ||
start_unit="years", | ||
end_type="absolute", | ||
end_value=False, # no end | ||
) | ||
) | ||
|
||
date = fields.Date.today() | ||
clines = self.contract.contract_line_ids | ||
clines.write({"recurring_next_date": date}) | ||
|
||
self.contract.partner_id.company_id.update( | ||
{ | ||
"enable_contract_forecast": True, | ||
"contract_forecast_rule_type": "monthly", | ||
"contract_forecast_interval": 36, | ||
} | ||
) | ||
|
||
self.assertFalse(self.contract.mapped("contract_line_ids.forecast_period_ids")) | ||
|
||
with trap_jobs() as trap: | ||
self.contract.date_start = date | ||
|
||
trap.assert_jobs_count(1, only=clines._generate_forecast_periods) | ||
trap.perform_enqueued_jobs() | ||
|
||
self.assertEqual( | ||
clines.mapped("forecast_period_ids").mapped("discount"), | ||
[0.0] * 12 + [10.0] * 12 + [20.0] * 12, | ||
) |
1 change: 1 addition & 0 deletions
1
setup/commown_contract_forecast/odoo/addons/commown_contract_forecast
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../commown_contract_forecast |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |