diff --git a/project_exception/__init__.py b/project_exception/__init__.py new file mode 100644 index 00000000..3616b300 --- /dev/null +++ b/project_exception/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- + +from . import models +from . import wizard \ No newline at end of file diff --git a/project_exception/__manifest__.py b/project_exception/__manifest__.py new file mode 100644 index 00000000..f892122d --- /dev/null +++ b/project_exception/__manifest__.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- + +{ + 'name': "Project Exception Rule", + + 'summary': """ + Module for Project Exception Rule""", + + 'description': """ + The ability to run and trigger exceptions to block the moving of a task based on rules + """, + + 'author': "Hibou Corp.", + 'website': "http://www.hibou.io/", + + # Categories can be used to filter modules in modules listing + # Check https://github.com/odoo/odoo/blob/15.0/odoo/addons/base/data/ir_module_category_data.xml + # for the full list + 'category': 'Generic Modules', + 'version': '15.0.1.0.0', + 'license': 'OPL-1', + + # any module necessary for this one to work correctly + 'depends': ['base_exception_user', 'project'], + + # always loaded + 'data': [ + 'security/ir.model.access.csv', + 'views/project_views.xml', + 'wizard/project_exception_confirm_views.xml', + ], + # only loaded in demonstration mode + 'demo': [ + 'demo/project_exception_demo.xml', + ], + 'installable': True, + 'auto_install': False, +} diff --git a/project_exception/demo/project_exception_demo.xml b/project_exception/demo/project_exception_demo.xml new file mode 100644 index 00000000..9a6b31a3 --- /dev/null +++ b/project_exception/demo/project_exception_demo.xml @@ -0,0 +1,13 @@ + + + + + No Project Id + No Project Id + 50 + project + if not project_id: failed=True + + + + diff --git a/project_exception/models/__init__.py b/project_exception/models/__init__.py new file mode 100644 index 00000000..5305644d --- /dev/null +++ b/project_exception/models/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import models \ No newline at end of file diff --git a/project_exception/models/models.py b/project_exception/models/models.py new file mode 100644 index 00000000..885bab9e --- /dev/null +++ b/project_exception/models/models.py @@ -0,0 +1,44 @@ +# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details. + +from odoo import api, models, fields + + +class ExceptionRule(models.Model): + _inherit = 'exception.rule' + + model = fields.Selection( + selection_add=[ + ('stock.picking', 'Transfer'), + ], + ondelete={ + 'stock.picking': 'cascade', + }, + ) + picking_ids = fields.Many2many( + 'stock.picking', + string="Transfers") + +class Picking(models.Model): + _inherit = ['stock.picking', 'base.exception'] + _name = 'stock.picking' + _order = 'main_exception_id asc, priority desc, date asc, id desc' + + @api.model + def _exception_rule_eval_context(self, rec): + res = super(Picking, self)._exception_rule_eval_context(rec) + res['picking'] = rec + return res + + @api.model + def _reverse_field(self): + return 'picking_ids' + + def button_validate(self): + self.ensure_one() + if self.detect_exceptions(): + return self._popup_exceptions() + return super().button_validate() + + @api.model + def _get_popup_action(self): + return self.env.ref('stock_exception.action_stock_exception_confirm') diff --git a/project_exception/security/ir.model.access.csv b/project_exception/security/ir.model.access.csv new file mode 100644 index 00000000..8177f81e --- /dev/null +++ b/project_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_project_task_exception_confirm_project_task,project_task_exception.project_task_exception,model_project_task_exception_confirm,project.group_project_user,1,1,1,1 \ No newline at end of file diff --git a/project_exception/tests/__init__.py b/project_exception/tests/__init__.py new file mode 100644 index 00000000..e40da629 --- /dev/null +++ b/project_exception/tests/__init__.py @@ -0,0 +1,2 @@ +# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details. +from . import test_project_exception diff --git a/project_exception/tests/test_project_exception.py b/project_exception/tests/test_project_exception.py new file mode 100644 index 00000000..6babeeab --- /dev/null +++ b/project_exception/tests/test_project_exception.py @@ -0,0 +1,43 @@ +# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details. + +from odoo.tests import common, Form + + +class TestProjectException(common.TransactionCase): + + def setUp(self): + super().setUp() + self.env = self.env(context=dict(self.env.context, tracking_disable=True)) + + def test_project_task_creation_exception(self): + exception = self.env.ref('project_exception.except_no_project_id') + exception.active = True + # partner = self.env.ref('base.res_partner_12') # Azure Interior + # partner.zip = False + # p = self.env.ref('product.product_product_6') + # stock_location = self.env.ref('stock.stock_location_stock') + # customer_location = self.env.ref('stock.stock_location_customers') + # self.env['stock.quant']._update_available_quantity(p, stock_location, 100) + # delivery_order = self.env['stock.picking'].create({ + # 'partner_id': partner.id, + # 'picking_type_id': self.ref('stock.picking_type_out'), + # 'location_id': self.env.ref('stock.stock_location_stock').id, + # 'location_dest_id': self.env.ref('stock.stock_location_customers').id, + # 'move_line_ids': [(0, 0, {'product_id': p.id, + # 'product_uom_id': p.uom_id.id, + # 'qty_done': 3.0, + # 'location_id': stock_location.id, + # 'location_dest_id': customer_location.id})], + # }) + + # validate delivery order + # action = delivery_order.button_validate() + # self.assertEqual(delivery_order.state, 'draft') + + # Simulation the opening of the wizard sale_exception_confirm and + # set ignore_exception to True + # stock_exception_confirm = Form(self.env[action['res_model']].with_context(action['context'])).save() + # stock_exception_confirm.ignore = True + # stock_exception_confirm.action_confirm() + # self.assertTrue(delivery_order.ignore_exception) + # self.assertEqual(delivery_order.state, 'done') diff --git a/project_exception/views/project_views.xml b/project_exception/views/project_views.xml new file mode 100644 index 00000000..232dfafa --- /dev/null +++ b/project_exception/views/project_views.xml @@ -0,0 +1,65 @@ + + + + + Stock Exception Rules + exception.rule + tree,form + + [('model', '=', 'stock.picking')] + {'active_test': False, 'default_model' : 'stock.picking'} + + + + + + stock.picking.form.inherit.exception + stock.picking + + + + + + + + + + + + + stock.picking.tree.inherit.exception + stock.picking + + + + + + + + + + stock.picking.internal.search.inherit.exception + stock.picking + + + + + + + + + + diff --git a/project_exception/wizard/__init__.py b/project_exception/wizard/__init__.py new file mode 100644 index 00000000..c2c0dbf4 --- /dev/null +++ b/project_exception/wizard/__init__.py @@ -0,0 +1 @@ +from . import project_exception_confim \ No newline at end of file diff --git a/project_exception/wizard/project_exception_confim.py b/project_exception/wizard/project_exception_confim.py new file mode 100644 index 00000000..e69de29b diff --git a/project_exception/wizard/project_exception_confirm_views.xml b/project_exception/wizard/project_exception_confirm_views.xml new file mode 100644 index 00000000..e69de29b