Add module stock_picking_batch_usability

This commit is contained in:
Alexis de Lattre
2024-04-26 17:48:51 +02:00
parent 550704288d
commit b252bdff34
5 changed files with 98 additions and 0 deletions

View File

@@ -0,0 +1 @@
from . import wizards

View File

@@ -0,0 +1,31 @@
# Copyright 2024 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# 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 <alexis.delattre@akretion.com>.
""",
'author': 'Akretion',
'website': 'https://github.com/akretion/odoo-usability',
'depends': ['stock_picking_batch'],
'data': [
'views/stock_picking.xml',
],
'installable': True,
}

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2014-2020 Akretion (http://www.akretion.com/)
@author Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>
<record id="view_picking_form" model="ir.ui.view">
<field name="name">stock_picking_batch_usability.stock.picking_form</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.view_picking_form" />
<field name="arch" type="xml">
<group name="other_infos" position="inside">
<field name="batch_id" attrs="{'invisible': [('picking_type_code', '!=', 'outgoing')]}"/>
</group>
</field>
</record>
</odoo>

View File

@@ -0,0 +1 @@
from . import stock_picking_to_batch

View File

@@ -0,0 +1,42 @@
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# 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