From 48108b4085665916140697e25e4b94e9b86e0f02 Mon Sep 17 00:00:00 2001 From: dessanhemrayev Date: Thu, 11 Apr 2024 01:09:08 +0300 Subject: [PATCH] [MIG] stock_picking_auto_create_lot_qty: Migration to 16.0 --- stock_picking_auto_create_lot_qty/README.rst | 5 +- .../__manifest__.py | 7 +- .../models/__init__.py | 5 +- .../models/product_template.py | 5 +- .../{stock_production_lot.py => stock_lot.py} | 4 +- .../models/stock_picking.py | 34 +---- .../readme/CONFIGURE.md | 2 +- .../readme/DESCRIPTION.md | 5 +- .../readme/USAGE.md | 2 +- .../static/description/index.html | 16 +-- .../tests/__init__.py | 1 - .../tests/common.py | 15 ++- .../test_stock_picking_auto_create_lot_qty.py | 118 +++++++++++------- 13 files changed, 116 insertions(+), 103 deletions(-) rename stock_picking_auto_create_lot_qty/models/{stock_production_lot.py => stock_lot.py} (80%) diff --git a/stock_picking_auto_create_lot_qty/README.rst b/stock_picking_auto_create_lot_qty/README.rst index 5aabb7e8594a..a4b1dcac7beb 100644 --- a/stock_picking_auto_create_lot_qty/README.rst +++ b/stock_picking_auto_create_lot_qty/README.rst @@ -7,7 +7,7 @@ Stock Picking Auto Create Lot Quantity !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:9da0cd91088d3be4a92d7376e09e59d73080bdad49e1fe1d1c9dc6b039a7a561 + !! source digest: sha256:31abf6223e281237e7c286a76e4f06a04aaeff5bb04aaef7548eee5df36c5256 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png @@ -28,8 +28,7 @@ Stock Picking Auto Create Lot Quantity |badge1| |badge2| |badge3| |badge4| |badge5| -This module extends the functionality of stock module to allow auto -create lots with certain count for incoming pickings. +Add a unique lot sequence for lots being created for every company **Table of contents** diff --git a/stock_picking_auto_create_lot_qty/__manifest__.py b/stock_picking_auto_create_lot_qty/__manifest__.py index 71c26b83df16..ef7d40f36778 100644 --- a/stock_picking_auto_create_lot_qty/__manifest__.py +++ b/stock_picking_auto_create_lot_qty/__manifest__.py @@ -4,7 +4,7 @@ { "name": "Stock Picking Auto Create Lot Quantity", "summary": "Auto batch generation by quantity", - "version": "14.0.1.0.0", + "version": "16.0.1.0.0", "development_status": "Production/Stable", "category": "stock", "website": "https://github.com/OCA/stock-logistics-workflow", @@ -12,5 +12,8 @@ "license": "AGPL-3", "installable": True, "depends": ["stock_picking_auto_create_lot"], - "data": ["views/product_template_view.xml", "views/res_config_settings_view.xml"], + "data": [ + "views/product_template_view.xml", + "views/res_config_settings_view.xml", + ], } diff --git a/stock_picking_auto_create_lot_qty/models/__init__.py b/stock_picking_auto_create_lot_qty/models/__init__.py index 69345ebf68bf..7a12c1cc20ef 100644 --- a/stock_picking_auto_create_lot_qty/models/__init__.py +++ b/stock_picking_auto_create_lot_qty/models/__init__.py @@ -1,5 +1,8 @@ +# Copyright (C) 2024 Cetmix OÜ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + from . import product_template from . import stock_picking from . import res_company -from . import stock_production_lot +from . import stock_lot from . import res_config_settings diff --git a/stock_picking_auto_create_lot_qty/models/product_template.py b/stock_picking_auto_create_lot_qty/models/product_template.py index 7dd25a5a8da8..1a876e569cfd 100644 --- a/stock_picking_auto_create_lot_qty/models/product_template.py +++ b/stock_picking_auto_create_lot_qty/models/product_template.py @@ -35,5 +35,6 @@ class ProductTemplate(models.Model): @api.onchange("tracking") def _onchange_tracking(self): - if self.tracking != "lot": - self.create_lot_every_n = False + for rec in self: + if rec.tracking != "lot": + rec.create_lot_every_n = False diff --git a/stock_picking_auto_create_lot_qty/models/stock_production_lot.py b/stock_picking_auto_create_lot_qty/models/stock_lot.py similarity index 80% rename from stock_picking_auto_create_lot_qty/models/stock_production_lot.py rename to stock_picking_auto_create_lot_qty/models/stock_lot.py index e2195115d57a..7745eb2ce74d 100644 --- a/stock_picking_auto_create_lot_qty/models/stock_production_lot.py +++ b/stock_picking_auto_create_lot_qty/models/stock_lot.py @@ -3,8 +3,8 @@ from odoo import fields, models -class ProductionLot(models.Model): - _inherit = "stock.production.lot" +class StockLot(models.Model): + _inherit = "stock.lot" name = fields.Char( default=lambda self: self.env["ir.sequence"].next_by_code( diff --git a/stock_picking_auto_create_lot_qty/models/stock_picking.py b/stock_picking_auto_create_lot_qty/models/stock_picking.py index 21e548f23b85..8ad9bfb90bf4 100644 --- a/stock_picking_auto_create_lot_qty/models/stock_picking.py +++ b/stock_picking_auto_create_lot_qty/models/stock_picking.py @@ -11,19 +11,15 @@ class StockPicking(models.Model): def _split_stock_move_lines(self, pickings): """ Split stock move lines into existing and new lines. - This method separates stock move lines into existing and new lines based on specific criteria and optionally creates automatic lot numbers. - Args: pickings (recordset): Recordset of stock pickings for which to retrieve stock move lines - Returns: tuple (existing_lines, new_lines): A tuple containing two recordsets: - existing_lines: Existing stock move lines associated with the pickings. - new_lines: New stock move lines that need to be created. - """ existing_lines = self.env["stock.move.line"].browse() new_lines = self.env["stock.move.line"].browse() @@ -45,13 +41,11 @@ def _create_multiple_stock_move_lines_for_lots( ): """ Create multiple stock move lines for generating lots. - Args: count_of_lots (int): Number of lots to generate. line (stock.move.line): Stock move line to use as a template. product_id (product.product): Product for which lots are generated. every_n (int): Number of units of measure to generate a lot for. - Returns: new_lines (recordset): List of new stock move lines generated. """ @@ -62,43 +56,23 @@ def _create_multiple_stock_move_lines_for_lots( { "qty_done": every_n, "product_uom_id": product_id.batch_uom_id or product_id.uom_id, + "product_id": product_id, } ) new_lines |= new_line return new_lines - @api.model - def _prepare_count_by_products(self, lines): - """ - Prepares the number of lots to generate for each product - based on the stock move lines provided. - - Args: - lines (recordset): List of stock move lines. - - Returns: - count_by_product (dict): Dictionary with product IDs as keys and number of lots - to generate as values. - """ - count_by_product = dict.fromkeys(lines.mapped("product_id"), 0) - for line in lines: - count_by_product[line.product_id] += line.product_uom_qty - return count_by_product - @api.model def _prepare_stock_move_lines_for_lots(self, product_id, line, current_product_qty): """ Prepare stock move lines representing generated lots for a product. - This method is responsible for preparing stock move lines that represent the lots generated for a specific product based on the product's configuration and the provided quantity. - Args: product_id (product.product): Product for which lots are generated. line (stock.move.line): Stock move line to use as a template. current_product_qty (int): Quantity of the product to generate lots for. - Returns: lines (recordset): A set of new stock move lines representing the generated lots. @@ -135,9 +109,9 @@ def _set_auto_lot(self): lines, new_lines = self._split_stock_move_lines(pickings) if new_lines or not lines: return - count_by_product = self._prepare_count_by_products(lines) - line = lines[0] - for product_id, product_qty in count_by_product.items(): + for line in lines: + product_id = line.product_id + product_qty = line.reserved_uom_qty current_product_qty = product_id.uom_id._compute_quantity( product_qty, product_id.batch_uom_id or product_id.uom_id, diff --git a/stock_picking_auto_create_lot_qty/readme/CONFIGURE.md b/stock_picking_auto_create_lot_qty/readme/CONFIGURE.md index 7e1ae8ed3bfd..092f045e7629 100644 --- a/stock_picking_auto_create_lot_qty/readme/CONFIGURE.md +++ b/stock_picking_auto_create_lot_qty/readme/CONFIGURE.md @@ -5,4 +5,4 @@ To configure this module, you need to: If you need to create lots for different companies, you can set the sequence for the company #. Go to a General Settings > Inventory > Stock Serial Lots > Select sequence -for current company +for current company \ No newline at end of file diff --git a/stock_picking_auto_create_lot_qty/readme/DESCRIPTION.md b/stock_picking_auto_create_lot_qty/readme/DESCRIPTION.md index d095bf0a209d..761464a63979 100644 --- a/stock_picking_auto_create_lot_qty/readme/DESCRIPTION.md +++ b/stock_picking_auto_create_lot_qty/readme/DESCRIPTION.md @@ -1,2 +1,3 @@ -This module extends the functionality of stock module to allow auto create lots with -certain count for incoming pickings. +Add a unique lot sequence for lots being created for every company + + diff --git a/stock_picking_auto_create_lot_qty/readme/USAGE.md b/stock_picking_auto_create_lot_qty/readme/USAGE.md index bb5917c26a8d..87ca7c2caa0c 100644 --- a/stock_picking_auto_create_lot_qty/readme/USAGE.md +++ b/stock_picking_auto_create_lot_qty/readme/USAGE.md @@ -8,4 +8,4 @@ product. If you need to create lots for different companies, you can set the sequence for the company #. Go to a General Settings > Inventory > Stock Serial Lots > Select sequence -for current company +for current company \ No newline at end of file diff --git a/stock_picking_auto_create_lot_qty/static/description/index.html b/stock_picking_auto_create_lot_qty/static/description/index.html index df152818f8d3..d21958171622 100644 --- a/stock_picking_auto_create_lot_qty/static/description/index.html +++ b/stock_picking_auto_create_lot_qty/static/description/index.html @@ -8,10 +8,11 @@ /* :Author: David Goodger (goodger@python.org) -:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $ +:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $ :Copyright: This stylesheet has been placed in the public domain. Default cascading style sheet for the HTML output of Docutils. +Despite the name, some widely supported CSS2 features are used. See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to customize this style sheet. @@ -274,7 +275,7 @@ margin-left: 2em ; margin-right: 2em } -pre.code .ln { color: grey; } /* line numbers */ +pre.code .ln { color: gray; } /* line numbers */ pre.code, code { background-color: #eeeeee } pre.code .comment, code .comment { color: #5C6576 } pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold } @@ -300,7 +301,7 @@ span.pre { white-space: pre } -span.problematic { +span.problematic, pre.problematic { color: red } span.section-subtitle { @@ -366,11 +367,10 @@

Stock Picking Auto Create Lot Quantity

!! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:9da0cd91088d3be4a92d7376e09e59d73080bdad49e1fe1d1c9dc6b039a7a561 +!! source digest: sha256:31abf6223e281237e7c286a76e4f06a04aaeff5bb04aaef7548eee5df36c5256 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

Production/Stable License: AGPL-3 OCA/stock-logistics-workflow Translate me on Weblate Try me on Runboat

-

This module extends the functionality of stock module to allow auto -create lots with certain count for incoming pickings.

+

Add a unique lot sequence for lots being created for every company

Table of contents