Skip to content

Commit

Permalink
Merge PR #923 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by rousseldenis
  • Loading branch information
OCA-git-bot committed Apr 29, 2022
2 parents 5355b04 + 4fbed3c commit d5c647e
Show file tree
Hide file tree
Showing 25 changed files with 1,119 additions and 0 deletions.
6 changes: 6 additions & 0 deletions setup/stock_picking_auto_create_lot/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
108 changes: 108 additions & 0 deletions stock_picking_auto_create_lot/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
=============================
Stock Picking Auto Create Lot
=============================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
:target: https://odoo-community.org/page/development-status
:alt: Production/Stable
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--workflow-lightgray.png?logo=github
:target: https://github.com/OCA/stock-logistics-workflow/tree/14.0/stock_picking_auto_create_lot
:alt: OCA/stock-logistics-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/stock-logistics-workflow-14-0/stock-logistics-workflow-14-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/14.0
:alt: Try me on Runbot

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

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

**Table of contents**

.. contents::
:local:

Configuration
=============

To configure this module, you need to:

#. Go to a *Inventory > Configuration > Operation Types*.
#. Set 'auto create lot' option for this operation type.

#. Go to a *Inventory > Master Data > Products*.
#. Set 'auto create lot' option for the products you need.

Usage
=====

To use this module you need to:

#. Go to a *Product > Inventory tab*.
#. Set a tracking option for this product.
#. Set auto create lot.
#. Go to *Inventory > Incoming* and create one.
#. Validate picking without lot.

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
`feedback <https://github.com/OCA/stock-logistics-workflow/issues/new?body=module:%20stock_picking_auto_create_lot%0Aversion:%2014.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.

Credits
=======

Authors
~~~~~~~

* ACSONE SA/NV
* Tecnativa

Contributors
~~~~~~~~~~~~

* Carlos Dauden <carlos.dauden@tecnativa.com>
* Sergio Teruel <sergio.teruel@tecnativa.com>
* Pimolnat Suntian <pimolnats@ecosoft.co.th>
* Denis Roussel <denis.roussel@acsone.eu>

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

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.

.. |maintainer-sergio-teruel| image:: https://github.com/sergio-teruel.png?size=40px
:target: https://github.com/sergio-teruel
:alt: sergio-teruel

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-sergio-teruel|

This module is part of the `OCA/stock-logistics-workflow <https://github.com/OCA/stock-logistics-workflow/tree/14.0/stock_picking_auto_create_lot>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions stock_picking_auto_create_lot/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import models
17 changes: 17 additions & 0 deletions stock_picking_auto_create_lot/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2018 Tecnativa - Sergio Teruel
# Copyright 2020 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Stock Picking Auto Create Lot",
"summary": "Auto create lots for incoming pickings",
"version": "14.0.1.0.0",
"development_status": "Production/Stable",
"category": "stock",
"website": "https://github.com/OCA/stock-logistics-workflow",
"author": "ACSONE SA/NV, Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
"installable": True,
"depends": ["stock"],
"data": ["views/product_views.xml", "views/stock_picking_type_views.xml"],
"maintainers": ["sergio-teruel"],
}
49 changes: 49 additions & 0 deletions stock_picking_auto_create_lot/i18n/es.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 12.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-02-25 13:29+0000\n"
"PO-Revision-Date: 2019-02-25 13:29+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \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 "Auto crear lote"

#. module: stock_picking_auto_create_lot
#: model:ir.model,name:stock_picking_auto_create_lot.model_stock_picking_type
msgid "Picking Type"
msgstr "Tipo de albarán"

#. 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 ""

#. module: stock_picking_auto_create_lot
#: model:ir.model,name:stock_picking_auto_create_lot.model_product_template
msgid "Product Template"
msgstr "Plantilla de producto"

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

#. module: stock_picking_auto_create_lot
#: model:ir.model,name:stock_picking_auto_create_lot.model_stock_picking
msgid "Transfer"
msgstr "Transferir"
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# 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 13.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \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 ""

#. 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_stock_move_line
msgid "Product Moves (Stock Move Line)"
msgstr ""

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

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

#. module: stock_picking_auto_create_lot
#: model:ir.model,name:stock_picking_auto_create_lot.model_stock_picking
msgid "Transfer"
msgstr ""
49 changes: 49 additions & 0 deletions stock_picking_auto_create_lot/i18n/zh_CN.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 13.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2020-03-21 15:13+0000\n"
"Last-Translator: Dong <dong@freshoo.cn>\n"
"Language-Team: none\n"
"Language: zh_CN\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=1; plural=0;\n"
"X-Generator: Weblate 3.10\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 "自动创建批次"

#. 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_stock_move_line
msgid "Product Moves (Stock Move Line)"
msgstr ""

#. module: stock_picking_auto_create_lot
#: model:ir.model,name:stock_picking_auto_create_lot.model_product_template
msgid "Product Template"
msgstr "产品模版"

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

#. module: stock_picking_auto_create_lot
#: model:ir.model,name:stock_picking_auto_create_lot.model_stock_picking
msgid "Transfer"
msgstr "调拨"
6 changes: 6 additions & 0 deletions stock_picking_auto_create_lot/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import product
from . import stock_picking
from . import stock_picking_type
from . import stock_move_line
from . import stock_move
9 changes: 9 additions & 0 deletions stock_picking_auto_create_lot/models/product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright 2018 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models


class ProductTemplate(models.Model):
_inherit = "product.template"

auto_create_lot = fields.Boolean(string="Auto Create Lot")
23 changes: 23 additions & 0 deletions stock_picking_auto_create_lot/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2020 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, models


class StockMove(models.Model):

_inherit = "stock.move"

@api.depends(
"has_tracking",
"picking_type_id.auto_create_lot",
"product_id.auto_create_lot",
"picking_type_id.use_existing_lots",
"state",
)
def _compute_display_assign_serial(self):
super()._compute_display_assign_serial()
moves_not_display = self.filtered(
lambda m: m.picking_type_id.auto_create_lot and m.product_id.auto_create_lot
)
for move in moves_not_display:
move.display_assign_serial = False
39 changes: 39 additions & 0 deletions stock_picking_auto_create_lot/models/stock_move_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2020 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import models
from odoo.fields import first


class StockMoveLine(models.Model):

_inherit = "stock.move.line"

def _prepare_auto_lot_values(self):
"""
Prepare multi valued lots per line to use multi creation.
"""
self.ensure_one()
return {"product_id": self.product_id.id, "company_id": self.company_id.id}

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 = []
production_lot_obj = self.env["stock.production.lot"]
lots_by_product = dict()
for line in self:
values.append(line._prepare_auto_lot_values())
lots = production_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
31 changes: 31 additions & 0 deletions stock_picking_auto_create_lot/models/stock_picking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright 2018 Tecnativa - Sergio Teruel
# Copyright 2020 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import models


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

def _set_auto_lot(self):
"""
Allows to be called either by button or through code
"""
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
)
)
lines.set_lot_auto()

def _action_done(self):
self._set_auto_lot()
return super()._action_done()

def button_validate(self):
self._set_auto_lot()
return super().button_validate()
Loading

0 comments on commit d5c647e

Please sign in to comment.