Skip to content

Commit

Permalink
[16.0][ADD] base_tier_validation_on_update
Browse files Browse the repository at this point in the history
  • Loading branch information
Kev-Roche committed May 23, 2024
1 parent aa1d758 commit ebc33e7
Show file tree
Hide file tree
Showing 19 changed files with 1,483 additions and 0 deletions.
92 changes: 92 additions & 0 deletions base_tier_validation_on_update/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
==============================
Base Tier Validation On Update
==============================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:53aed95bc3c9bce9d89d3ddeda2890bd342e774478f9025cb9f94925c0f49bc1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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%2Fserver--ux-lightgray.png?logo=github
:target: https://github.com/OCA/server-ux/tree/16.0/base_tier_validation_on_update
:alt: OCA/server-ux
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/server-ux-16-0/server-ux-16-0-base_tier_validation_on_update
: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/server-ux&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module allows a validation by a tier for modification on existings record.
It is a generic module like base_tier_validation.

**Table of contents**

.. contents::
:local:

Usage
=====

The process will be the same as a regular tier validation.
Add a new tier definition and configure it:
* set a "On update Type" if you want to select some particular fields or records to validate.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-ux/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/server-ux/issues/new?body=module:%20base_tier_validation_on_update%0Aversion:%2016.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
~~~~~~~

* Akretion

Contributors
~~~~~~~~~~~~

* Kévin Roche <kevin.roche@akretion.com>

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-Kev-Roche| image:: https://github.com/Kev-Roche.png?size=40px
:target: https://github.com/Kev-Roche
:alt: Kev-Roche

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-Kev-Roche|

This module is part of the `OCA/server-ux <https://github.com/OCA/server-ux/tree/16.0/base_tier_validation_on_update>`_ 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 base_tier_validation_on_update/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
24 changes: 24 additions & 0 deletions base_tier_validation_on_update/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2024 Akretion (https://www.akretion.com).
# @author Kévin Roche <kevin.roche@akretion.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Base Tier Validation On Update",
"summary": "Validation on record modification / update",
"version": "16.0.1.0.0",
"category": "TODO",
"website": "https://github.com/OCA/server-ux",
"author": "Akretion, Odoo Community Association (OCA)",
"license": "AGPL-3",
"maintainers": ["Kev-Roche"],
"application": False,
"installable": True,
"depends": [
"base_tier_validation",
],
"data": [
"views/tier_definition.xml",
"views/tier_review.xml",
"templates/tier_validation_templates.xml",
],
}
3 changes: 3 additions & 0 deletions base_tier_validation_on_update/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import tier_validation
from . import tier_definition
from . import tier_review
37 changes: 37 additions & 0 deletions base_tier_validation_on_update/models/tier_definition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright 2024 Akretion (https://www.akretion.com).
# @author Kévin Roche <kevin.roche@akretion.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models

UNSUPPORTED_FIELD_TYPES = ["binary", "serialized"]


class TierDefinition(models.Model):
_inherit = "tier.definition"

review_on_update = fields.Boolean()

on_update_type = fields.Selection(
selection=[
("all", "All Records, All Modifications"),
("records", "Selected Records, Selected Modifications"),
("fields", "All Records, Selected Modifications"),
],
default=None,
)

on_update_record_ids = fields.Many2many(
comodel_name="ir.model.data",
string="On Update Records",
domain="[('model', '=', model)]",
)

on_update_field_ids = fields.Many2many(
comodel_name="ir.model.fields",
string="On Update Fields",
relation="tier_definition_on_update_fields_rel",
column1="tier_definition_id",
column2="field_id",
domain="[('model_id', '=', model_id)]",
)
50 changes: 50 additions & 0 deletions base_tier_validation_on_update/models/tier_review.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright 2024 Akretion (https://www.akretion.com).
# @author Kévin Roche <kevin.roche@akretion.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class TierReview(models.Model):
_inherit = "tier.review"

review_on_update = fields.Boolean(
related="definition_id.review_on_update", readonly=True
)
on_update_type = fields.Selection(
related="definition_id.on_update_type", readonly=True
)

new_values = fields.Serialized(readonly=True)

def cancel_my_on_update_review(self):
self.ensure_one()
if (
self.status == "pending"
and self.review_on_update
and self.requested_by == self.env.user
):
self.unlink()
return True

def apply_update_on_record(self):
self.ensure_one()
# check if other reviews are pending on the same fields
# before applying the changes. Can be improved in the future
# to allow a more complex workflow.
if self.review_on_update:
pending_reviews = self.search(
[
("status", "=", "pending"),
("res_id", "=", self.res_id),
("id", "!=", self.id),
]
)
if pending_reviews:
return True
return (
self.env[self.model]
.with_context(skip_on_update_check=True)
.browse(self.res_id)
.write(self.new_values)
)

0 comments on commit ebc33e7

Please sign in to comment.