From 428bcfb00c89c023b29fbac1af5282b33272f2fa Mon Sep 17 00:00:00 2001 From: Saran440 Date: Mon, 16 Dec 2024 14:39:56 +0700 Subject: [PATCH] [15.0][ADD] request_document_exception --- request_document_exception/README.rst | 60 +++ request_document_exception/__init__.py | 4 + request_document_exception/__manifest__.py | 18 + request_document_exception/models/__init__.py | 5 + .../models/exception_rule.py | 19 + .../models/request_document.py | 24 + .../models/request_request.py | 44 ++ request_document_exception/pyproject.toml | 3 + .../readme/CONTRIBUTORS.rst | 1 + .../readme/DESCRIPTION.rst | 1 + .../security/ir.model.access.csv | 2 + .../static/description/index.html | 416 ++++++++++++++++++ .../views/request_request_view.xml | 74 ++++ request_document_exception/wizard/__init__.py | 1 + .../wizard/request_exception_confirm.py | 19 + .../wizard/request_exception_confirm_view.xml | 11 + 16 files changed, 702 insertions(+) create mode 100644 request_document_exception/README.rst create mode 100644 request_document_exception/__init__.py create mode 100644 request_document_exception/__manifest__.py create mode 100644 request_document_exception/models/__init__.py create mode 100644 request_document_exception/models/exception_rule.py create mode 100644 request_document_exception/models/request_document.py create mode 100644 request_document_exception/models/request_request.py create mode 100644 request_document_exception/pyproject.toml create mode 100644 request_document_exception/readme/CONTRIBUTORS.rst create mode 100644 request_document_exception/readme/DESCRIPTION.rst create mode 100644 request_document_exception/security/ir.model.access.csv create mode 100644 request_document_exception/static/description/index.html create mode 100644 request_document_exception/views/request_request_view.xml create mode 100644 request_document_exception/wizard/__init__.py create mode 100644 request_document_exception/wizard/request_exception_confirm.py create mode 100644 request_document_exception/wizard/request_exception_confirm_view.xml diff --git a/request_document_exception/README.rst b/request_document_exception/README.rst new file mode 100644 index 0000000..eb1e02f --- /dev/null +++ b/request_document_exception/README.rst @@ -0,0 +1,60 @@ +============================ +Request Document - Exception +============================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:b878ce5aa176b7326e8d73f33a04da7bee313624e74af77ef285c43bc3dcc444 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-ecosoft--odoo%2Fecosoft--addons-lightgray.png?logo=github + :target: https://github.com/ecosoft-odoo/ecosoft-addons/tree/15.0/request_document_exception + :alt: ecosoft-odoo/ecosoft-addons + +|badge1| |badge2| |badge3| + +# TODO + +**Table of contents** + +.. contents:: + :local: + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Ecosoft + +Contributors +~~~~~~~~~~~~ + +* Saran Lim. + +Maintainers +~~~~~~~~~~~ + +This module is part of the `ecosoft-odoo/ecosoft-addons `_ project on GitHub. + +You are welcome to contribute. diff --git a/request_document_exception/__init__.py b/request_document_exception/__init__.py new file mode 100644 index 0000000..25aa51e --- /dev/null +++ b/request_document_exception/__init__.py @@ -0,0 +1,4 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import models +from . import wizard diff --git a/request_document_exception/__manifest__.py b/request_document_exception/__manifest__.py new file mode 100644 index 0000000..f06f7e7 --- /dev/null +++ b/request_document_exception/__manifest__.py @@ -0,0 +1,18 @@ +# Copyright 2024 Ecosoft Co., Ltd (https://ecosoft.co.th) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Request Document - Exception", + "version": "15.0.1.0.0", + "license": "AGPL-3", + "category": "Accounting & Finance", + "author": "Ecosoft, Odoo Community Association (OCA)", + "website": "https://github.com/ecosoft-odoo/ecosoft-addons", + "depends": ["request_document", "base_exception"], + "data": [ + "security/ir.model.access.csv", + "views/request_request_view.xml", + "wizard/request_exception_confirm_view.xml", + ], + "installable": True, +} diff --git a/request_document_exception/models/__init__.py b/request_document_exception/models/__init__.py new file mode 100644 index 0000000..57a25cb --- /dev/null +++ b/request_document_exception/models/__init__.py @@ -0,0 +1,5 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import exception_rule +from . import request_request +from . import request_document diff --git a/request_document_exception/models/exception_rule.py b/request_document_exception/models/exception_rule.py new file mode 100644 index 0000000..dacc0e7 --- /dev/null +++ b/request_document_exception/models/exception_rule.py @@ -0,0 +1,19 @@ +# Copyright 2024 Ecosoft Co., Ltd. (http://ecosoft.co.th) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ExceptionRule(models.Model): + _inherit = "exception.rule" + + request_request_ids = fields.Many2many( + comodel_name="request.request", string="Requests" + ) + model = fields.Selection( + selection_add=[ + ("request.request", "Request Sheet"), + ("request.document", "Request Document"), + ], + ondelete={"request.request": "cascade", "request.document": "cascade"}, + ) diff --git a/request_document_exception/models/request_document.py b/request_document_exception/models/request_document.py new file mode 100644 index 0000000..89e42c6 --- /dev/null +++ b/request_document_exception/models/request_document.py @@ -0,0 +1,24 @@ +# Copyright 2024 Ecosoft Co., Ltd. (http://ecosoft.co.th) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models + + +class RequestDocument(models.Model): + _name = "request.document" + _inherit = ["request.document", "base.exception.method"] + + ignore_exception = fields.Boolean( + related="request_id.ignore_exception", store=True, string="Ignore Exceptions" + ) + + @api.model + def _reverse_field(self): + return "request_request_ids" + + def _get_main_records(self): + return self.mapped("request_id") + + def _detect_exceptions(self, rule): + records = super()._detect_exceptions(rule) + return records.mapped("request_id") diff --git a/request_document_exception/models/request_request.py b/request_document_exception/models/request_request.py new file mode 100644 index 0000000..971f7d0 --- /dev/null +++ b/request_document_exception/models/request_request.py @@ -0,0 +1,44 @@ +# Copyright 2024 Ecosoft Co., Ltd. (http://ecosoft.co.th) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import api, models + + +class RequestRequest(models.Model): + _name = "request.request" + _inherit = ["request.request", "base.exception"] + + @api.model + def _reverse_field(self): + return "request_request_ids" + + def detect_exceptions(self): + all_exceptions = super().detect_exceptions() + lines = self.mapped("line_ids") + all_exceptions += lines.detect_exceptions() + return all_exceptions + + @api.onchange("line_ids") + def onchange_ignore_exception(self): + if self.state == "submit": + self.ignore_exception = False + + def action_submit(self): + if self.detect_exceptions() and not self.ignore_exception: + return self._popup_exceptions() + return super().action_submit() + + @api.model + def _get_popup_action(self): + action = self.env.ref( + "request_document_exception.action_request_exception_confirm" + ) + return action + + def action_draft(self): + res = super().action_draft() + for rec in self: + rec.exception_ids = False + rec.main_exception_id = False + rec.ignore_exception = False + return res diff --git a/request_document_exception/pyproject.toml b/request_document_exception/pyproject.toml new file mode 100644 index 0000000..4231d0c --- /dev/null +++ b/request_document_exception/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/request_document_exception/readme/CONTRIBUTORS.rst b/request_document_exception/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000..cc6b231 --- /dev/null +++ b/request_document_exception/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Saran Lim. diff --git a/request_document_exception/readme/DESCRIPTION.rst b/request_document_exception/readme/DESCRIPTION.rst new file mode 100644 index 0000000..4640904 --- /dev/null +++ b/request_document_exception/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +# TODO diff --git a/request_document_exception/security/ir.model.access.csv b/request_document_exception/security/ir.model.access.csv new file mode 100644 index 0000000..089cc4c --- /dev/null +++ b/request_document_exception/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_request_exception_confirm_user,access_request_exception_confirm_user,model_request_exception_confirm,base.group_user,1,1,1,1 diff --git a/request_document_exception/static/description/index.html b/request_document_exception/static/description/index.html new file mode 100644 index 0000000..4e116be --- /dev/null +++ b/request_document_exception/static/description/index.html @@ -0,0 +1,416 @@ + + + + + +Request Document - Exception + + + +
+

