From 97d0ea36ff18c092e6051a4a7f5b8c114ca05032 Mon Sep 17 00:00:00 2001 From: Aungkokolin1997 Date: Fri, 12 Jul 2024 10:03:41 +0000 Subject: [PATCH] upd --- stock_picking_auto_create_lot/README.rst | 15 ++-- stock_picking_auto_create_lot/__manifest__.py | 2 +- stock_picking_auto_create_lot/i18n/it.po | 49 +++++++++++++ stock_picking_auto_create_lot/i18n/nl.po | 49 +++++++++++++ .../models/__init__.py | 2 +- .../models/stock_move_line.py | 37 ++-------- .../models/stock_picking.py | 42 +++++++----- .../static/description/index.html | 43 ++++++------ .../test_stock_picking_auto_create_lot.py | 68 ++++++++++++++----- 9 files changed, 211 insertions(+), 96 deletions(-) create mode 100644 stock_picking_auto_create_lot/i18n/it.po create mode 100644 stock_picking_auto_create_lot/i18n/nl.po diff --git a/stock_picking_auto_create_lot/README.rst b/stock_picking_auto_create_lot/README.rst index ff6dee5b..56f74272 100644 --- a/stock_picking_auto_create_lot/README.rst +++ b/stock_picking_auto_create_lot/README.rst @@ -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 @@ -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. @@ -60,7 +63,7 @@ Bug Tracker Bugs are tracked on `GitHub 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 `_. Do not contact contributors directly about support or help with technical issues. diff --git a/stock_picking_auto_create_lot/__manifest__.py b/stock_picking_auto_create_lot/__manifest__.py index bfc49912..26d9c246 100644 --- a/stock_picking_auto_create_lot/__manifest__.py +++ b/stock_picking_auto_create_lot/__manifest__.py @@ -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", diff --git a/stock_picking_auto_create_lot/i18n/it.po b/stock_picking_auto_create_lot/i18n/it.po new file mode 100644 index 00000000..b65d964d --- /dev/null +++ b/stock_picking_auto_create_lot/i18n/it.po @@ -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 \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" diff --git a/stock_picking_auto_create_lot/i18n/nl.po b/stock_picking_auto_create_lot/i18n/nl.po new file mode 100644 index 00000000..121cc4db --- /dev/null +++ b/stock_picking_auto_create_lot/i18n/nl.po @@ -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 \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" diff --git a/stock_picking_auto_create_lot/models/__init__.py b/stock_picking_auto_create_lot/models/__init__.py index c8a0ac35..d873a374 100644 --- a/stock_picking_auto_create_lot/models/__init__.py +++ b/stock_picking_auto_create_lot/models/__init__.py @@ -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 diff --git a/stock_picking_auto_create_lot/models/stock_move_line.py b/stock_picking_auto_create_lot/models/stock_move_line.py index 2635505f..5fb9dd26 100644 --- a/stock_picking_auto_create_lot/models/stock_move_line.py +++ b/stock_picking_auto_create_lot/models/stock_move_line.py @@ -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). + 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") diff --git a/stock_picking_auto_create_lot/models/stock_picking.py b/stock_picking_auto_create_lot/models/stock_picking.py index bee1f7e9..834de5a0 100644 --- a/stock_picking_auto_create_lot/models/stock_picking.py +++ b/stock_picking_auto_create_lot/models/stock_picking.py @@ -8,19 +8,20 @@ class StockPicking(models.Model): _inherit = "stock.picking" - def _prepare_auto_lot_domain(self, picking): - """ - Prepare the domain to search for stock.move.line records - that require automatic lot assignment. + 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", "=", picking.id), + ("picking_id", "in", self.ids), ("lot_id", "=", False), ("lot_name", "=", False), ("product_id.tracking", "!=", "none"), ("product_id.auto_create_lot", "=", True), ] - if not picking._check_immediate(): + if not immediate: domain = expression.AND([domain, [("qty_done", ">", 0)]]) return domain @@ -29,18 +30,23 @@ def _set_auto_lot(self): Allows to be called either by button or through code. """ lines_to_set = self.env["stock.move.line"] - domains = [] - # Prepare domains for each picking that allows auto lot creation - for picking in self: - if not picking.picking_type_id.auto_create_lot: - continue - domain = self._prepare_auto_lot_domain(picking) - domains.append(domain) - if domains: - combined_domain = expression.OR(domains) - lines_to_set = lines_to_set.search(combined_domain) - if lines_to_set: - lines_to_set.set_lot_auto() + pickings = self.filtered(lambda p: p.picking_type_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 + ) + 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() diff --git a/stock_picking_auto_create_lot/static/description/index.html b/stock_picking_auto_create_lot/static/description/index.html index d02791d0..b51d8c91 100644 --- a/stock_picking_auto_create_lot/static/description/index.html +++ b/stock_picking_auto_create_lot/static/description/index.html @@ -1,20 +1,19 @@ - - + Stock Picking Auto Create Lot