diff --git a/stock_owner_restriction/README.rst b/stock_owner_restriction/README.rst index 662a6fcc..a97485cb 100644 --- a/stock_owner_restriction/README.rst +++ b/stock_owner_restriction/README.rst @@ -2,10 +2,13 @@ Stock Owner Restriction ======================= -.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:885d32742bfef03a27c8c9373bfecefea44e5758c69cc6f525399e7aa025751b + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png :target: https://odoo-community.org/page/development-status @@ -19,11 +22,11 @@ Stock Owner Restriction .. |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_owner_restriction :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 restriction of product quantities (quants) for stock operations such as reserve quantities @@ -46,6 +49,12 @@ To configure this module you need to: #. Select an operation type, or create a new one, and set *Owner Restriction* field to the desired value. +Developers notes + +This module update the context dependency of product quantity available to be computed +correctly. If you need get product quantity available for an owner yo need set the +context key "force_restricted_owner_id". + Usage ===== @@ -91,7 +100,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_owner_restriction/__manifest__.py b/stock_owner_restriction/__manifest__.py index 6a1a9249..1916009c 100644 --- a/stock_owner_restriction/__manifest__.py +++ b/stock_owner_restriction/__manifest__.py @@ -4,7 +4,7 @@ { "name": "Stock Owner Restriction", "summary": "Do not reserve quantity with assigned owner", - "version": "16.0.1.0.0", + "version": "16.0.1.1.2", "development_status": "Beta", "category": "stock", "website": "https://github.com/OCA/stock-logistics-workflow", diff --git a/stock_owner_restriction/i18n/es.po b/stock_owner_restriction/i18n/es.po index ce340967..55abe6fa 100644 --- a/stock_owner_restriction/i18n/es.po +++ b/stock_owner_restriction/i18n/es.po @@ -7,21 +7,21 @@ msgstr "" "Project-Id-Version: Odoo Server 13.0\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2020-11-10 20:46+0000\n" -"PO-Revision-Date: 2020-11-10 21:48+0100\n" -"Last-Translator: Sergio Teruel \n" +"PO-Revision-Date: 2023-10-15 20:38+0000\n" +"Last-Translator: Ivorra78 \n" "Language-Team: \n" -"Language: es_ES\n" +"Language: es\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"Plural-Forms: nplurals=2; plural=(n != 1);\n" -"X-Generator: Poedit 2.3\n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" #. module: stock_owner_restriction #: model:ir.model.fields,field_description:stock_owner_restriction.field_stock_picking__owner_restriction #: model:ir.model.fields,field_description:stock_owner_restriction.field_stock_picking_type__owner_restriction -msgid "Owner restriction" -msgstr "Restricción de cantidad disponible" +msgid "Owner Restriction" +msgstr "Restricción del propietario" #. module: stock_owner_restriction #: model_terms:ir.ui.view,arch_db:stock_owner_restriction.view_picking_type_form @@ -38,15 +38,20 @@ msgstr "Tipo de operación" msgid "Picking partner" msgstr "Dirección de entrega del albarán" +#. module: stock_owner_restriction +#: model:ir.model.fields.selection,name:stock_owner_restriction.selection__stock_picking_type__owner_restriction__partner_or_unassigned +msgid "Picking partner or unassigned owner" +msgstr "" + #. module: stock_owner_restriction #: model:ir.model,name:stock_owner_restriction.model_product_product -msgid "Product" -msgstr "Producto" +msgid "Product Variant" +msgstr "Variante del Producto" #. module: stock_owner_restriction #: model:ir.model,name:stock_owner_restriction.model_stock_quant msgid "Quants" -msgstr "Quants" +msgstr "Cants" #. module: stock_owner_restriction #: model:ir.model.fields.selection,name:stock_owner_restriction.selection__stock_picking_type__owner_restriction__standard_behavior @@ -67,3 +72,9 @@ msgstr "Transferir" #: model:ir.model.fields.selection,name:stock_owner_restriction.selection__stock_picking_type__owner_restriction__unassigned_owner msgid "Unassigned owner" msgstr "Propietario no asignado" + +#~ msgid "Owner restriction" +#~ msgstr "Restricción de cantidad disponible" + +#~ msgid "Product" +#~ msgstr "Producto" diff --git a/stock_owner_restriction/i18n/fr.po b/stock_owner_restriction/i18n/fr.po new file mode 100644 index 00000000..55adc9ba --- /dev/null +++ b/stock_owner_restriction/i18n/fr.po @@ -0,0 +1,73 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_owner_restriction +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2025-01-31 16:05+0000\n" +"Last-Translator: Arnaud LAYEC \n" +"Language-Team: none\n" +"Language: fr\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 5.6.2\n" + +#. module: stock_owner_restriction +#: model:ir.model.fields,field_description:stock_owner_restriction.field_stock_picking__owner_restriction +#: model:ir.model.fields,field_description:stock_owner_restriction.field_stock_picking_type__owner_restriction +msgid "Owner Restriction" +msgstr "Restriction de propriétaire" + +#. module: stock_owner_restriction +#: model_terms:ir.ui.view,arch_db:stock_owner_restriction.view_picking_type_form +msgid "Owner settings" +msgstr "Paramètres de propriétaire" + +#. module: stock_owner_restriction +#: model:ir.model,name:stock_owner_restriction.model_stock_picking_type +msgid "Picking Type" +msgstr "Type de transfert" + +#. module: stock_owner_restriction +#: model:ir.model.fields.selection,name:stock_owner_restriction.selection__stock_picking_type__owner_restriction__picking_partner +msgid "Picking partner" +msgstr "Contact du transfert" + +#. module: stock_owner_restriction +#: model:ir.model.fields.selection,name:stock_owner_restriction.selection__stock_picking_type__owner_restriction__partner_or_unassigned +msgid "Picking partner or unassigned owner" +msgstr "" + +#. module: stock_owner_restriction +#: model:ir.model,name:stock_owner_restriction.model_product_product +msgid "Product Variant" +msgstr "Variante de produit" + +#. module: stock_owner_restriction +#: model:ir.model,name:stock_owner_restriction.model_stock_quant +msgid "Quants" +msgstr "Quantités" + +#. module: stock_owner_restriction +#: model:ir.model.fields.selection,name:stock_owner_restriction.selection__stock_picking_type__owner_restriction__standard_behavior +msgid "Standard behavior" +msgstr "Comportement standard" + +#. module: stock_owner_restriction +#: model:ir.model,name:stock_owner_restriction.model_stock_move +msgid "Stock Move" +msgstr "Mouvement de stock" + +#. module: stock_owner_restriction +#: model:ir.model,name:stock_owner_restriction.model_stock_picking +msgid "Transfer" +msgstr "Transfert" + +#. module: stock_owner_restriction +#: model:ir.model.fields.selection,name:stock_owner_restriction.selection__stock_picking_type__owner_restriction__unassigned_owner +msgid "Unassigned owner" +msgstr "Propriétaire non assigné" diff --git a/stock_owner_restriction/i18n/it.po b/stock_owner_restriction/i18n/it.po new file mode 100644 index 00000000..453ebf79 --- /dev/null +++ b/stock_owner_restriction/i18n/it.po @@ -0,0 +1,73 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_owner_restriction +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2025-01-22 12:06+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 5.6.2\n" + +#. module: stock_owner_restriction +#: model:ir.model.fields,field_description:stock_owner_restriction.field_stock_picking__owner_restriction +#: model:ir.model.fields,field_description:stock_owner_restriction.field_stock_picking_type__owner_restriction +msgid "Owner Restriction" +msgstr "Restrizione proprietario" + +#. module: stock_owner_restriction +#: model_terms:ir.ui.view,arch_db:stock_owner_restriction.view_picking_type_form +msgid "Owner settings" +msgstr "Impostazioni proprietario" + +#. module: stock_owner_restriction +#: model:ir.model,name:stock_owner_restriction.model_stock_picking_type +msgid "Picking Type" +msgstr "Tipo prelievo" + +#. module: stock_owner_restriction +#: model:ir.model.fields.selection,name:stock_owner_restriction.selection__stock_picking_type__owner_restriction__picking_partner +msgid "Picking partner" +msgstr "Partner prelievo" + +#. module: stock_owner_restriction +#: model:ir.model.fields.selection,name:stock_owner_restriction.selection__stock_picking_type__owner_restriction__partner_or_unassigned +msgid "Picking partner or unassigned owner" +msgstr "Partner prelievo o proprietario non assegnato" + +#. module: stock_owner_restriction +#: model:ir.model,name:stock_owner_restriction.model_product_product +msgid "Product Variant" +msgstr "Variante prodotto" + +#. module: stock_owner_restriction +#: model:ir.model,name:stock_owner_restriction.model_stock_quant +msgid "Quants" +msgstr "Quanti" + +#. module: stock_owner_restriction +#: model:ir.model.fields.selection,name:stock_owner_restriction.selection__stock_picking_type__owner_restriction__standard_behavior +msgid "Standard behavior" +msgstr "Comportamento standard" + +#. module: stock_owner_restriction +#: model:ir.model,name:stock_owner_restriction.model_stock_move +msgid "Stock Move" +msgstr "Movimento di magazzino" + +#. module: stock_owner_restriction +#: model:ir.model,name:stock_owner_restriction.model_stock_picking +msgid "Transfer" +msgstr "Trasferimento" + +#. module: stock_owner_restriction +#: model:ir.model.fields.selection,name:stock_owner_restriction.selection__stock_picking_type__owner_restriction__unassigned_owner +msgid "Unassigned owner" +msgstr "Prprietario non assegnato" diff --git a/stock_owner_restriction/i18n/stock_owner_restriction.pot b/stock_owner_restriction/i18n/stock_owner_restriction.pot index cf3c6830..44e18056 100644 --- a/stock_owner_restriction/i18n/stock_owner_restriction.pot +++ b/stock_owner_restriction/i18n/stock_owner_restriction.pot @@ -4,7 +4,7 @@ # msgid "" msgstr "" -"Project-Id-Version: Odoo Server 15.0\n" +"Project-Id-Version: Odoo Server 16.0\n" "Report-Msgid-Bugs-To: \n" "Last-Translator: \n" "Language-Team: \n" @@ -34,9 +34,14 @@ msgstr "" msgid "Picking partner" msgstr "" +#. module: stock_owner_restriction +#: model:ir.model.fields.selection,name:stock_owner_restriction.selection__stock_picking_type__owner_restriction__partner_or_unassigned +msgid "Picking partner or unassigned owner" +msgstr "" + #. module: stock_owner_restriction #: model:ir.model,name:stock_owner_restriction.model_product_product -msgid "Product" +msgid "Product Variant" msgstr "" #. module: stock_owner_restriction diff --git a/stock_owner_restriction/models/product.py b/stock_owner_restriction/models/product.py index 7bc54d74..a7162cdd 100644 --- a/stock_owner_restriction/models/product.py +++ b/stock_owner_restriction/models/product.py @@ -1,7 +1,7 @@ # Copyright 2020 Carlos Dauden - Tecnativa # Copyright 2020 Sergio Teruel - Tecnativa # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from odoo import models +from odoo import api, models class ProductProduct(models.Model): @@ -34,3 +34,11 @@ def _search_qty_available_new( return super(ProductProduct, new_self)._search_qty_available_new( operator, value, lot_id=lot_id, owner_id=owner_id, package_id=package_id ) + + @api.depends_context("force_restricted_owner_id") + def _compute_quantities(self): + # Add force_restricted_owner_id to depends_context to compute qty when this + # key change. + # For example, in a report you want to print all stock available from a product + # and stock available from one owner. + return super()._compute_quantities() diff --git a/stock_owner_restriction/models/stock_move.py b/stock_owner_restriction/models/stock_move.py index 2f3430dc..2f36dbc6 100644 --- a/stock_owner_restriction/models/stock_move.py +++ b/stock_owner_restriction/models/stock_move.py @@ -1,6 +1,6 @@ # Copyright 2020 Carlos Dauden - Tecnativa # Copyright 2020 Sergio Teruel - Tecnativa -# Copyright 2023-2024 Quartile Limited +# Copyright 2023-2024 Quartile # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from collections import defaultdict @@ -24,14 +24,6 @@ def _compute_restrict_partner_id(self): else: move.restrict_partner_id = False - # pylint: disable=W8110 - @api.depends("restrict_partner_id") - def _compute_forecast_information(self): - for move in self: - if move.picking_type_id.owner_restriction == "picking_partner": - move = move.with_context(owner_id=move.restrict_partner_id.id) - super(StockMove, move)._compute_forecast_information() - def _get_moves_to_assign_with_standard_behavior(self): """This method is expected to be extended as necessary. e.g. you may not want to handle subcontracting receipts (whose picking type is normal incoming receipt @@ -39,7 +31,8 @@ def _get_moves_to_assign_with_standard_behavior(self): those moves. """ return self.filtered( - lambda m: m.picking_type_id.owner_restriction == "standard_behavior" + lambda m: not m.picking_type_id + or m.picking_type_id.owner_restriction == "standard_behavior" ) def _get_owner_restriction(self): @@ -54,11 +47,10 @@ def _get_owner_for_assign(self): needs to be applied to moves in manufacturing orders. """ self.ensure_one() - return ( - self.move_dest_ids.restrict_partner_id - or self.picking_id.owner_id - or self.picking_id.partner_id - ) + partner = self.move_dest_ids.picking_id.owner_id + if not partner: + partner = self.picking_id.owner_id or self.picking_id.partner_id + return partner def _action_assign(self, force_qty=False): # Split moves by picking type owner behavior restriction to process @@ -78,6 +70,20 @@ def _action_assign(self, force_qty=False): StockMove, moves_to_assign.with_context(force_restricted_owner_id=owner_id), )._action_assign(force_qty=force_qty) + if ( + owner_id + and moves_to_assign.picking_type_id.owner_restriction + == "partner_or_unassigned" + and sum( + move.reserved_availability - move.product_uom_qty + for move in moves_to_assign + ) + < 0 + ): + super( + StockMove, + moves_to_assign.with_context(force_restricted_owner_id=False), + )._action_assign(force_qty=force_qty) return res def _update_reserved_quantity( diff --git a/stock_owner_restriction/models/stock_picking_type.py b/stock_owner_restriction/models/stock_picking_type.py index 0dc85226..1b41ff63 100644 --- a/stock_owner_restriction/models/stock_picking_type.py +++ b/stock_owner_restriction/models/stock_picking_type.py @@ -9,9 +9,10 @@ class StockPickingType(models.Model): owner_restriction = fields.Selection( [ - ("standard_behavior", "Standard Behavior"), - ("unassigned_owner", "Unassigned Owner"), - ("picking_partner", "Picking Partner"), + ("standard_behavior", "Standard behavior"), + ("unassigned_owner", "Unassigned owner"), + ("picking_partner", "Picking partner"), + ("partner_or_unassigned", "Picking partner or unassigned owner"), ], default="standard_behavior", ) diff --git a/stock_owner_restriction/models/stock_quant.py b/stock_owner_restriction/models/stock_quant.py index 8edc5326..eea4226a 100644 --- a/stock_owner_restriction/models/stock_quant.py +++ b/stock_owner_restriction/models/stock_quant.py @@ -9,6 +9,14 @@ class StockQuant(models.Model): _inherit = "stock.quant" + @api.model + def _get_restriction_owner_id(self, location_id, owner_id): + """Hook to allow modify the owner of quants to gather. + By default prevent a negative quant from being created with owner instead of + reducing the original quant when a return is made by assigning owner. + """ + return owner_id if location_id.usage != "customer" else None + def _gather( self, product_id, @@ -23,7 +31,7 @@ def _gather( location_id, lot_id=lot_id, package_id=package_id, - owner_id=owner_id, + owner_id=self._get_restriction_owner_id(location_id, owner_id), strict=strict, ) restricted_owner = self.env.context.get("force_restricted_owner_id", None) diff --git a/stock_owner_restriction/readme/CONFIGURE.rst b/stock_owner_restriction/readme/CONFIGURE.rst index f8874be8..c1d25fb0 100644 --- a/stock_owner_restriction/readme/CONFIGURE.rst +++ b/stock_owner_restriction/readme/CONFIGURE.rst @@ -6,3 +6,9 @@ To configure this module you need to: #. Go to *Inventory > Configuration > Operation Types*. #. Select an operation type, or create a new one, and set *Owner Restriction* field to the desired value. + +Developers notes + +This module update the context dependency of product quantity available to be computed +correctly. If you need get product quantity available for an owner yo need set the +context key "force_restricted_owner_id". diff --git a/stock_owner_restriction/static/description/index.html b/stock_owner_restriction/static/description/index.html index a690b688..f5df7e7a 100644 --- a/stock_owner_restriction/static/description/index.html +++ b/stock_owner_restriction/static/description/index.html @@ -1,20 +1,20 @@ - - + Stock Owner Restriction