Skip to content

Commit

Permalink
[MIG] stock_picking_auto_create_lot_qty: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dessanhemrayev committed Jun 15, 2024
1 parent 30d1d5a commit 48108b4
Show file tree
Hide file tree
Showing 13 changed files with 116 additions and 103 deletions.
5 changes: 2 additions & 3 deletions stock_picking_auto_create_lot_qty/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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**

Expand Down
7 changes: 5 additions & 2 deletions stock_picking_auto_create_lot_qty/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
{
"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",
"author": "Ooops, Cetmix OÜ, Odoo Community Association (OCA)",
"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",
],
}
5 changes: 4 additions & 1 deletion stock_picking_auto_create_lot_qty/models/__init__.py
Original file line number Diff line number Diff line change
@@ -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
5 changes: 3 additions & 2 deletions stock_picking_auto_create_lot_qty/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
34 changes: 4 additions & 30 deletions stock_picking_auto_create_lot_qty/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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.
"""
Expand All @@ -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.
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion stock_picking_auto_create_lot_qty/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions stock_picking_auto_create_lot_qty/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -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


2 changes: 1 addition & 1 deletion stock_picking_auto_create_lot_qty/readme/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 9 additions & 7 deletions stock_picking_auto_create_lot_qty/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 }
Expand All @@ -300,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -366,11 +367,10 @@ <h1 class="title">Stock Picking Auto Create Lot Quantity</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:9da0cd91088d3be4a92d7376e09e59d73080bdad49e1fe1d1c9dc6b039a7a561
!! source digest: sha256:31abf6223e281237e7c286a76e4f06a04aaeff5bb04aaef7548eee5df36c5256
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/stock-logistics-workflow/tree/16.0/stock_picking_auto_create_lot_qty"><img alt="OCA/stock-logistics-workflow" src="https://img.shields.io/badge/github-OCA%2Fstock--logistics--workflow-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/stock-logistics-workflow-16-0/stock-logistics-workflow-16-0-stock_picking_auto_create_lot_qty"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-workflow&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module extends the functionality of stock module to allow auto
create lots with certain count for incoming pickings.</p>
<p>Add a unique lot sequence for lots being created for every company</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
Expand Down Expand Up @@ -440,7 +440,9 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
Expand Down
1 change: 0 additions & 1 deletion stock_picking_auto_create_lot_qty/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# Copyright (C) 2023 Cetmix OÜ
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import common
from . import test_stock_picking_auto_create_lot_qty
15 changes: 7 additions & 8 deletions stock_picking_auto_create_lot_qty/tests/common.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
# Copyright (C) 2023 Cetmix OÜ
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.tests import TransactionCase

from odoo.tests import SavepointCase


class CommonStockPicking(SavepointCase):
class CommonStockPicking(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
cls.lot_obj = cls.env["stock.production.lot"]
cls.lot_obj = cls.env["stock.lot"]
cls.warehouse = cls.env.ref("stock.warehouse0")
cls.company_1 = cls.env.ref("base.main_company")
cls.company_2 = cls.env.ref("stock.res_company_1")
cls.picking_type_in = cls.env.ref("stock.picking_type_in")
cls.picking_type_in_2 = cls.env.ref("stock.chi_picking_type_in")

cls.supplier_location = cls.env.ref("stock.stock_location_suppliers")
cls.supplier = cls.env["res.partner"].create({"name": "Supplier - test"})

cls.stock_serial_sequence_2 = cls.env.ref(
"stock.sequence_production_lots"
).copy()
cls.stock_serial_sequence_2.prefix = "TEST"
cls.company_1 = cls.env.ref("base.main_company")
cls.company_2 = cls.env.ref("stock.res_company_1")
cls.company_2.stock_lot_serial_sequence_id = cls.stock_serial_sequence_2.id

@classmethod
def _create_product(
Expand Down Expand Up @@ -111,7 +110,7 @@ def _create_move(cls, product=None, qty=1.0, multicompany=False):
0,
{
"product_id": product.id,
"product_uom_qty": qty,
"reserved_uom_qty": qty,
"product_uom_id": product.uom_id.id,
"location_id": cls.supplier_location.id,
"location_dest_id": location_dest.id,
Expand Down
Loading

0 comments on commit 48108b4

Please sign in to comment.