forked from OCA/sale-workflow
-
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.
Merge pull request #2237 from OCA/15.0
Syncing from upstream OCA/sale-workflow (15.0)
- Loading branch information
Showing
23 changed files
with
806 additions
and
1 deletion.
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,99 @@ | ||
========================= | ||
Sale Validity Auto-Cancel | ||
========================= | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:55d4197d188e6eee2871ac6d9a8ad0325e32d499bce0781356613ac65d2b3e16 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |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/licence-LGPL--3-blue.png | ||
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html | ||
:alt: License: LGPL-3 | ||
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github | ||
:target: https://github.com/OCA/sale-workflow/tree/15.0/sale_validity_auto_cancel | ||
:alt: OCA/sale-workflow | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/sale-workflow-15-0/sale-workflow-15-0-sale_validity_auto_cancel | ||
: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/sale-workflow&target_branch=15.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module adds a scheduled action that automatically cancels quotations after their expiration date. | ||
|
||
A company setting can be modified to decide how many days after the expiration date the quotations are automatically cancelled. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Configuration | ||
============= | ||
|
||
Go to the menu *Sale > Configuration > Settings*, in the section *Quotations & Sales*, set the *Auto-cancel expired quotations after* in days. | ||
|
||
Usage | ||
===== | ||
|
||
By default, the scheduled action *Cancel Expired Quotations* is not enabled in order to | ||
first configure the setting parameter for the number of days. | ||
|
||
Once enabled, the scheduled action will run automatically once a day. | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/sale-workflow/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/sale-workflow/issues/new?body=module:%20sale_validity_auto_cancel%0Aversion:%2015.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 | ||
~~~~~~~ | ||
|
||
* ForgeFlow | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* Jordi Masvidal <[email protected]> | ||
|
||
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. | ||
|
||
.. |maintainer-JordiMForgeFlow| image:: https://github.com/JordiMForgeFlow.png?size=40px | ||
:target: https://github.com/JordiMForgeFlow | ||
:alt: JordiMForgeFlow | ||
|
||
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__: | ||
|
||
|maintainer-JordiMForgeFlow| | ||
|
||
This module is part of the `OCA/sale-workflow <https://github.com/OCA/sale-workflow/tree/15.0/sale_validity_auto_cancel>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
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 @@ | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
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,16 @@ | ||
# Copyright 2023 ForgeFlow S.L. | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
{ | ||
"name": "Sale Validity Auto-Cancel", | ||
"version": "15.0.1.0.0", | ||
"category": "Sales", | ||
"license": "LGPL-3", | ||
"summary": "Automatically cancel quotations after validity period.", | ||
"depends": ["sale_management"], | ||
"author": "ForgeFlow, Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/sale-workflow", | ||
"data": ["data/ir_cron.xml", "views/res_config_settings.xml"], | ||
"installable": True, | ||
"maintainers": ["JordiMForgeFlow"], | ||
} |
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,17 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<!-- Copyright 2023 ForgeFlow S.L. | ||
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
--> | ||
<odoo noupdate="1"> | ||
<record model="ir.cron" id="cron_sale_validity_auto_cancel"> | ||
<field name="name">Cancel Expired Quotations</field> | ||
<field name="interval_number">1</field> | ||
<field name="interval_type">days</field> | ||
<field name="numbercall">-1</field> | ||
<field name="active">False</field> | ||
<field name="doall" eval="False" /> | ||
<field name="model_id" ref="model_sale_order" /> | ||
<field name="state">code</field> | ||
<field name="code">model.cron_sale_validity_auto_cancel()</field> | ||
</record> | ||
</odoo> |
69 changes: 69 additions & 0 deletions
69
sale_validity_auto_cancel/i18n/sale_validity_auto_cancel.pot
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,69 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * sale_validity_auto_cancel | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 15.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"Last-Translator: \n" | ||
"Language-Team: \n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: \n" | ||
"Plural-Forms: \n" | ||
|
||
#. module: sale_validity_auto_cancel | ||
#: model_terms:ir.ui.view,arch_db:sale_validity_auto_cancel.res_config_settings_view_form | ||
msgid "<span style=\"margin-left: 5px;\">Days</span>" | ||
msgstr "" | ||
|
||
#. module: sale_validity_auto_cancel | ||
#: model:ir.model.fields,field_description:sale_validity_auto_cancel.field_res_company__sale_validity_auto_cancel_days | ||
#: model:ir.model.fields,field_description:sale_validity_auto_cancel.field_res_config_settings__sale_validity_auto_cancel_days | ||
msgid "Auto-cancel expired quotations after (days)" | ||
msgstr "" | ||
|
||
#. module: sale_validity_auto_cancel | ||
#: model:ir.actions.server,name:sale_validity_auto_cancel.cron_sale_validity_auto_cancel_ir_actions_server | ||
#: model:ir.cron,cron_name:sale_validity_auto_cancel.cron_sale_validity_auto_cancel | ||
#: model:ir.cron,name:sale_validity_auto_cancel.cron_sale_validity_auto_cancel | ||
msgid "Cancel Expired Quotations" | ||
msgstr "" | ||
|
||
#. module: sale_validity_auto_cancel | ||
#: model:ir.model,name:sale_validity_auto_cancel.model_res_company | ||
msgid "Companies" | ||
msgstr "" | ||
|
||
#. module: sale_validity_auto_cancel | ||
#: model:ir.model,name:sale_validity_auto_cancel.model_res_config_settings | ||
msgid "Config Settings" | ||
msgstr "" | ||
|
||
#. module: sale_validity_auto_cancel | ||
#: model_terms:ir.ui.view,arch_db:sale_validity_auto_cancel.res_config_settings_view_form | ||
msgid "" | ||
"Quotations will be automatically cancelled after the expiration date plus " | ||
"the number of days specified." | ||
msgstr "" | ||
|
||
#. module: sale_validity_auto_cancel | ||
#: model:ir.model.fields,help:sale_validity_auto_cancel.field_res_company__sale_validity_auto_cancel_days | ||
#: model:ir.model.fields,help:sale_validity_auto_cancel.field_res_config_settings__sale_validity_auto_cancel_days | ||
msgid "" | ||
"Quotations will be cancelled after the specified number of days since the " | ||
"expiration date." | ||
msgstr "" | ||
|
||
#. module: sale_validity_auto_cancel | ||
#: model:ir.model,name:sale_validity_auto_cancel.model_sale_order | ||
msgid "Sales Order" | ||
msgstr "" | ||
|
||
#. module: sale_validity_auto_cancel | ||
#: model:ir.model.constraint,message:sale_validity_auto_cancel.constraint_res_company_sale_validity_auto_cancel_days_positive | ||
msgid "" | ||
"The value of the field 'Auto-cancel expired quotations after' must be " | ||
"positive or 0." | ||
msgstr "" |
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,5 @@ | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
from . import res_company | ||
from . import res_config_settings | ||
from . import sale_order |
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,24 @@ | ||
# Copyright 2023 ForgeFlow S.L. | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class ResCompany(models.Model): | ||
_inherit = "res.company" | ||
|
||
sale_validity_auto_cancel_days = fields.Integer( | ||
string="Auto-cancel expired quotations after (days)", | ||
default=0, | ||
help="Quotations will be cancelled after the specified number of" | ||
" days since the expiration date.", | ||
) | ||
|
||
_sql_constraints = [ | ||
( | ||
"sale_validity_auto_cancel_days_positive", | ||
"CHECK (sale_validity_auto_cancel_days >= 0)", | ||
"The value of the field 'Auto-cancel expired quotations after' " | ||
"must be positive or 0.", | ||
), | ||
] |
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,13 @@ | ||
# Copyright 2023 ForgeFlow S.L. | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class ResConfigSettings(models.TransientModel): | ||
_inherit = "res.config.settings" | ||
|
||
sale_validity_auto_cancel_days = fields.Integer( | ||
related="company_id.sale_validity_auto_cancel_days", | ||
readonly=False, | ||
) |
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,37 @@ | ||
# Copyright 2023 ForgeFlow S.L. | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
import logging | ||
|
||
from dateutil.relativedelta import relativedelta | ||
|
||
from odoo import fields, models | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
class SaleOrder(models.Model): | ||
_inherit = "sale.order" | ||
|
||
def _get_expired_order_states(self): | ||
# Can be inherited to exclude/include order states | ||
return ["draft", "sent"] | ||
|
||
def cron_sale_validity_auto_cancel(self): | ||
today = fields.Date.today() | ||
for company in self.env["res.company"].search([]): | ||
threshold = today - relativedelta( | ||
days=company.sale_validity_auto_cancel_days | ||
) | ||
expired_states = self._get_expired_order_states() | ||
orders = self.env["sale.order"].search( | ||
[ | ||
("state", "in", expired_states), | ||
("validity_date", "<", threshold), | ||
("company_id", "=", company.id), | ||
] | ||
) | ||
for order in orders.with_company(company.id): | ||
try: | ||
order._action_cancel() | ||
except Exception as e: | ||
_logger.error("Failed to auto-cancel %s: %s" % (order.name, str(e))) |
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 @@ | ||
Go to the menu *Sale > Configuration > Settings*, in the section *Quotations & Sales*, set the *Auto-cancel expired quotations after* in days. |
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 @@ | ||
* Jordi Masvidal <[email protected]> |
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 @@ | ||
This module adds a scheduled action that automatically cancels quotations after their expiration date. | ||
|
||
A company setting can be modified to decide how many days after the expiration date the quotations are automatically cancelled. |
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,4 @@ | ||
By default, the scheduled action *Cancel Expired Quotations* is not enabled in order to | ||
first configure the setting parameter for the number of days. | ||
|
||
Once enabled, the scheduled action will run automatically once a day. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.