Request Document - Exception

+ + +

Beta License: AGPL-3 ecosoft-odoo/ecosoft-addons

+

# TODO

+

Table of contents

+ +
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Ecosoft
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is part of the ecosoft-odoo/ecosoft-addons project on GitHub.

+

You are welcome to contribute.

+
+
+
+ + diff --git a/request_document_exception/views/request_request_view.xml b/request_document_exception/views/request_request_view.xml new file mode 100644 index 0000000..3f14720 --- /dev/null +++ b/request_document_exception/views/request_request_view.xml @@ -0,0 +1,74 @@ + + + + view.request.request.tree + request.request + + + + + + + + + view.request.request.form + request.request + + + + + + + + + + + + + + + Request Exception Rules + exception.rule + tree,form + + [('model', 'in', ['request.request', 'request.document'])] + {'active_test': False, 'default_model' : 'request.request'} + + + diff --git a/request_document_exception/wizard/__init__.py b/request_document_exception/wizard/__init__.py new file mode 100644 index 0000000..00853c6 --- /dev/null +++ b/request_document_exception/wizard/__init__.py @@ -0,0 +1 @@ +from . import request_exception_confirm diff --git a/request_document_exception/wizard/request_exception_confirm.py b/request_document_exception/wizard/request_exception_confirm.py new file mode 100644 index 0000000..65f9f2f --- /dev/null +++ b/request_document_exception/wizard/request_exception_confirm.py @@ -0,0 +1,19 @@ +# Copyright 2024 Ecosoft Co., Ltd. (http://ecosoft.co.th) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class RequestExceptionConfirm(models.TransientModel): + _name = "request.exception.confirm" + _description = "Request exception wizard" + _inherit = ["exception.rule.confirm"] + + related_model_id = fields.Many2one(comodel_name="request.request", string="Request") + + def action_confirm(self): + self.ensure_one() + if self.ignore: + self.related_model_id.ignore_exception = True + self.related_model_id.action_submit() + return super().action_confirm() diff --git a/request_document_exception/wizard/request_exception_confirm_view.xml b/request_document_exception/wizard/request_exception_confirm_view.xml new file mode 100644 index 0000000..700e653 --- /dev/null +++ b/request_document_exception/wizard/request_exception_confirm_view.xml @@ -0,0 +1,11 @@ + + + + Outstanding exceptions to manage + ir.actions.act_window + request.exception.confirm + form + + new + +