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] sale_confirm_activities_mandatory: Migration to 17.0 #3035

Open
wants to merge 3 commits into
base: 17.0
Choose a base branch
from
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
1 change: 1 addition & 0 deletions oca_dependencies.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
social
91 changes: 91 additions & 0 deletions sale_confirm_activities_mandatory/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
==============================================
Sale Order Activities Mandatory before confirm
==============================================

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

.. |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-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%2Fsale--workflow-lightgray.png?logo=github
:target: https://github.com/OCA/sale-workflow/tree/17.0/sale_confirm_activities_mandatory
: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_confirm_activities_mandatory
: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 allows to set a list of activities that must be achieved
before being able to confirm a sale order.

When all activities defined on the sale order are done, the sale order
can be confirm as usual.

**Table of contents**

.. contents::
:local:

Installation
============

You need to install *sale_management* module for accessing the needed
menus.

Usage
=====



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_confirm_activities_mandatory%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
-------

* Camptocamp

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

- Damien Crier <[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.

This module is part of the `OCA/sale-workflow <https://github.com/OCA/sale-workflow/tree/17.0/sale_confirm_activities_mandatory>`_ 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 sale_confirm_activities_mandatory/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
18 changes: 18 additions & 0 deletions sale_confirm_activities_mandatory/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2022 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

{
"name": "Sale Order Activities Mandatory before confirm",
"summary": "Set mandatory activities before confirm sale order",
"author": "Camptocamp, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/sale-workflow",
"category": "Sales",
"version": "17.0.1.0.0",
"license": "AGPL-3",
"depends": [
"sale",
"mail_activity_validation", # OCA/social
],
"data": [],
"installable": True,
}
3 changes: 3 additions & 0 deletions sale_confirm_activities_mandatory/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import mail_activity_mixin
from . import mail_thread
from . import sale_order
12 changes: 12 additions & 0 deletions sale_confirm_activities_mandatory/models/mail_activity_mixin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright 2022 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

from odoo import models


class MailActivityMixin(models.AbstractModel):
_inherit = "mail.activity.mixin"

def _check_validation_activities_todo(self):
acts = self.activity_ids
return not any(a.activity_category == "validation" for a in acts)
17 changes: 17 additions & 0 deletions sale_confirm_activities_mandatory/models/mail_thread.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2024 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

from odoo import models


class MailThread(models.AbstractModel):
_inherit = "mail.thread"

def _message_subscribe(self, partner_ids=None, subtype_ids=None, customer_ids=None):
# OVERRIDE to be able to skip followers subscribtion
# when create several mail activities
# otherwise mail_followers_res_partner_res_model_id_uniq is raised in test
# it has no impact on standard flow till context key is used
if self._context.get("mail_create_nosubscribe"):
return True
return super()._message_subscribe(partner_ids, subtype_ids, customer_ids)
67 changes: 67 additions & 0 deletions sale_confirm_activities_mandatory/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Copyright 2022 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

from odoo import _, api, models
from odoo.exceptions import UserError


class SaleOrder(models.Model):
_inherit = "sale.order"

def manage_activities(self):
# manage activities creation
activity_types = self.env["mail.activity.type"].search(
[
("res_model", "=", self._name),
("category", "=", "validation"),
("previous_type_ids", "=", False),
]
)
values = []
for order in self:
for activity_type in activity_types:
values.append(order._prepare_activity_data(activity_type))
if values:
self.env["mail.activity"].create(values)

@api.model_create_multi
def create(self, vals_list):
orders = super().create(vals_list)
orders.manage_activities()
return orders

def _prepare_activity_data(self, activity_type):
self.ensure_one()
return {
"res_id": self.id,
"res_model_id": self.env["ir.model"]._get(activity_type.res_model).id,
"activity_type_id": activity_type.id,
"summary": activity_type.summary,
"automated": True,
}

def action_confirm(self):
# check if some validation activities remain for each sale order
# given in self
# All done activities are unlinked
# (see _action_done of mail.activity model)
if not self._check_validation_activities_todo():
raise UserError(
_(
"All validation checks must be done before "
"confirming the sale order."
)
)
return super().action_confirm()

def action_draft(self):
res = super().action_draft()

Check warning on line 58 in sale_confirm_activities_mandatory/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

sale_confirm_activities_mandatory/models/sale_order.py#L58

Added line #L58 was not covered by tests
# delete old activities if necessary
acts = self.activity_ids.filtered(
lambda a: a.activity_type_id.category == "validation"
)
if acts:
acts.unlink()

Check warning on line 64 in sale_confirm_activities_mandatory/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

sale_confirm_activities_mandatory/models/sale_order.py#L64

Added line #L64 was not covered by tests
# generate new ones
self.manage_activities()
return res

Check warning on line 67 in sale_confirm_activities_mandatory/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

sale_confirm_activities_mandatory/models/sale_order.py#L66-L67

Added lines #L66 - L67 were not covered by tests
3 changes: 3 additions & 0 deletions sale_confirm_activities_mandatory/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 sale_confirm_activities_mandatory/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Damien Crier \<<[email protected]>\>
5 changes: 5 additions & 0 deletions sale_confirm_activities_mandatory/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This module allows to set a list of activities that must be achieved
before being able to confirm a sale order.

When all activities defined on the sale order are done, the sale order
can be confirm as usual.
2 changes: 2 additions & 0 deletions sale_confirm_activities_mandatory/readme/INSTALL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
You need to install *sale_management* module for accessing the needed
menus.
1 change: 1 addition & 0 deletions sale_confirm_activities_mandatory/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading
Loading