Skip to content

Commit

Permalink
Merge pull request #2237 from OCA/15.0
Browse files Browse the repository at this point in the history
Syncing from upstream OCA/sale-workflow (15.0)
  • Loading branch information
bt-admin authored Feb 1, 2025
2 parents d532d2b + e0352c9 commit 8414de0
Show file tree
Hide file tree
Showing 23 changed files with 806 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ addon | version | maintainers | summary
[sale_substate](sale_substate/) | 15.0.1.0.0 | | Sale Sub State
[sale_tier_validation](sale_tier_validation/) | 15.0.1.1.2 | | Extends the functionality of Sale Orders to support a tier validation process.
[sale_triple_discount](sale_triple_discount/) | 15.0.1.0.1 | | Manage triple discount on sale order lines
[sale_validity_auto_cancel](sale_validity_auto_cancel/) | 15.0.1.0.0 | [![JordiMForgeFlow](https://github.com/JordiMForgeFlow.png?size=30px)](https://github.com/JordiMForgeFlow) | Automatically cancel quotations after validity period.
[sale_warn_option](sale_warn_option/) | 15.0.1.0.1 | [![Shide](https://github.com/Shide.png?size=30px)](https://github.com/Shide) [![rafaelbn](https://github.com/rafaelbn.png?size=30px)](https://github.com/rafaelbn) | Add Options to Sale Warn Messages
[sale_wishlist](sale_wishlist/) | 15.0.1.0.1 | | Handle sale wishlist for partners
[sales_team_security](sales_team_security/) | 15.0.1.0.3 | [![pedrobaeza](https://github.com/pedrobaeza.png?size=30px)](https://github.com/pedrobaeza) [![ivantodorovich](https://github.com/ivantodorovich.png?size=30px)](https://github.com/ivantodorovich) | New group for seeing only sales channel's documents
Expand Down
99 changes: 99 additions & 0 deletions sale_validity_auto_cancel/README.rst
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.
3 changes: 3 additions & 0 deletions sale_validity_auto_cancel/__init__.py
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
16 changes: 16 additions & 0 deletions sale_validity_auto_cancel/__manifest__.py
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"],
}
17 changes: 17 additions & 0 deletions sale_validity_auto_cancel/data/ir_cron.xml
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 sale_validity_auto_cancel/i18n/sale_validity_auto_cancel.pot
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 ""
5 changes: 5 additions & 0 deletions sale_validity_auto_cancel/models/__init__.py
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
24 changes: 24 additions & 0 deletions sale_validity_auto_cancel/models/res_company.py
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.",
),
]
13 changes: 13 additions & 0 deletions sale_validity_auto_cancel/models/res_config_settings.py
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,
)
37 changes: 37 additions & 0 deletions sale_validity_auto_cancel/models/sale_order.py
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)))
1 change: 1 addition & 0 deletions sale_validity_auto_cancel/readme/CONFIGURE.rst
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.
1 change: 1 addition & 0 deletions sale_validity_auto_cancel/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Jordi Masvidal <[email protected]>
3 changes: 3 additions & 0 deletions sale_validity_auto_cancel/readme/DESCRIPTION.rst
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.
4 changes: 4 additions & 0 deletions sale_validity_auto_cancel/readme/USAGE.rst
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.
Loading

0 comments on commit 8414de0

Please sign in to comment.