From 2863de99f433869808f96308749562152ef196cc Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Fri, 28 Apr 2023 12:49:37 +0200 Subject: [PATCH] Add module stock_move_line_auto_fill_all Same as the OCA module stock_move_line_auto_fill but applies on all moves lines (including lines with lot) --- stock_move_line_auto_fill_all/__init__.py | 1 + stock_move_line_auto_fill_all/__manifest__.py | 27 +++++++++++++++ .../models/__init__.py | 1 + .../models/stock_picking.py | 34 +++++++++++++++++++ .../views/stock_picking.xml | 22 ++++++++++++ 5 files changed, 85 insertions(+) create mode 100644 stock_move_line_auto_fill_all/__init__.py create mode 100644 stock_move_line_auto_fill_all/__manifest__.py create mode 100644 stock_move_line_auto_fill_all/models/__init__.py create mode 100644 stock_move_line_auto_fill_all/models/stock_picking.py create mode 100644 stock_move_line_auto_fill_all/views/stock_picking.xml diff --git a/stock_move_line_auto_fill_all/__init__.py b/stock_move_line_auto_fill_all/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/stock_move_line_auto_fill_all/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/stock_move_line_auto_fill_all/__manifest__.py b/stock_move_line_auto_fill_all/__manifest__.py new file mode 100644 index 0000000..8dfb3e8 --- /dev/null +++ b/stock_move_line_auto_fill_all/__manifest__.py @@ -0,0 +1,27 @@ +# Copyright 2023 Akretion France (http://www.akretion.com/) +# @author: Alexis de Lattre +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + 'name': 'Stock Move Line Auto-fill All', + 'version': '14.0.1.0.0', + 'category': 'Warehouse', + 'license': 'AGPL-3', + 'summary': 'Add button on picking to auto-fill done qty', + 'description': """ +This module is an alternative to the OCA module **stock_move_line_auto_fill** from https://github.com/OCA/stock-logistics-workflow/ +The OCA module doesn't auto-fill the stock move lines with lots. This module does. + +This module has been written by Alexis de Lattre from Akretion +. + """, + 'author': 'Akretion', + 'maintainers': ['alexis-via'], + "development_status": "Mature", + 'website': 'https://github.com/akretion/odoo-usability', + 'depends': ['stock'], + 'data': [ + 'views/stock_picking.xml', + ], + 'installable': True, +} diff --git a/stock_move_line_auto_fill_all/models/__init__.py b/stock_move_line_auto_fill_all/models/__init__.py new file mode 100644 index 0000000..ae4c272 --- /dev/null +++ b/stock_move_line_auto_fill_all/models/__init__.py @@ -0,0 +1 @@ +from . import stock_picking diff --git a/stock_move_line_auto_fill_all/models/stock_picking.py b/stock_move_line_auto_fill_all/models/stock_picking.py new file mode 100644 index 0000000..17ff0f4 --- /dev/null +++ b/stock_move_line_auto_fill_all/models/stock_picking.py @@ -0,0 +1,34 @@ +# Copyright 2023 Akretion France (http://www.akretion.com/) +# @author: Alexis de Lattre +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models, _ +from odoo.tools import float_compare, float_is_zero +from odoo.exceptions import UserError + + +class StockPicking(models.Model): + _inherit = 'stock.picking' + + autofill_done = fields.Boolean(readonly=True) + + def button_stock_move_line_autofill(self): + self.ensure_one() + prec = self.env['decimal.precision'].precision_get( + 'Product Unit of Measure') + for ml in self.move_line_ids_without_package: + if ml.product_id and float_compare(ml.product_uom_qty, 0, precision_digits=prec) > 0 and float_is_zero(ml.qty_done, precision_digits=prec): + if ( + ml.product_id.tracking in ('lot', 'serial') and + not ml.lot_id and + not ml.lot_name): + raise UserError(_( + "Autofill is not possible: the lot is not set " + "on move line with product '%s' quantity %s %s.") + % ( + ml.product_id.display_name, + ml.product_uom_qty, + ml.product_uom_id.display_name + )) + ml.write({'qty_done': ml.product_uom_qty}) + self.write({'autofill_done': True}) diff --git a/stock_move_line_auto_fill_all/views/stock_picking.xml b/stock_move_line_auto_fill_all/views/stock_picking.xml new file mode 100644 index 0000000..966752e --- /dev/null +++ b/stock_move_line_auto_fill_all/views/stock_picking.xml @@ -0,0 +1,22 @@ + + + + + + + stock.picking + + + + + + + + + +