diff --git a/stock_exception/README.rst b/stock_exception/README.rst new file mode 100644 index 00000000000..8f4a1c7399c --- /dev/null +++ b/stock_exception/README.rst @@ -0,0 +1,88 @@ +=============== +Stock Exception +=============== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:9b8183c2a60002050aaae57962c63dba0c1d30762d8cc7f0f8273f52c62135a3 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fstock--logistics--warehouse-lightgray.png?logo=github + :target: https://github.com/OCA/stock-logistics-warehouse/tree/18.0/stock_exception + :alt: OCA/stock-logistics-warehouse +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-18-0/stock-logistics-warehouse-18-0-stock_exception + :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/stock-logistics-warehouse&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows you attach several customizable exceptions to your +stock picking in a way that you can filter pickings by exceptions type +and fix them. Exceptions are checked via a scheduled action as well as +during confirmation and validation. + +This is especially useful in an scenario for mass stock picking import, +because it's likely some pickings have errors when you import them (like +product not found in Odoo, wrong line format etc.) + +**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 +------------ + +- Tharathip Chaweewongphan + +- Open Source Integrators http://www.opensourceintegrators.com + + - Urvisha Desai udesai@opensourceintegrators.com + - Nikul Chaudhary nchaudhary@opensourceintegrators.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. + +This module is part of the `OCA/stock-logistics-warehouse `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/stock_exception/__init__.py b/stock_exception/__init__.py new file mode 100644 index 00000000000..346c779680a --- /dev/null +++ b/stock_exception/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) + +from . import models, wizard diff --git a/stock_exception/__manifest__.py b/stock_exception/__manifest__.py new file mode 100644 index 00000000000..ecac6c094b8 --- /dev/null +++ b/stock_exception/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2021 Ecosoft Co., Ltd (https://ecosoft.co.th) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) + +{ + "name": "Stock Exception", + "summary": "Custom exceptions on stock picking", + "version": "18.0.1.0.0", + "category": "Generic Modules/Warehouse Management", + "author": "Ecosoft, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/stock-logistics-warehouse", + "depends": ["stock", "base_exception"], + "license": "AGPL-3", + "data": [ + "security/ir.model.access.csv", + "data/stock_exception_data.xml", + "wizard/stock_exception_confirm_view.xml", + "views/stock_view.xml", + ], + "installable": True, +} diff --git a/stock_exception/data/stock_exception_data.xml b/stock_exception/data/stock_exception_data.xml new file mode 100644 index 00000000000..b046af107cc --- /dev/null +++ b/stock_exception/data/stock_exception_data.xml @@ -0,0 +1,31 @@ + + + + Stock: Test Draft Pickings Exception + + code + model.test_all_draft_pickings() + + 20 + minutes + + + + No Partner + No Partner + 50 + stock.picking + if not self.partner_id: + failed=True + + + + Demand Quantity not positive + Demand quantity must be positive + 50 + stock.move + if self.product_uom_qty <= 0: + failed=True + + + diff --git a/stock_exception/i18n/es.po b/stock_exception/i18n/es.po new file mode 100644 index 00000000000..e9cb6ef3c1a --- /dev/null +++ b/stock_exception/i18n/es.po @@ -0,0 +1,31 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_exception +# +# Translators: +# Matias Velazquez +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2022-06-28 22:06+0000\n" +"PO-Revision-Date: 2023-09-03 00:15+0000\n" +"Last-Translator: Matias Velazquez \n" +"Language-Team: \n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: stock_exception +#: model:ir.model.fields,field_description:stock_exception.field_exception_rule__check_on_confirm +msgid "Check On Confirm" +msgstr "Chequear al Confirmar" + +#. module: stock_exception +#: model:ir.model.fields,field_description:stock_exception.field_exception_rule__check_on_validate +msgid "Check On Validate" +msgstr "Chequear al Validar" diff --git a/stock_exception/i18n/it.po b/stock_exception/i18n/it.po new file mode 100644 index 00000000000..cad9f97d25f --- /dev/null +++ b/stock_exception/i18n/it.po @@ -0,0 +1,175 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_exception +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: Automatically generated\n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" + +#. module: stock_exception +#: model_terms:ir.ui.view,arch_db:stock_exception.view_picking_form +msgid "There are exceptions blocking this stock picking:" +msgstr "" + +#. module: stock_exception +#: model:ir.model.fields,field_description:stock_exception.field_exception_rule__model +msgid "Apply on" +msgstr "" + +#. module: stock_exception +#: model_terms:ir.ui.view,arch_db:stock_exception.view_picking_internal_search +msgid "Blocked in Draft" +msgstr "" + +#. module: stock_exception +#: model_terms:ir.ui.view,arch_db:stock_exception.view_picking_form +msgid "" +"Click here to be able to confirm this stock picking regardless of the " +"exceptions." +msgstr "" + +#. module: stock_exception +#: model:ir.model.fields,field_description:stock_exception.field_stock_exception_confirm__create_uid +msgid "Created by" +msgstr "" + +#. module: stock_exception +#: model:ir.model.fields,field_description:stock_exception.field_stock_exception_confirm__create_date +msgid "Created on" +msgstr "" + +#. module: stock_exception +#: model:exception.rule,name:stock_exception.sm_excep_product_uom_qty_check +msgid "Demand Quantity not positive" +msgstr "" + +#. module: stock_exception +#: model:exception.rule,description:stock_exception.sm_excep_product_uom_qty_check +msgid "Demand quantity must be positive" +msgstr "" + +#. module: stock_exception +#: model:ir.model.fields,field_description:stock_exception.field_exception_rule__display_name +#: model:ir.model.fields,field_description:stock_exception.field_stock_exception_confirm__display_name +#: model:ir.model.fields,field_description:stock_exception.field_stock_move__display_name +#: model:ir.model.fields,field_description:stock_exception.field_stock_picking__display_name +msgid "Display Name" +msgstr "" + +#. module: stock_exception +#: model:ir.model,name:stock_exception.model_exception_rule +msgid "Exception Rule" +msgstr "" + +#. module: stock_exception +#: model:ir.model.fields,field_description:stock_exception.field_stock_picking__exception_ids +msgid "Exceptions" +msgstr "" + +#. module: stock_exception +#: model:ir.model.fields,field_description:stock_exception.field_stock_picking__exceptions_summary +msgid "Exceptions Summary" +msgstr "" + +#. module: stock_exception +#: model:ir.model.fields,field_description:stock_exception.field_stock_exception_confirm__exception_ids +msgid "Exceptions to resolve" +msgstr "" + +#. module: stock_exception +#: model:ir.model.fields,field_description:stock_exception.field_exception_rule__id +#: model:ir.model.fields,field_description:stock_exception.field_stock_exception_confirm__id +#: model:ir.model.fields,field_description:stock_exception.field_stock_move__id +#: model:ir.model.fields,field_description:stock_exception.field_stock_picking__id +msgid "ID" +msgstr "" + +#. module: stock_exception +#: model:ir.model.fields,field_description:stock_exception.field_stock_exception_confirm__ignore +#: model:ir.model.fields,field_description:stock_exception.field_stock_move__ignore_exception +#: model:ir.model.fields,field_description:stock_exception.field_stock_picking__ignore_exception +#: model_terms:ir.ui.view,arch_db:stock_exception.view_picking_form +msgid "Ignore Exceptions" +msgstr "" + +#. module: stock_exception +#: model:ir.model.fields,field_description:stock_exception.field_exception_rule____last_update +#: model:ir.model.fields,field_description:stock_exception.field_stock_exception_confirm____last_update +#: model:ir.model.fields,field_description:stock_exception.field_stock_move____last_update +#: model:ir.model.fields,field_description:stock_exception.field_stock_picking____last_update +msgid "Last Modified on" +msgstr "" + +#. module: stock_exception +#: model:ir.model.fields,field_description:stock_exception.field_stock_exception_confirm__write_uid +msgid "Last Updated by" +msgstr "" + +#. module: stock_exception +#: model:ir.model.fields,field_description:stock_exception.field_stock_exception_confirm__write_date +msgid "Last Updated on" +msgstr "" + +#. module: stock_exception +#: model:ir.model.fields,field_description:stock_exception.field_stock_picking__main_exception_id +msgid "Main Exception" +msgstr "" + +#. module: stock_exception +#: model:exception.rule,description:stock_exception.sp_excep_no_partner +#: model:exception.rule,name:stock_exception.sp_excep_no_partner +msgid "No Partner" +msgstr "" + +#. module: stock_exception +#: model:ir.actions.act_window,name:stock_exception.action_stock_exception_confirm +msgid "Outstanding exceptions to manage" +msgstr "" + +#. module: stock_exception +#: model:ir.model.fields,field_description:stock_exception.field_exception_rule__picking_ids +msgid "Pickings" +msgstr "" + +#. module: stock_exception +#: model:ir.actions.act_window,name:stock_exception.action_stock_test_tree +#: model:ir.ui.menu,name:stock_exception.menu_stock_test +msgid "Stock Exception Rules" +msgstr "" + +#. module: stock_exception +#: model:ir.model,name:stock_exception.model_stock_move +#: model:ir.model.fields.selection,name:stock_exception.selection__exception_rule__model__stock_move +msgid "Stock Move" +msgstr "" + +#. module: stock_exception +#: model:ir.model.fields,field_description:stock_exception.field_stock_exception_confirm__related_model_id +#: model:ir.model.fields.selection,name:stock_exception.selection__exception_rule__model__stock_picking +msgid "Stock Picking" +msgstr "" + +#. module: stock_exception +#: model:ir.model,name:stock_exception.model_stock_exception_confirm +msgid "Stock exception wizard" +msgstr "" + +#. module: stock_exception +#: model:ir.actions.server,name:stock_exception.ir_cron_test_stock_picking_except_ir_actions_server +#: model:ir.cron,cron_name:stock_exception.ir_cron_test_stock_picking_except +#: model:ir.cron,name:stock_exception.ir_cron_test_stock_picking_except +msgid "Stock: Test Draft Pickings Exception" +msgstr "" + +#. module: stock_exception +#: model:ir.model,name:stock_exception.model_stock_picking +msgid "Transfer" +msgstr "" diff --git a/stock_exception/i18n/stock_exception.pot b/stock_exception/i18n/stock_exception.pot new file mode 100644 index 00000000000..78ef3754327 --- /dev/null +++ b/stock_exception/i18n/stock_exception.pot @@ -0,0 +1,164 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_exception +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.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: stock_exception +#: model_terms:ir.ui.view,arch_db:stock_exception.view_picking_form +msgid "There are exceptions blocking this stock picking:" +msgstr "" + +#. module: stock_exception +#: model:ir.model.fields,field_description:stock_exception.field_exception_rule__model +msgid "Apply on" +msgstr "" + +#. module: stock_exception +#: model_terms:ir.ui.view,arch_db:stock_exception.view_picking_internal_search +msgid "Blocked in Draft" +msgstr "" + +#. module: stock_exception +#: model_terms:ir.ui.view,arch_db:stock_exception.view_picking_form +msgid "" +"Click here to be able to confirm this stock picking regardless of the " +"exceptions." +msgstr "" + +#. module: stock_exception +#: model:ir.model.fields,field_description:stock_exception.field_stock_exception_confirm__create_uid +msgid "Created by" +msgstr "" + +#. module: stock_exception +#: model:ir.model.fields,field_description:stock_exception.field_stock_exception_confirm__create_date +msgid "Created on" +msgstr "" + +#. module: stock_exception +#: model:exception.rule,name:stock_exception.sm_excep_product_uom_qty_check +msgid "Demand Quantity not positive" +msgstr "" + +#. module: stock_exception +#: model:exception.rule,description:stock_exception.sm_excep_product_uom_qty_check +msgid "Demand quantity must be positive" +msgstr "" + +#. module: stock_exception +#: model:ir.model.fields,field_description:stock_exception.field_stock_exception_confirm__display_name +msgid "Display Name" +msgstr "" + +#. module: stock_exception +#: model:ir.model,name:stock_exception.model_exception_rule +msgid "Exception Rule" +msgstr "" + +#. module: stock_exception +#: model:ir.model.fields,field_description:stock_exception.field_stock_picking__exception_ids +msgid "Exceptions" +msgstr "" + +#. module: stock_exception +#: model:ir.model.fields,field_description:stock_exception.field_stock_picking__exceptions_summary +msgid "Exceptions Summary" +msgstr "" + +#. module: stock_exception +#: model:ir.model.fields,field_description:stock_exception.field_stock_exception_confirm__exception_ids +msgid "Exceptions to resolve" +msgstr "" + +#. module: stock_exception +#: model:ir.model.fields,field_description:stock_exception.field_stock_exception_confirm__id +msgid "ID" +msgstr "" + +#. module: stock_exception +#: model:ir.model.fields,field_description:stock_exception.field_stock_exception_confirm__ignore +#: model:ir.model.fields,field_description:stock_exception.field_stock_move__ignore_exception +#: model:ir.model.fields,field_description:stock_exception.field_stock_picking__ignore_exception +#: model_terms:ir.ui.view,arch_db:stock_exception.view_picking_form +msgid "Ignore Exceptions" +msgstr "" + +#. module: stock_exception +#: model:ir.model.fields,field_description:stock_exception.field_stock_exception_confirm____last_update +msgid "Last Modified on" +msgstr "" + +#. module: stock_exception +#: model:ir.model.fields,field_description:stock_exception.field_stock_exception_confirm__write_uid +msgid "Last Updated by" +msgstr "" + +#. module: stock_exception +#: model:ir.model.fields,field_description:stock_exception.field_stock_exception_confirm__write_date +msgid "Last Updated on" +msgstr "" + +#. module: stock_exception +#: model:ir.model.fields,field_description:stock_exception.field_stock_picking__main_exception_id +msgid "Main Exception" +msgstr "" + +#. module: stock_exception +#: model:exception.rule,description:stock_exception.sp_excep_no_partner +#: model:exception.rule,name:stock_exception.sp_excep_no_partner +msgid "No Partner" +msgstr "" + +#. module: stock_exception +#: model:ir.actions.act_window,name:stock_exception.action_stock_exception_confirm +msgid "Outstanding exceptions to manage" +msgstr "" + +#. module: stock_exception +#: model:ir.model.fields,field_description:stock_exception.field_exception_rule__picking_ids +msgid "Pickings" +msgstr "" + +#. module: stock_exception +#: model:ir.actions.act_window,name:stock_exception.action_stock_test_tree +#: model:ir.ui.menu,name:stock_exception.menu_stock_test +msgid "Stock Exception Rules" +msgstr "" + +#. module: stock_exception +#: model:ir.model,name:stock_exception.model_stock_move +#: model:ir.model.fields.selection,name:stock_exception.selection__exception_rule__model__stock_move +msgid "Stock Move" +msgstr "" + +#. module: stock_exception +#: model:ir.model.fields,field_description:stock_exception.field_stock_exception_confirm__related_model_id +#: model:ir.model.fields.selection,name:stock_exception.selection__exception_rule__model__stock_picking +msgid "Stock Picking" +msgstr "" + +#. module: stock_exception +#: model:ir.model,name:stock_exception.model_stock_exception_confirm +msgid "Stock exception wizard" +msgstr "" + +#. module: stock_exception +#: model:ir.actions.server,name:stock_exception.ir_cron_test_stock_picking_except_ir_actions_server +#: model:ir.cron,cron_name:stock_exception.ir_cron_test_stock_picking_except +msgid "Stock: Test Draft Pickings Exception" +msgstr "" + +#. module: stock_exception +#: model:ir.model,name:stock_exception.model_stock_picking +msgid "Transfer" +msgstr "" diff --git a/stock_exception/models/__init__.py b/stock_exception/models/__init__.py new file mode 100644 index 00000000000..2ea20c65418 --- /dev/null +++ b/stock_exception/models/__init__.py @@ -0,0 +1,5 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) + +from . import exception_rule +from . import stock +from . import stock_move diff --git a/stock_exception/models/exception_rule.py b/stock_exception/models/exception_rule.py new file mode 100644 index 00000000000..f47aa828cd6 --- /dev/null +++ b/stock_exception/models/exception_rule.py @@ -0,0 +1,17 @@ +# Copyright 2021 Ecosoft Co., Ltd (https://ecosoft.co.th) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) + +from odoo import fields, models + + +class ExceptionRule(models.Model): + _inherit = "exception.rule" + + picking_ids = fields.Many2many(comodel_name="stock.picking", string="Pickings") + model = fields.Selection( + selection_add=[ + ("stock.picking", "Stock Picking"), + ("stock.move", "Stock Move"), + ], + ondelete={"stock.picking": "cascade", "stock.move": "cascade"}, + ) diff --git a/stock_exception/models/stock.py b/stock_exception/models/stock.py new file mode 100644 index 00000000000..5e690b112c1 --- /dev/null +++ b/stock_exception/models/stock.py @@ -0,0 +1,55 @@ +# Copyright 2021 Ecosoft Co., Ltd (https://ecosoft.co.th) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) + +from odoo import api, models + + +class StockPicking(models.Model): + _inherit = ["stock.picking", "base.exception"] + _name = "stock.picking" + + @api.model + def test_all_draft_pickings(self): + picking_set = self.search([("state", "=", "draft")]) + picking_set.detect_exceptions() + return True + + @api.model + def _reverse_field(self): + return "picking_ids" + + def detect_exceptions(self): + all_exceptions = super().detect_exceptions() + moves = self.mapped("move_ids") + all_exceptions += moves.detect_exceptions() + return all_exceptions + + @api.constrains("ignore_exception", "move_ids", "state") + def stock_check_exception(self): + pickings = self.filtered( + lambda s: s.state in ["waiting", "confirmed", "assigned"] + ) + if pickings: + pickings._check_exception() + + @api.onchange("move_ids") + def onchange_ignore_exception(self): + if self.state in ["waiting", "confirmed", "assigned"]: + self.ignore_exception = False + + def action_confirm(self): + for rec in self: + if rec.detect_exceptions() and not rec.ignore_exception: + return rec._popup_exceptions() + return super().action_confirm() + + def button_validate(self): + for rec in self: + if rec.detect_exceptions() and not rec.ignore_exception: + return rec._popup_exceptions() + return super().button_validate() + + @api.model + def _get_popup_action(self): + action = self.env.ref("stock_exception.action_stock_exception_confirm") + return action diff --git a/stock_exception/models/stock_move.py b/stock_exception/models/stock_move.py new file mode 100644 index 00000000000..3e1bb7980e0 --- /dev/null +++ b/stock_exception/models/stock_move.py @@ -0,0 +1,24 @@ +# Copyright 2021 Ecosoft Co., Ltd (https://ecosoft.co.th) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) + +from odoo import api, fields, models + + +class StockMove(models.Model): + _inherit = ["stock.move", "base.exception.method"] + _name = "stock.move" + + ignore_exception = fields.Boolean( + related="picking_id.ignore_exception", store=True, string="Ignore Exceptions" + ) + + def _get_main_records(self): + return self.mapped("picking_id") + + @api.model + def _reverse_field(self): + return "picking_ids" + + def _detect_exceptions(self, rule): + records = super()._detect_exceptions(rule) + return records.mapped("picking_id") diff --git a/stock_exception/pyproject.toml b/stock_exception/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/stock_exception/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/stock_exception/readme/CONTRIBUTORS.md b/stock_exception/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..6363b1da165 --- /dev/null +++ b/stock_exception/readme/CONTRIBUTORS.md @@ -0,0 +1,6 @@ +- Tharathip Chaweewongphan \<\> + +* Open Source Integrators + + * Urvisha Desai + * Nikul Chaudhary diff --git a/stock_exception/readme/DESCRIPTION.md b/stock_exception/readme/DESCRIPTION.md new file mode 100644 index 00000000000..1769072b43b --- /dev/null +++ b/stock_exception/readme/DESCRIPTION.md @@ -0,0 +1,8 @@ +This module allows you attach several customizable exceptions to your +stock picking in a way that you can filter pickings by exceptions type +and fix them. Exceptions are checked via a scheduled action as well as +during confirmation and validation. + +This is especially useful in an scenario for mass stock picking import, +because it's likely some pickings have errors when you import them (like +product not found in Odoo, wrong line format etc.) diff --git a/stock_exception/security/ir.model.access.csv b/stock_exception/security/ir.model.access.csv new file mode 100644 index 00000000000..cf442317547 --- /dev/null +++ b/stock_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_stock_exception_confirm,access_stock_exception_confirm,model_stock_exception_confirm,base.group_user,1,1,1,1 diff --git a/stock_exception/static/description/icon.png b/stock_exception/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/stock_exception/static/description/icon.png differ diff --git a/stock_exception/static/description/index.html b/stock_exception/static/description/index.html new file mode 100644 index 00000000000..7bba19144c4 --- /dev/null +++ b/stock_exception/static/description/index.html @@ -0,0 +1,434 @@ + + + + + +Stock Exception + + + +
+

