Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[17.0][MIG/IMP] sale_validity_auto_cancel: Migration to 17.0 #3204

Merged
merged 8 commits into from
Jul 29, 2024
Merged
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
108 changes: 108 additions & 0 deletions sale_validity_auto_cancel/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
=========================
Sale Validity Auto-Cancel
=========================

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

.. |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/17.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-17-0/sale-workflow-17-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=17.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:%2017.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
* OERP Canada

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

- Jordi Masvidal <[email protected]>
- `OERP Canada <https://www.oerp.ca/>`__:

- Foram Darji <[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/17.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
21 changes: 21 additions & 0 deletions sale_validity_auto_cancel/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2023 ForgeFlow S.L.
# Copyright 2024 OERP Canada <https://www.oerp.ca>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

{
"name": "Sale Validity Auto-Cancel",
"version": "17.0.1.0.0",
"category": "Sales",
"license": "LGPL-3",
"summary": "Automatically cancel quotations after validity period.",
"depends": ["sale_management"],
"author": "ForgeFlow, OERP Canada, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/sale-workflow",
"data": [
"data/ir_cron.xml",
"views/res_config_settings.xml",
"views/res_partner_views.xml",
],
"installable": True,
"maintainers": ["JordiMForgeFlow"],
}
18 changes: 18 additions & 0 deletions sale_validity_auto_cancel/data/ir_cron.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2023 ForgeFlow S.L.
Copyright 2024 OERP Canada <https://www.oerp.ca>
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>
94 changes: 94 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,94 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * sale_validity_auto_cancel
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 17.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-07-02 19:37+0000\n"
"PO-Revision-Date: 2024-07-02 19:37+0000\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> days</span>"
msgstr ""

#. module: sale_validity_auto_cancel
#: model:ir.model.fields,field_description:sale_validity_auto_cancel.field_sale_order__auto_cancel_expired_so
msgid "Auto Cancel"
msgstr ""

#. module: sale_validity_auto_cancel
#: model:ir.model.fields,field_description:sale_validity_auto_cancel.field_res_partner__auto_cancel_expired_so
#: model:ir.model.fields,field_description:sale_validity_auto_cancel.field_res_users__auto_cancel_expired_so
msgid "Auto Cancel Expired SaleOrder"
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
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:ir.model,name:sale_validity_auto_cancel.model_res_partner
msgid "Contact"
msgstr ""

#. module: sale_validity_auto_cancel
#: model:ir.model.fields,help:sale_validity_auto_cancel.field_res_partner__auto_cancel_expired_so
#: model:ir.model.fields,help:sale_validity_auto_cancel.field_res_users__auto_cancel_expired_so
#: model:ir.model.fields,help:sale_validity_auto_cancel.field_sale_order__auto_cancel_expired_so
msgid ""
"If unchecked, you will be able to restrict this contact's expired SO from "
"being auto-canceled."
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 ""
6 changes: 6 additions & 0 deletions sale_validity_auto_cancel/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from . import res_company
from . import res_config_settings
from . import res_partner
from . import sale_order
25 changes: 25 additions & 0 deletions sale_validity_auto_cancel/models/res_company.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2023 ForgeFlow S.L.
# Copyright 2024 OERP Canada <https://www.oerp.ca>
# 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.",
),
]
14 changes: 14 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,14 @@
# Copyright 2023 ForgeFlow S.L.
# Copyright 2024 OERP Canada <https://www.oerp.ca>
# 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,
)
16 changes: 16 additions & 0 deletions sale_validity_auto_cancel/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2023 ForgeFlow S.L.
# Copyright 2024 OERP Canada <https://www.oerp.ca>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class ResPartner(models.Model):
_inherit = "res.partner"

auto_cancel_expired_so = fields.Boolean(
string="Auto Cancel Expired SaleOrder",
default=True,
help="If unchecked, you will be able to restrict \n"
"this contact's expired SO from being auto-canceled.",
)
42 changes: 42 additions & 0 deletions sale_validity_auto_cancel/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright 2023 ForgeFlow S.L.
# Copyright 2024 OERP Canada <https://www.oerp.ca>
# 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"

auto_cancel_expired_so = fields.Boolean(
related="partner_id.auto_cancel_expired_so", string="Auto Cancel"
)

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),
("auto_cancel_expired_so", "=", True),
]
)
for order in orders:
try:
order.with_context(company_id=company.id)._action_cancel()
except Exception as e:
_logger.error("Failed to auto-cancel %s: %s", (order.name, str(e)))

Check warning on line 42 in sale_validity_auto_cancel/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

sale_validity_auto_cancel/models/sale_order.py#L41-L42

Added lines #L41 - L42 were not covered by tests
3 changes: 3 additions & 0 deletions sale_validity_auto_cancel/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
3 changes: 3 additions & 0 deletions sale_validity_auto_cancel/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Go to the menu *Sale \> Configuration \> Settings*, in the section
*Quotations & Sales*, set the *Auto-cancel expired quotations after* in
days.
3 changes: 3 additions & 0 deletions sale_validity_auto_cancel/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Jordi Masvidal \<<[email protected]>\>
- [OERP Canada](https://www.oerp.ca/):
- Foram Darji \<<[email protected]>\>
5 changes: 5 additions & 0 deletions sale_validity_auto_cancel/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
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.
5 changes: 5 additions & 0 deletions sale_validity_auto_cancel/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
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
Loading