diff --git a/stock_exception/__init__.py b/stock_exception/__init__.py new file mode 100644 index 00000000..c7120225 --- /dev/null +++ b/stock_exception/__init__.py @@ -0,0 +1,4 @@ +# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details. + +from . import models +from . import wizard diff --git a/stock_exception/__manifest__.py b/stock_exception/__manifest__.py new file mode 100644 index 00000000..94034a05 --- /dev/null +++ b/stock_exception/__manifest__.py @@ -0,0 +1,27 @@ +# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details. + +{ + 'name': 'Stock Exception Rule', + 'version': '13.0.1.0.0', + 'author': 'Hibou Corp.', + 'license': 'OPL-1', + 'category': 'Generic Modules', + 'summary': 'Custom exceptions on delivery orders', + 'description': """ +Custom exceptions on delivery orders +""", + 'website': 'https://hibou.io/', + 'depends': [ + 'base_exception_user', + 'stock', + ], + 'data': [ + 'views/stock_views.xml', + 'wizard/stock_exception_confirm_views.xml', + ], + 'demo': [ + 'demo/stock_exception_demo.xml', + ], + 'installable': True, + 'auto_install': False, +} diff --git a/stock_exception/demo/stock_exception_demo.xml b/stock_exception/demo/stock_exception_demo.xml new file mode 100644 index 00000000..032968c5 --- /dev/null +++ b/stock_exception/demo/stock_exception_demo.xml @@ -0,0 +1,13 @@ + + + + + No ZIP code on destination + No ZIP code on destination + 50 + stock.picking + if not picking.partner_id.zip: failed=True + + + + diff --git a/stock_exception/models/__init__.py b/stock_exception/models/__init__.py new file mode 100644 index 00000000..7297e4be --- /dev/null +++ b/stock_exception/models/__init__.py @@ -0,0 +1,3 @@ +# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details. + +from . import stock diff --git a/stock_exception/models/stock.py b/stock_exception/models/stock.py new file mode 100644 index 00000000..95824dfb --- /dev/null +++ b/stock_exception/models/stock.py @@ -0,0 +1,42 @@ +# 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'), + ] + ) + 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/stock_exception/tests/__init__.py b/stock_exception/tests/__init__.py new file mode 100644 index 00000000..7589231c --- /dev/null +++ b/stock_exception/tests/__init__.py @@ -0,0 +1,3 @@ +# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details. + +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 00000000..6525d607 --- /dev/null +++ b/stock_exception/tests/test_stock_exception.py @@ -0,0 +1,47 @@ +# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details. + +from odoo.tests import common + + +class TestStockException(common.TransactionCase): + + def setUp(self): + super().setUp() + self.env = self.env(context=dict(self.env.context, tracking_disable=True)) + + def test_delivery_order_exception(self): + exception = self.env.ref('stock_exception.excep_no_zip') + 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 + 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 = self.env['stock.exception.confirm'].with_context( + { + 'active_id': delivery_order.id, + 'active_ids': [delivery_order.id], + 'active_model': delivery_order._name + }).create({'ignore': True}) + stock_exception_confirm.action_confirm() + self.assertTrue(delivery_order.ignore_exception) + self.assertEqual(delivery_order.state, 'done') diff --git a/stock_exception/views/stock_views.xml b/stock_exception/views/stock_views.xml new file mode 100644 index 00000000..232dfafa --- /dev/null +++ b/stock_exception/views/stock_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 + + + + + There are exceptions blocking the confirmation of this Delivery Order: + + + + + + + + + + + + stock.picking.tree.inherit.exception + stock.picking + + + + + + + + + + stock.picking.internal.search.inherit.exception + stock.picking + + + + + + + + + + diff --git a/stock_exception/wizard/__init__.py b/stock_exception/wizard/__init__.py new file mode 100644 index 00000000..f2d4f882 --- /dev/null +++ b/stock_exception/wizard/__init__.py @@ -0,0 +1,3 @@ +# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details. + +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 00000000..b575f965 --- /dev/null +++ b/stock_exception/wizard/stock_exception_confirm.py @@ -0,0 +1,25 @@ +# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details. + +from odoo import api, fields, models + + +class StockExceptionConfirm(models.TransientModel): + _name = 'stock.exception.confirm' + _inherit = ['exception.rule.confirm'] + + related_model_id = fields.Many2one('stock.picking', 'Transfer') + + def action_confirm(self): + self.ensure_one() + if self.ignore: + self.related_model_id.ignore_exception = True + res = super().action_confirm() + if self.ignore: + return self.related_model_id.button_validate() + else: + return res + + def _action_ignore(self): + self.related_model_id.ignore_exception = True + super()._action_ignore() + return self.related_model_id.button_validate() diff --git a/stock_exception/wizard/stock_exception_confirm_views.xml b/stock_exception/wizard/stock_exception_confirm_views.xml new file mode 100644 index 00000000..0150c870 --- /dev/null +++ b/stock_exception/wizard/stock_exception_confirm_views.xml @@ -0,0 +1,25 @@ + + + + + Stock Exceptions Rules + stock.exception.confirm + + primary + + + + + + + + + Blocked due to exceptions + ir.actions.act_window + stock.exception.confirm + form + + new + + +
There are exceptions blocking the confirmation of this Delivery Order: