Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4337][FIX] stock_picking_auto_create_lot: fix creating lot for 0 qty move lines for serial product #109

Merged
merged 3 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions stock_picking_auto_create_lot/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
Stock Picking Auto Create Lot
=============================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:7bd67aa1ef1a59ba07d7a22f56d8d7d066206b34bbcf6d93bf9dc8b6966d2c9c
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
:target: https://odoo-community.org/page/development-status
Expand All @@ -19,11 +22,11 @@ Stock Picking Auto Create Lot
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/stock-logistics-workflow-16-0/stock-logistics-workflow-16-0-stock_picking_auto_create_lot
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/154/16.0
:alt: Try me on Runbot
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-workflow&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
|badge1| |badge2| |badge3| |badge4| |badge5|

This module extends the functionality of stock module to allow auto create
lots for incoming pickings.
Expand Down Expand Up @@ -60,7 +63,7 @@ Bug Tracker

Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-workflow/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/stock-logistics-workflow/issues/new?body=module:%20stock_picking_auto_create_lot%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.
Expand Down
2 changes: 1 addition & 1 deletion stock_picking_auto_create_lot/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"name": "Stock Picking Auto Create Lot",
"summary": "Auto create lots for incoming pickings",
"version": "16.0.1.0.0",
"version": "16.0.3.0.0",
"development_status": "Production/Stable",
"category": "stock",
"website": "https://github.com/OCA/stock-logistics-workflow",
Expand Down
49 changes: 49 additions & 0 deletions stock_picking_auto_create_lot/i18n/it.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * stock_picking_auto_create_lot
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2023-11-17 11:36+0000\n"
"Last-Translator: mymage <[email protected]>\n"
"Language-Team: none\n"
"Language: it\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 4.17\n"

#. module: stock_picking_auto_create_lot
#: model:ir.model.fields,field_description:stock_picking_auto_create_lot.field_product_product__auto_create_lot
#: model:ir.model.fields,field_description:stock_picking_auto_create_lot.field_product_template__auto_create_lot
#: model:ir.model.fields,field_description:stock_picking_auto_create_lot.field_stock_picking_type__auto_create_lot
msgid "Auto Create Lot"
msgstr "Creazione automatica lotto"

#. module: stock_picking_auto_create_lot
#: model:ir.model,name:stock_picking_auto_create_lot.model_stock_picking_type
msgid "Picking Type"
msgstr "Tipologia prelievo"

#. module: stock_picking_auto_create_lot
#: model:ir.model,name:stock_picking_auto_create_lot.model_product_template
msgid "Product"
msgstr "Prodotto"

#. module: stock_picking_auto_create_lot
#: model:ir.model,name:stock_picking_auto_create_lot.model_stock_move_line
msgid "Product Moves (Stock Move Line)"
msgstr "Movimenti prodotto (riga movimento di magazzino)"

#. module: stock_picking_auto_create_lot
#: model:ir.model,name:stock_picking_auto_create_lot.model_stock_move
msgid "Stock Move"
msgstr "Movimento di magazzino"

#. module: stock_picking_auto_create_lot
#: model:ir.model,name:stock_picking_auto_create_lot.model_stock_picking
msgid "Transfer"
msgstr "Trasferimento"
49 changes: 49 additions & 0 deletions stock_picking_auto_create_lot/i18n/nl.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * stock_picking_auto_create_lot
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2023-10-14 00:45+0000\n"
"Last-Translator: Bosd <[email protected]>\n"
"Language-Team: none\n"
"Language: nl\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 4.17\n"

#. module: stock_picking_auto_create_lot
#: model:ir.model.fields,field_description:stock_picking_auto_create_lot.field_product_product__auto_create_lot
#: model:ir.model.fields,field_description:stock_picking_auto_create_lot.field_product_template__auto_create_lot
#: model:ir.model.fields,field_description:stock_picking_auto_create_lot.field_stock_picking_type__auto_create_lot
msgid "Auto Create Lot"
msgstr "Automatisch een partij aanmaken"

#. module: stock_picking_auto_create_lot
#: model:ir.model,name:stock_picking_auto_create_lot.model_stock_picking_type
msgid "Picking Type"
msgstr ""

#. module: stock_picking_auto_create_lot
#: model:ir.model,name:stock_picking_auto_create_lot.model_product_template
msgid "Product"
msgstr "Product"

#. module: stock_picking_auto_create_lot
#: model:ir.model,name:stock_picking_auto_create_lot.model_stock_move_line
msgid "Product Moves (Stock Move Line)"
msgstr "Voorraadverplaatsingen (Voorraadverplaatsingsregels)"

#. module: stock_picking_auto_create_lot
#: model:ir.model,name:stock_picking_auto_create_lot.model_stock_move
msgid "Stock Move"
msgstr "Voorraadverplaatsing"

#. module: stock_picking_auto_create_lot
#: model:ir.model,name:stock_picking_auto_create_lot.model_stock_picking
msgid "Transfer"
msgstr "transfer"
2 changes: 1 addition & 1 deletion stock_picking_auto_create_lot/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
from . import product
from . import stock_picking
from . import stock_picking_type
from . import stock_move_line
from . import stock_move
from . import stock_move_line
37 changes: 5 additions & 32 deletions stock_picking_auto_create_lot/models/stock_move_line.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,12 @@
# Copyright 2020 ACSONE SA/NV
# Copyright 2024 Quartile Limited
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Copyright 2024 Quartile Limited
# Copyright 2020 ACSONE SA/NV
# Copyright 2024 Quartile Limited

Please don't remove this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is already removed in OCA because it is removed this file first in OCA repo by another PR that is proposed by other community member. Then, we added this file again because it is needed for some use case. So, I guess we don't need add in our repo as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AungKoKoLin1997
I understood.


from odoo import models
from odoo.fields import first


class StockMoveLine(models.Model):

_inherit = "stock.move.line"

def _get_value_production_lot(self):
res = super()._get_value_production_lot()
if "name" in res and not res["name"]:
del res["name"]
return res

def set_lot_auto(self):
"""
Create lots using create_multi to avoid too much queries
As move lines were created by product or by tracked 'serial'
products, we apply the lot with both different approaches.
"""
values = []
stock_lot_obj = self.env["stock.lot"]
lots_by_product = dict()
for line in self:
# Prepare multi valued lots per line to use multi creation.
values.append(line._get_value_production_lot())
lots = stock_lot_obj.create(values)
for lot in lots:
if lot.product_id.id not in lots_by_product:
lots_by_product[lot.product_id.id] = lot
else:
lots_by_product[lot.product_id.id] += lot
for line in self:
lot = first(lots_by_product[line.product_id.id])
line.lot_id = lot
if lot.product_id.tracking == "serial":
lots_by_product[line.product_id.id] -= lot
def _get_lot_sequence(self):
self.ensure_one()
return self.env["ir.sequence"].next_by_code("stock.lot.serial")
44 changes: 35 additions & 9 deletions stock_picking_auto_create_lot/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,51 @@
# Copyright 2020 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import models
from odoo.osv import expression


class StockPicking(models.Model):
_inherit = "stock.picking"

def _prepare_auto_lot_domain(self, immediate=False):
"""Prepare the domain to search for stock.move.line records that require
automatic lot assignment.
The 'immediate' parameter influences the inclusion of 'qty_done' in the search criteria,
depending on whether the transfer is immediate or planned.
"""
domain = [
("picking_id", "in", self.ids),
("lot_id", "=", False),
("lot_name", "=", False),
("product_id.tracking", "!=", "none"),
("product_id.auto_create_lot", "=", True),
]
if not immediate:
domain = expression.AND([domain, [("qty_done", ">", 0)]])
return domain

def _set_auto_lot(self):
"""
Allows to be called either by button or through code
Allows to be called either by button or through code.
"""
lines_to_set = self.env["stock.move.line"]
pickings = self.filtered(lambda p: p.picking_type_id.auto_create_lot)
lines = pickings.mapped("move_line_ids").filtered(
lambda x: (
not x.lot_id
and not x.lot_name
and x.product_id.tracking != "none"
and x.product_id.auto_create_lot
if not pickings:
return
immediate_domain = []
planned_domain = []
immediate_pickings = pickings._check_immediate()
if immediate_pickings:
immediate_domain = immediate_pickings._prepare_auto_lot_domain(
immediate=True
)
)
lines.set_lot_auto()
planned_pickings = pickings - immediate_pickings
if planned_pickings:
planned_domain = planned_pickings._prepare_auto_lot_domain()
domain = expression.OR([immediate_domain, planned_domain])
lines_to_set = lines_to_set.search(domain)
for line in lines_to_set:
line.lot_name = line._get_lot_sequence()

def _action_done(self):
self._set_auto_lot()
Expand Down
43 changes: 22 additions & 21 deletions stock_picking_auto_create_lot/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<title>Stock Picking Auto Create Lot</title>
<style type="text/css">

/*
:Author: David Goodger ([email protected])
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Copyright: This stylesheet has been placed in the public domain.

Default cascading style sheet for the HTML output of Docutils.

See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
*/

Expand Down Expand Up @@ -366,26 +365,28 @@ <h1 class="title">Stock Picking Auto Create Lot</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:7bd67aa1ef1a59ba07d7a22f56d8d7d066206b34bbcf6d93bf9dc8b6966d2c9c
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" 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" 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" href="https://github.com/OCA/stock-logistics-workflow/tree/16.0/stock_picking_auto_create_lot"><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" href="https://translation.odoo-community.org/projects/stock-logistics-workflow-16-0/stock-logistics-workflow-16-0-stock_picking_auto_create_lot"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/154/16.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<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"><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"><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 for incoming pickings.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#configuration" id="id1">Configuration</a></li>
<li><a class="reference internal" href="#usage" id="id2">Usage</a></li>
<li><a class="reference internal" href="#bug-tracker" id="id3">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="id4">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="id5">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="id6">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="id7">Maintainers</a></li>
<li><a class="reference internal" href="#configuration" id="toc-entry-1">Configuration</a></li>
<li><a class="reference internal" href="#usage" id="toc-entry-2">Usage</a></li>
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-3">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-4">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-5">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-6">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-7">Maintainers</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="configuration">
<h1><a class="toc-backref" href="#id1">Configuration</a></h1>
<h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
<p>To configure this module, you need to:</p>
<ol class="arabic simple">
<li>Go to a <em>Inventory &gt; Configuration &gt; Operation Types</em>.</li>
Expand All @@ -395,7 +396,7 @@ <h1><a class="toc-backref" href="#id1">Configuration</a></h1>
</ol>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#id2">Usage</a></h1>
<h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
<p>To use this module you need to:</p>
<ol class="arabic simple">
<li>Go to a <em>Product &gt; Inventory tab</em>.</li>
Expand All @@ -406,24 +407,24 @@ <h1><a class="toc-backref" href="#id2">Usage</a></h1>
</ol>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#id3">Bug Tracker</a></h1>
<h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/stock-logistics-workflow/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/stock-logistics-workflow/issues/new?body=module:%20stock_picking_auto_create_lot%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h1><a class="toc-backref" href="#id4">Credits</a></h1>
<h1><a class="toc-backref" href="#toc-entry-4">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#id5">Authors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-5">Authors</a></h2>
<ul class="simple">
<li>ACSONE SA/NV</li>
<li>Tecnativa</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#id6">Contributors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<ul class="simple">
<li>Carlos Dauden &lt;<a class="reference external" href="mailto:carlos.dauden&#64;tecnativa.com">carlos.dauden&#64;tecnativa.com</a>&gt;</li>
<li>Sergio Teruel &lt;<a class="reference external" href="mailto:sergio.teruel&#64;tecnativa.com">sergio.teruel&#64;tecnativa.com</a>&gt;</li>
Expand All @@ -437,14 +438,14 @@ <h2><a class="toc-backref" href="#id6">Contributors</a></h2>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#id7">Maintainers</a></h2>
<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>
<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>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external" href="https://github.com/sergio-teruel"><img alt="sergio-teruel" src="https://github.com/sergio-teruel.png?size=40px" /></a></p>
<p><a class="reference external image-reference" href="https://github.com/sergio-teruel"><img alt="sergio-teruel" src="https://github.com/sergio-teruel.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/stock-logistics-workflow/tree/16.0/stock_picking_auto_create_lot">OCA/stock-logistics-workflow</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
Expand Down
Loading
Loading