diff --git a/stock_picking_batch_usability/__init__.py b/stock_picking_batch_usability/__init__.py new file mode 100644 index 0000000..5cb1c49 --- /dev/null +++ b/stock_picking_batch_usability/__init__.py @@ -0,0 +1 @@ +from . import wizards diff --git a/stock_picking_batch_usability/__manifest__.py b/stock_picking_batch_usability/__manifest__.py new file mode 100644 index 0000000..b388ae9 --- /dev/null +++ b/stock_picking_batch_usability/__manifest__.py @@ -0,0 +1,31 @@ +# Copyright 2024 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + + +{ + 'name': 'Stock Picking Batch Usability', + 'version': '14.0.1.0.0', + 'category': 'Inventory, Logistic, Storage', + 'license': 'AGPL-3', + 'summary': 'Several usability enhancements in Batch Pickings', + 'description': """ +Stock Picking Batch Usability +============================= + +The usability enhancements include: + +* add batch_id on picking form view +* when creating a batch from a list of pickings, raise an error if a picking is already linked to a batch. +* when creating a batch from a list of pickings, display the form view of the batch after validation of the wizard + +This module has been written by Alexis de Lattre from Akretion . + """, + 'author': 'Akretion', + 'website': 'https://github.com/akretion/odoo-usability', + 'depends': ['stock_picking_batch'], + 'data': [ + 'views/stock_picking.xml', + ], + 'installable': True, +} diff --git a/stock_picking_batch_usability/views/stock_picking.xml b/stock_picking_batch_usability/views/stock_picking.xml new file mode 100644 index 0000000..5cce78a --- /dev/null +++ b/stock_picking_batch_usability/views/stock_picking.xml @@ -0,0 +1,23 @@ + + + + + + + + stock_picking_batch_usability.stock.picking_form + stock.picking + + + + + + + + + + diff --git a/stock_picking_batch_usability/wizards/__init__.py b/stock_picking_batch_usability/wizards/__init__.py new file mode 100644 index 0000000..b9e4989 --- /dev/null +++ b/stock_picking_batch_usability/wizards/__init__.py @@ -0,0 +1 @@ +from . import stock_picking_to_batch diff --git a/stock_picking_batch_usability/wizards/stock_picking_to_batch.py b/stock_picking_batch_usability/wizards/stock_picking_to_batch.py new file mode 100644 index 0000000..b4d9846 --- /dev/null +++ b/stock_picking_batch_usability/wizards/stock_picking_to_batch.py @@ -0,0 +1,42 @@ +# @author: Alexis de Lattre +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, models, fields, _ +from odoo.exceptions import UserError + + +class StockPickingToBatch(models.TransientModel): + _inherit = 'stock.picking.to.batch' + + # add 'in_progress' in domain + batch_id = fields.Many2one(domain="[('state', 'in', ('draft', 'in_progress'))]") + mode = fields.Selection(default='new') + + @api.model + def default_get(self, fields_list): + res = super().default_get(fields_list) + pickings = self.env['stock.picking'].browse(self.env.context.get('active_ids')) + for picking in pickings: + if picking.batch_id: + raise UserError(_( + "The picking %(picking)s is already part of batch %(batch)s.", + picking=picking.display_name, + batch=picking.batch_id.display_name)) + return res + + def attach_pickings(self): + super().attach_pickings() + if self.mode == 'new': + pickings = self.env['stock.picking'].browse(self.env.context.get('active_ids')) + batch_id = pickings[0].batch_id.id + elif self.mode == 'existing': + batch_id = self.batch_id.id + else: + raise UserError('It should never happen') + action = self.env["ir.actions.actions"]._for_xml_id("stock_picking_batch.stock_picking_batch_action") + action.update({ + 'view_mode': 'form,tree', + 'res_id': batch_id, + 'views': False, + }) + return action