Stock Exception

+ + +

Beta License: AGPL-3 OCA/stock-logistics-warehouse Translate me on Weblate Try me on Runboat

+

This module allows you attach several customizable exceptions to your +stock picking in a way that you can filter pickings by exceptions type +and fix them. Exceptions are checked via a scheduled action as well as +during confirmation and validation.

+

This is especially useful in an scenario for mass stock picking import, +because it’s likely some pickings have errors when you import them (like +product not found in Odoo, wrong line format etc.)

+

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 maintained by the OCA.

+ +Odoo Community Association + +

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/stock-logistics-warehouse project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/stock_exception/tests/__init__.py b/stock_exception/tests/__init__.py new file mode 100644 index 00000000000..dd7a6cf2606 --- /dev/null +++ b/stock_exception/tests/__init__.py @@ -0,0 +1 @@ +from . import test_stock_exception diff --git a/stock_exception/tests/test_stock_exception.py b/stock_exception/tests/test_stock_exception.py new file mode 100644 index 00000000000..8027f6988fc --- /dev/null +++ b/stock_exception/tests/test_stock_exception.py @@ -0,0 +1,113 @@ +# Copyright 2024 Open Source Integrators +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) +from odoo.tests import Form +from odoo.tests.common import TransactionCase + + +class TestStockException(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.res_users_model = cls.env["res.users"] + cls.product_model = cls.env["product.product"] + cls.exception_rule = cls.env["exception.rule"] + + cls.uom_unit = cls.env.ref("uom.product_uom_unit") + cls.picking_type_id = cls.env.ref("stock.picking_type_out") + cls.stock_location = cls.env.ref("stock.stock_location_stock") + cls.customer_location = cls.env.ref("stock.stock_location_customers") + + # Create a product: + cls.product_1 = cls.product_model.create( + { + "name": "Test Product 1", + "type": "consu", + "default_code": "PROD1", + "uom_id": cls.uom_unit.id, + } + ) + + # Create a Picking: + cls.picking = cls.env["stock.picking"].create( + { + "location_id": cls.stock_location.id, + "location_dest_id": cls.customer_location.id, + "picking_type_id": cls.picking_type_id.id, + "move_ids": [ + ( + 0, + 0, + { + "name": cls.product_1.name, + "product_id": cls.product_1.id, + "product_uom_qty": 1, + "product_uom": cls.product_1.uom_id.id, + "location_id": cls.stock_location.id, + "location_dest_id": cls.customer_location.id, + }, + ) + ], + } + ) + + def test01_confirm_picking_fail_by_py(self): + self.stock_exception = self.exception_rule.create( + { + "name": "No Partner", + "sequence": 10, + "model": "stock.picking", + "exception_type": "by_py_code", + "code": "if not self.partner_id: failed=True", + } + ) + exception_action = self.picking.action_confirm() + self.assertEqual(exception_action.get("res_model"), "stock.exception.confirm") + self.assertTrue(self.picking.exceptions_summary) + self.assertTrue(self.picking.exception_ids) + rules = self.env["exception.rule"].browse(self.picking.exception_ids.ids) + self.assertIn(self.picking.id, rules.mapped("picking_ids.id")) + + self.picking.button_validate() + self.assertTrue(self.picking.exceptions_summary) + + # Test ignore exception make possible for the picking to validate + self.assertEqual(self.picking.state, "draft") + self.picking.action_ignore_exceptions() + self.assertTrue(self.picking.ignore_exception) + self.assertFalse(self.picking.exceptions_summary) + self.picking.action_confirm() + self.assertEqual(self.picking.state, "assigned") + + def test02_confirm_picking_fail_by_domain(self): + self.exception_method = self.env["exception.rule"].create( + { + "name": "No Partner", + "sequence": 11, + "model": "stock.picking", + "domain": "[('partner_id', '=', False)]", + "exception_type": "by_domain", + } + ) + exception_action = self.picking.action_confirm() + self.assertEqual(exception_action.get("res_model"), "stock.exception.confirm") + self.assertTrue(self.picking.exceptions_summary) + self.assertTrue(self.picking.exception_ids) + exception_form = Form( + self.env["stock.exception.confirm"].with_context( + **exception_action.get("context") + ), + ) + stock_exception = exception_form.save() + stock_exception.ignore = True + stock_exception.action_confirm() + + def test03_call_picking_method(self): + self.env["stock.picking"].test_all_draft_pickings() + self.env["stock.picking"]._reverse_field() + self.picking.move_ids._get_main_records() + self.picking.move_ids._reverse_field() + + def test_confirm_picking(self): + self.assertEqual(self.picking.state, "draft") + self.picking.action_confirm() + self.assertEqual(self.picking.state, "assigned") diff --git a/stock_exception/views/stock_view.xml b/stock_exception/views/stock_view.xml new file mode 100644 index 00000000000..ef9800ecf25 --- /dev/null +++ b/stock_exception/views/stock_view.xml @@ -0,0 +1,82 @@ + + + Stock Exception Rules + exception.rule + tree,form + + [('model', 'in', ['stock.picking', 'stock.move', 'stock.move.line'])] + {'active_test': False, 'default_model' : 'stock.picking'} + + + + stock_exception.view_picking_form + stock.picking + + + + + + + + + + + + + stock_exception.vpicktree + stock.picking + + + + + + + + + stock_exception.view_picking_internal_search + stock.picking + + + + + + + + + diff --git a/stock_exception/wizard/__init__.py b/stock_exception/wizard/__init__.py new file mode 100644 index 00000000000..db10bd01b72 --- /dev/null +++ b/stock_exception/wizard/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) + +from . import stock_exception_confirm diff --git a/stock_exception/wizard/stock_exception_confirm.py b/stock_exception/wizard/stock_exception_confirm.py new file mode 100644 index 00000000000..0c3e2964cde --- /dev/null +++ b/stock_exception/wizard/stock_exception_confirm.py @@ -0,0 +1,19 @@ +# Copyright 2021 Ecosoft Co., Ltd (https://ecosoft.co.th) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) + +from odoo import fields, models + + +class StockExceptionConfirm(models.TransientModel): + _name = "stock.exception.confirm" + _description = "Stock exception wizard" + _inherit = ["exception.rule.confirm"] + + related_model_id = fields.Many2one("stock.picking", "Stock Picking") + + def action_confirm(self): + self.ensure_one() + if self.ignore: + self.related_model_id.ignore_exception = True + self.related_model_id.action_confirm() + return super().action_confirm() diff --git a/stock_exception/wizard/stock_exception_confirm_view.xml b/stock_exception/wizard/stock_exception_confirm_view.xml new file mode 100644 index 00000000000..40734ca4b99 --- /dev/null +++ b/stock_exception/wizard/stock_exception_confirm_view.xml @@ -0,0 +1,10 @@ + + + Outstanding exceptions to manage + ir.actions.act_window + stock.exception.confirm + form + + new + +