diff --git a/internal_stock_quant_package/README.rst b/internal_stock_quant_package/README.rst new file mode 100644 index 00000000000..39e3949f277 --- /dev/null +++ b/internal_stock_quant_package/README.rst @@ -0,0 +1,118 @@ +============================ +Internal Stock Quant Package +============================ + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |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--tracking-lightgray.png?logo=github + :target: https://github.com/OCA/stock-logistics-tracking/tree/16.0/internal_stock_quant_package + :alt: OCA/stock-logistics-tracking +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/stock-logistics-tracking-16-0/stock-logistics-tracking-16-0-internal_stock_quant_package + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/stock-logistics-tracking&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows to declare internal stock quant package. + +Sometimes, when an operator is picking, he needs to put the product in +internal packages placed on his trolley that will be emptied later. + +Two kinds of operations can lead to the emptying of the internal packages: + + * when product from the internal packages will be 'put in pack' at the pack station (in a pick / pack / ship scenario) + + * when a carrier will load his truck with the products from the internal packages (in a pick / ship scenario) + +This modules extends the stock module to add the concept of internal stock +quant package and therefore allows you to manage this kind of operational need. +It ensures that the internal stock quant packages are emptied when required +depending on the picking type configuration. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +As this addon rely on the concept of "internal" packages. If you want to +use packages into your picking operations, you need first to activate the +package functionality in the stock settings (see the "Operations" section). + +Then, you need to create packages and set them as internal. This is done +by going to Inventory > Products > Packages and clicking on the "Create". +(Don't forget to tick the "Internal use" box). + +By default, when you put your products into an internal package when processing +a picking, once the picking is done, the package is automatically emptied. +You can change this behavior at 2 levels: + +1. At the picking type level: go to "Inventory > Configuration > Operation +Types" and edit the picking type you want to change. Then, untick the "Empty +Internal Package On Transfer" box. (By default internal packages are always +emptied when the picking is done). + +2. At the picking type level for a specific carrier: go to "Inventory > +Configuration > Operation Types" and edit the picking type you want to change. +Then, add or remove lines in the "Stock Internal Package Config Line" table. +You can add a line for a specific carrier and tick/untick the "Empty" box. + +To know if internal packages must be emptied or not for a given picking, the +system will first check if a configuration line exists on the picking type for +the carrier of the picking. If a line exists, the system will use the value +of the "Empty" box. If no line exists, the system will use the value of the +"Empty Internal Package On Transfer" box of the picking type. + +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 +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* ACSONE SA/NV + +Contributors +~~~~~~~~~~~~ + +* Hughes Damry + +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. + +This module is part of the `OCA/stock-logistics-tracking `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/internal_stock_quant_package/__init__.py b/internal_stock_quant_package/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/internal_stock_quant_package/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/internal_stock_quant_package/__manifest__.py b/internal_stock_quant_package/__manifest__.py new file mode 100644 index 00000000000..fd1ca222ca6 --- /dev/null +++ b/internal_stock_quant_package/__manifest__.py @@ -0,0 +1,18 @@ +# Copyright 2021 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Internal Stock Quant Package", + "summary": "This module allows to declare internal stock quant package", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/stock-logistics-tracking", + "depends": ["stock", "delivery_procurement_group_carrier"], + "data": [ + "security/ir.model.access.csv", + "views/stock_quant_package_views.xml", + "views/stock_picking_type_views.xml", + ], + "installable": True, +} diff --git a/internal_stock_quant_package/i18n/fr_BE.po b/internal_stock_quant_package/i18n/fr_BE.po new file mode 100644 index 00000000000..526383200c1 --- /dev/null +++ b/internal_stock_quant_package/i18n/fr_BE.po @@ -0,0 +1,116 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * internal_stock_quant_package +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-02-09 12:56+0000\n" +"PO-Revision-Date: 2023-02-09 12:56+0000\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: internal_stock_quant_package +#: model:ir.model.fields,field_description:internal_stock_quant_package.field_stock_internal_package_config_line__create_uid +msgid "Created by" +msgstr "" + +#. module: internal_stock_quant_package +#: model:ir.model.fields,field_description:internal_stock_quant_package.field_stock_internal_package_config_line__create_date +msgid "Created on" +msgstr "" + +#. module: internal_stock_quant_package +#: model:ir.model.fields,field_description:internal_stock_quant_package.field_stock_internal_package_config_line__delivery_carrier_id +msgid "Delivery Carrier" +msgstr "" + +#. module: internal_stock_quant_package +#: model:ir.model.fields,field_description:internal_stock_quant_package.field_stock_internal_package_config_line__display_name +msgid "Display Name" +msgstr "" + +#. module: internal_stock_quant_package +#: model:ir.model.fields,field_description:internal_stock_quant_package.field_stock_internal_package_config_line__empty +msgid "Empty" +msgstr "" + +#. module: internal_stock_quant_package +#: model:ir.model.fields,field_description:internal_stock_quant_package.field_stock_picking__empty_internal_package_on_transfer +#: model:ir.model.fields,field_description:internal_stock_quant_package.field_stock_picking_type__empty_internal_package_on_transfer +msgid "Empty Internal Package On Transfer" +msgstr "Vider les colis internes lors du transfert?" + +#. module: internal_stock_quant_package +#: model:ir.model.fields,field_description:internal_stock_quant_package.field_stock_internal_package_config_line__id +msgid "ID" +msgstr "" + +#. module: internal_stock_quant_package +#: model:ir.model.fields,help:internal_stock_quant_package.field_stock_picking_type__empty_internal_package_on_transfer +msgid "" +"If set internal packages are emptied after the transfer or when products are" +" put in pack." +msgstr "" +"Si coché, les colis internes sont vidés une fois la préparation terminée ou " +"lorsqu'on fait la mise en colis." + +#. module: internal_stock_quant_package +#: model_terms:ir.ui.view,arch_db:internal_stock_quant_package.stock_quant_package_search_view +msgid "Internal" +msgstr "Interne" + +#. module: internal_stock_quant_package +#: model:ir.model,name:internal_stock_quant_package.model_stock_internal_package_config_line +msgid "Internal Package Configuration Line" +msgstr "Vider les colis internes lors du transfert?" + +#. module: internal_stock_quant_package +#: model:ir.model.fields,field_description:internal_stock_quant_package.field_stock_quant_package__is_internal +msgid "Internal use?" +msgstr "Usage interne?" + +#. module: internal_stock_quant_package +#: model:ir.model.fields,field_description:internal_stock_quant_package.field_stock_internal_package_config_line____last_update +msgid "Last Modified on" +msgstr "" + +#. module: internal_stock_quant_package +#: model:ir.model.fields,field_description:internal_stock_quant_package.field_stock_internal_package_config_line__write_uid +msgid "Last Updated by" +msgstr "" + +#. module: internal_stock_quant_package +#: model:ir.model.fields,field_description:internal_stock_quant_package.field_stock_internal_package_config_line__write_date +msgid "Last Updated on" +msgstr "" + +#. module: internal_stock_quant_package +#: model:ir.model,name:internal_stock_quant_package.model_stock_quant_package +msgid "Packages" +msgstr "Colis" + +#. module: internal_stock_quant_package +#: model:ir.model,name:internal_stock_quant_package.model_stock_picking_type +msgid "Picking Type" +msgstr "" + +#. module: internal_stock_quant_package +#: model:ir.model.fields,field_description:internal_stock_quant_package.field_stock_picking_type__stock_internal_package_config_line_ids +msgid "Stock Internal Package Config Line" +msgstr "Vider les colis internes lors du transfert?" + +#. module: internal_stock_quant_package +#: model:ir.model.fields,field_description:internal_stock_quant_package.field_stock_internal_package_config_line__stock_picking_type_id +msgid "Stock Picking Type" +msgstr "" + +#. module: internal_stock_quant_package +#: model:ir.model,name:internal_stock_quant_package.model_stock_picking +msgid "Transfer" +msgstr "Transfert" diff --git a/internal_stock_quant_package/i18n/internal_stock_quant_package.pot b/internal_stock_quant_package/i18n/internal_stock_quant_package.pot new file mode 100644 index 00000000000..9dc8532675a --- /dev/null +++ b/internal_stock_quant_package/i18n/internal_stock_quant_package.pot @@ -0,0 +1,114 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * internal_stock_quant_package +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-02-09 12:56+0000\n" +"PO-Revision-Date: 2023-02-09 12:56+0000\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: internal_stock_quant_package +#: model:ir.model.fields,field_description:internal_stock_quant_package.field_stock_internal_package_config_line__create_uid +msgid "Created by" +msgstr "" + +#. module: internal_stock_quant_package +#: model:ir.model.fields,field_description:internal_stock_quant_package.field_stock_internal_package_config_line__create_date +msgid "Created on" +msgstr "" + +#. module: internal_stock_quant_package +#: model:ir.model.fields,field_description:internal_stock_quant_package.field_stock_internal_package_config_line__delivery_carrier_id +msgid "Delivery Carrier" +msgstr "" + +#. module: internal_stock_quant_package +#: model:ir.model.fields,field_description:internal_stock_quant_package.field_stock_internal_package_config_line__display_name +msgid "Display Name" +msgstr "" + +#. module: internal_stock_quant_package +#: model:ir.model.fields,field_description:internal_stock_quant_package.field_stock_internal_package_config_line__empty +msgid "Empty" +msgstr "" + +#. module: internal_stock_quant_package +#: model:ir.model.fields,field_description:internal_stock_quant_package.field_stock_picking__empty_internal_package_on_transfer +#: model:ir.model.fields,field_description:internal_stock_quant_package.field_stock_picking_type__empty_internal_package_on_transfer +msgid "Empty Internal Package On Transfer" +msgstr "" + +#. module: internal_stock_quant_package +#: model:ir.model.fields,field_description:internal_stock_quant_package.field_stock_internal_package_config_line__id +msgid "ID" +msgstr "" + +#. module: internal_stock_quant_package +#: model:ir.model.fields,help:internal_stock_quant_package.field_stock_picking_type__empty_internal_package_on_transfer +msgid "" +"If set internal packages are emptied after the transfer or when products are" +" put in pack." +msgstr "" + +#. module: internal_stock_quant_package +#: model_terms:ir.ui.view,arch_db:internal_stock_quant_package.stock_quant_package_search_view +msgid "Internal" +msgstr "" + +#. module: internal_stock_quant_package +#: model:ir.model,name:internal_stock_quant_package.model_stock_internal_package_config_line +msgid "Internal Package Configuration Line" +msgstr "" + +#. module: internal_stock_quant_package +#: model:ir.model.fields,field_description:internal_stock_quant_package.field_stock_quant_package__is_internal +msgid "Internal use?" +msgstr "" + +#. module: internal_stock_quant_package +#: model:ir.model.fields,field_description:internal_stock_quant_package.field_stock_internal_package_config_line____last_update +msgid "Last Modified on" +msgstr "" + +#. module: internal_stock_quant_package +#: model:ir.model.fields,field_description:internal_stock_quant_package.field_stock_internal_package_config_line__write_uid +msgid "Last Updated by" +msgstr "" + +#. module: internal_stock_quant_package +#: model:ir.model.fields,field_description:internal_stock_quant_package.field_stock_internal_package_config_line__write_date +msgid "Last Updated on" +msgstr "" + +#. module: internal_stock_quant_package +#: model:ir.model,name:internal_stock_quant_package.model_stock_quant_package +msgid "Packages" +msgstr "" + +#. module: internal_stock_quant_package +#: model:ir.model,name:internal_stock_quant_package.model_stock_picking_type +msgid "Picking Type" +msgstr "" + +#. module: internal_stock_quant_package +#: model:ir.model.fields,field_description:internal_stock_quant_package.field_stock_picking_type__stock_internal_package_config_line_ids +msgid "Stock Internal Package Config Line" +msgstr "" + +#. module: internal_stock_quant_package +#: model:ir.model.fields,field_description:internal_stock_quant_package.field_stock_internal_package_config_line__stock_picking_type_id +msgid "Stock Picking Type" +msgstr "" + +#. module: internal_stock_quant_package +#: model:ir.model,name:internal_stock_quant_package.model_stock_picking +msgid "Transfer" +msgstr "" diff --git a/internal_stock_quant_package/models/__init__.py b/internal_stock_quant_package/models/__init__.py new file mode 100644 index 00000000000..e39e3bd8636 --- /dev/null +++ b/internal_stock_quant_package/models/__init__.py @@ -0,0 +1,4 @@ +from . import stock_internal_package_config_line +from . import stock_picking_type +from . import stock_picking +from . import stock_quant_package diff --git a/internal_stock_quant_package/models/stock_internal_package_config_line.py b/internal_stock_quant_package/models/stock_internal_package_config_line.py new file mode 100644 index 00000000000..017c1c790d2 --- /dev/null +++ b/internal_stock_quant_package/models/stock_internal_package_config_line.py @@ -0,0 +1,33 @@ +# Copyright 2022 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class StockInternalPackageConfigLine(models.Model): + _name = "stock.internal.package.config.line" + _description = "Internal Package Configuration Line" + + empty = fields.Boolean() + delivery_carrier_id = fields.Many2one( + "delivery.carrier", + required=True, + ondelete="cascade", + ) + stock_picking_type_id = fields.Many2one( + "stock.picking.type", + required=True, + readonly=True, + ondelete="cascade", + ) + + def write(self, vals): + res = super().write(vals) + self._invalidate_empty_internal_package_on_transfer_cache() + return res + + def _invalidate_empty_internal_package_on_transfer_cache(self): + domain = [("stock_internal_package_config_line_ids", "in", self.ids)] + picking_types = self.env["stock.picking.type"].search(domain) + picking_types.clear_caches() + self.env["stock.picking"].invalidate_model() diff --git a/internal_stock_quant_package/models/stock_picking.py b/internal_stock_quant_package/models/stock_picking.py new file mode 100644 index 00000000000..b630db2a973 --- /dev/null +++ b/internal_stock_quant_package/models/stock_picking.py @@ -0,0 +1,60 @@ +# Copyright 2021 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class StockPicking(models.Model): + + _inherit = "stock.picking" + + empty_internal_package_on_transfer = fields.Boolean( + compute="_compute_empty_internal_package_on_transfer", + ) + + @api.depends("picking_type_id.empty_internal_package_on_transfer", "carrier_id") + def _compute_empty_internal_package_on_transfer(self): + for record in self: + carrier = record.carrier_id or record.group_id.carrier_id + carrier_id = carrier.id + picking_type_id = record.picking_type_id.id + value = self.env["stock.picking.type"]._empty_internal_package_on_transfer( + picking_type_id, + carrier_id, + ) + record.empty_internal_package_on_transfer = value + + def action_put_in_pack(self): + self._move_lines_clear_internal_result_packages() + return super().action_put_in_pack() + + def button_validate(self): + self._move_lines_clear_internal_result_packages() + res = super().button_validate() + self._empty_transferred_internal_packages() + return res + + def _empty_transferred_internal_packages(self): + """ + Remove products from internal quant packages on picking done + """ + pickings = self.filtered( + lambda p: p.empty_internal_package_on_transfer and p.state == "done" + ) + packages = pickings.mapped("move_line_ids.package_id") + internal_packages = packages.filtered("is_internal") + internal_packages.unpack() + + def _move_lines_clear_internal_result_packages(self): + """ + Remove links between move lines and stock quant package to ensure + that move lines are put into a non internal stock.quant.package + """ + move_lines = self._get_move_lines_internal_package_used_to_empty() + move_lines.write({"result_package_id": False}) + + def _get_move_lines_internal_package_used_to_empty(self): + pickings = self.filtered("empty_internal_package_on_transfer") + return pickings.mapped("move_line_ids").filtered( + lambda line: line.result_package_id.is_internal + ) diff --git a/internal_stock_quant_package/models/stock_picking_type.py b/internal_stock_quant_package/models/stock_picking_type.py new file mode 100644 index 00000000000..ebd6a96e169 --- /dev/null +++ b/internal_stock_quant_package/models/stock_picking_type.py @@ -0,0 +1,39 @@ +# Copyright 2021 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models, tools + + +class StockPickingType(models.Model): + + _inherit = "stock.picking.type" + + empty_internal_package_on_transfer = fields.Boolean( + help="If set internal packages are emptied after the transfer or " + "when products are put in pack.", + default=True, + ) + stock_internal_package_config_line_ids = fields.One2many( + comodel_name="stock.internal.package.config.line", + inverse_name="stock_picking_type_id", + ) + + @api.model + @tools.ormcache("picking_type_id", "carrier_id") + def _empty_internal_package_on_transfer(self, picking_type_id, carrier_id): + """ + To know if internal packages must be emptied: + 1. We check if the flag is set on the picking type + 2. We lookup if a specific configuration exists for the given partner + 3. If a specific configuration exists we return the value of this configuration + 4. Otherwise we return the value on the picking type. + """ + picking_type = self.browse(picking_type_id) + result = picking_type.empty_internal_package_on_transfer + lines = picking_type.stock_internal_package_config_line_ids + carrier_line = lines.filtered( + lambda cl: cl.delivery_carrier_id.id == carrier_id + ) + if carrier_line: + result = carrier_line.empty + return result diff --git a/internal_stock_quant_package/models/stock_quant_package.py b/internal_stock_quant_package/models/stock_quant_package.py new file mode 100644 index 00000000000..d79d476ea1e --- /dev/null +++ b/internal_stock_quant_package/models/stock_quant_package.py @@ -0,0 +1,11 @@ +# Copyright 2021 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class StockQuantPackage(models.Model): + + _inherit = "stock.quant.package" + + is_internal = fields.Boolean("Internal use?") diff --git a/internal_stock_quant_package/readme/CONTRIBUTORS.rst b/internal_stock_quant_package/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..abe377cff49 --- /dev/null +++ b/internal_stock_quant_package/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Hughes Damry diff --git a/internal_stock_quant_package/readme/DESCRIPTION.rst b/internal_stock_quant_package/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..a6b951e5360 --- /dev/null +++ b/internal_stock_quant_package/readme/DESCRIPTION.rst @@ -0,0 +1,15 @@ +This module allows to declare internal stock quant package. + +Sometimes, when an operator is picking, he needs to put the product in +internal packages placed on his trolley that will be emptied later. + +Two kinds of operations can lead to the emptying of the internal packages: + + * when product from the internal packages will be 'put in pack' at the pack station (in a pick / pack / ship scenario) + + * when a carrier will load his truck with the products from the internal packages (in a pick / ship scenario) + +This modules extends the stock module to add the concept of internal stock +quant package and therefore allows you to manage this kind of operational need. +It ensures that the internal stock quant packages are emptied when required +depending on the picking type configuration. diff --git a/internal_stock_quant_package/readme/USAGE.rst b/internal_stock_quant_package/readme/USAGE.rst new file mode 100644 index 00000000000..0dae52d80de --- /dev/null +++ b/internal_stock_quant_package/readme/USAGE.rst @@ -0,0 +1,26 @@ +As this addon rely on the concept of "internal" packages. If you want to +use packages into your picking operations, you need first to activate the +package functionality in the stock settings (see the "Operations" section). + +Then, you need to create packages and set them as internal. This is done +by going to Inventory > Products > Packages and clicking on the "Create". +(Don't forget to tick the "Internal use" box). + +By default, when you put your products into an internal package when processing +a picking, once the picking is done, the package is automatically emptied. +You can change this behavior at 2 levels: + +1. At the picking type level: go to "Inventory > Configuration > Operation +Types" and edit the picking type you want to change. Then, untick the "Empty +Internal Package On Transfer" box. (By default internal packages are always +emptied when the picking is done). +2. At the picking type level for a specific carrier: go to "Inventory > +Configuration > Operation Types" and edit the picking type you want to change. +Then, add or remove lines in the "Stock Internal Package Config Line" table. +You can add a line for a specific carrier and tick/untick the "Empty" box. + +To know if internal packages must be emptied or not for a given picking, the +system will first check if a configuration line exists on the picking type for +the carrier of the picking. If a line exists, the system will use the value +of the "Empty" box. If no line exists, the system will use the value of the +"Empty Internal Package On Transfer" box of the picking type. diff --git a/internal_stock_quant_package/security/ir.model.access.csv b/internal_stock_quant_package/security/ir.model.access.csv new file mode 100644 index 00000000000..45187ff8f5c --- /dev/null +++ b/internal_stock_quant_package/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +stock_internal_config_line_user_access,stock_internal_config_line_user_access,model_stock_internal_package_config_line,base.group_user,1,0,0,0 +stock_internal_config_line_manager_access,stock_internal_config_line_manager_access,model_stock_internal_package_config_line,stock.group_stock_manager,1,1,1,1 diff --git a/internal_stock_quant_package/static/description/index.html b/internal_stock_quant_package/static/description/index.html new file mode 100644 index 00000000000..1cec77f6579 --- /dev/null +++ b/internal_stock_quant_package/static/description/index.html @@ -0,0 +1,458 @@ + + + + + + +Internal Stock Quant Package + + + +
+

Internal Stock Quant Package

+ + +

Beta License: AGPL-3 OCA/stock-logistics-tracking Translate me on Weblate Try me on Runboat

+

This module allows to declare internal stock quant package.

+

Sometimes, when an operator is picking, he needs to put the product in +internal packages placed on his trolley that will be emptied later.

+

Two kinds of operations can lead to the emptying of the internal packages:

+
+
    +
  • when product from the internal packages will be ‘put in pack’ at the pack station (in a pick / pack / ship scenario)
  • +
  • when a carrier will load his truck with the products from the internal packages (in a pick / ship scenario)
  • +
+
+

This modules extends the stock module to add the concept of internal stock +quant package and therefore allows you to manage this kind of operational need. +It ensures that the internal stock quant packages are emptied when required +depending on the picking type configuration.

+

Table of contents

+ +
+

Usage

+

As this addon rely on the concept of “internal” packages. If you want to +use packages into your picking operations, you need first to activate the +package functionality in the stock settings (see the “Operations” section).

+

Then, you need to create packages and set them as internal. This is done +by going to Inventory > Products > Packages and clicking on the “Create”. +(Don’t forget to tick the “Internal use” box).

+

By default, when you put your products into an internal package when processing +a picking, once the picking is done, the package is automatically emptied. +You can change this behavior at 2 levels:

+

1. At the picking type level: go to “Inventory > Configuration > Operation +Types” and edit the picking type you want to change. Then, untick the “Empty +Internal Package On Transfer” box. (By default internal packages are always +emptied when the picking is done).

+

2. At the picking type level for a specific carrier: go to “Inventory > +Configuration > Operation Types” and edit the picking type you want to change. +Then, add or remove lines in the “Stock Internal Package Config Line” table. +You can add a line for a specific carrier and tick/untick the “Empty” box.

+

To know if internal packages must be emptied or not for a given picking, the +system will first check if a configuration line exists on the picking type for +the carrier of the picking. If a line exists, the system will use the value +of the “Empty” box. If no line exists, the system will use the value of the +“Empty Internal Package On Transfer” box of the picking type.

+
+
+

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 +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • ACSONE SA/NV
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

This module is part of the OCA/stock-logistics-tracking project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/internal_stock_quant_package/tests/__init__.py b/internal_stock_quant_package/tests/__init__.py new file mode 100644 index 00000000000..77a4423aee0 --- /dev/null +++ b/internal_stock_quant_package/tests/__init__.py @@ -0,0 +1,2 @@ +from . import common +from . import test_stock_picking diff --git a/internal_stock_quant_package/tests/common.py b/internal_stock_quant_package/tests/common.py new file mode 100644 index 00000000000..d3e4362bce7 --- /dev/null +++ b/internal_stock_quant_package/tests/common.py @@ -0,0 +1,56 @@ +# Copyright 2021 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + + +from odoo.tests.common import TransactionCase + + +class TestStockPickingInternal(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env( + context=dict( + cls.env.context, tracking_disable=True, test_queue_job_no_delay=True + ) + ) + + cls.picking_type_out = cls.env.ref("stock.picking_type_out") + cls.picking_type_out.empty_internal_package_on_transfer = True + cls.internal_package = cls.env["stock.quant.package"].create( + {"is_internal": True} + ) + cls.external_package = cls.env["stock.quant.package"].create({}) + cls.product_a = cls.env["product.product"].create( + {"name": "Product A", "type": "product"} + ) + cls.customer_location = cls.env.ref("stock.stock_location_customers") + cls.stock_location = cls.env.ref("stock.stock_location_stock") + cls.picking = cls.env["stock.picking"].create( + { + "picking_type_id": cls.picking_type_out.id, + "location_dest_id": cls.customer_location.id, + "location_id": cls.stock_location.id, + } + ) + cls.env["stock.move"].create( + { + "name": cls.product_a.name, + "product_id": cls.product_a.id, + "product_uom_qty": 1, + "product_uom": cls.product_a.uom_id.id, + "picking_id": cls.picking.id, + "location_dest_id": cls.customer_location.id, + "location_id": cls.stock_location.id, + } + ) + wiz = cls.env["stock.change.product.qty"].create( + { + "product_id": cls.product_a.id, + "product_tmpl_id": cls.product_a.product_tmpl_id.id, + "new_quantity": 1, + } + ) + wiz.change_product_qty() + + cls.picking.action_assign() diff --git a/internal_stock_quant_package/tests/test_stock_picking.py b/internal_stock_quant_package/tests/test_stock_picking.py new file mode 100644 index 00000000000..e13dfbaec25 --- /dev/null +++ b/internal_stock_quant_package/tests/test_stock_picking.py @@ -0,0 +1,104 @@ +# Copyright 2021 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.exceptions import UserError +from odoo.fields import Command + +from .common import TestStockPickingInternal + + +class TestStockPickingInternalFlow(TestStockPickingInternal): + def test_internal_result_package_emptied_on_transfer(self): + self.assertEqual(self.picking.state, "assigned") + packop = self.picking.move_line_ids + packop.write( + dict( + result_package_id=self.internal_package.id, + qty_done=packop.reserved_qty, + ) + ) + self.picking.button_validate() + self.assertEqual(self.picking.state, "done") + self.assertFalse(self.internal_package.quant_ids) + + def test_internal_result_package_not_emptied_on_transfer(self): + self.picking_type_out.empty_internal_package_on_transfer = False + self.assertEqual(self.picking.state, "assigned") + packop = self.picking.move_line_ids + packop.write( + dict( + result_package_id=self.internal_package.id, + qty_done=packop.reserved_qty, + ) + ) + self.picking.button_validate() + self.assertEqual(self.picking.state, "done") + self.assertTrue(self.internal_package.quant_ids) + + def test_external_package_not_emptied_on_transfer(self): + self.assertEqual(self.picking.state, "assigned") + packop = self.picking.move_line_ids + packop.write( + dict( + result_package_id=self.external_package.id, + qty_done=packop.reserved_qty, + ) + ) + self.picking.button_validate() + self.assertEqual(self.picking.state, "done") + self.assertTrue(self.external_package.quant_ids) + + def test_internal_package_emptied_on_put_in_pack(self): + self.assertEqual(self.picking.state, "assigned") + packop = self.picking.move_line_ids + packop.write( + dict( + result_package_id=self.internal_package.id, + qty_done=packop.reserved_qty, + ) + ) + self.picking.action_put_in_pack() + self.assertNotEqual(packop.result_package_id, self.internal_package) + self.picking.button_validate() + self.assertEqual(self.picking.state, "done") + self.assertFalse(self.internal_package.quant_ids) + + def test_internal_package_not_emptied_on_put_in_pack(self): + self.picking_type_out.empty_internal_package_on_transfer = False + self.assertEqual(self.picking.state, "assigned") + packop = self.picking.move_line_ids + packop.write( + dict( + result_package_id=self.internal_package.id, + qty_done=packop.reserved_qty, + ) + ) + msg = "Please add 'Done' quantities to the picking to create a new pack." + with self.assertRaises(UserError, msg=msg): + self.picking.action_put_in_pack() + self.equal = self.assertEqual(packop.result_package_id, self.internal_package) + self.picking.button_validate() + self.assertEqual(self.picking.state, "done") + self.assertTrue(self.internal_package.quant_ids) + + def test_internal_package_emptied_on_transfer_depend_on_carrier(self): + carrier_product = self.env["product.product"].create( + {"name": "Product Carrier", "sale_ok": False, "type": "service"} + ) + carrier_1 = self.env["delivery.carrier"].create( + { + "name": "Carrier1", + "product_id": carrier_product.id, + } + ) + self.picking.carrier_id = carrier_1 + vals_line = {"empty": False, "delivery_carrier_id": carrier_1.id} + vals = {"stock_internal_package_config_line_ids": [Command.create(vals_line)]} + self.picking_type_out.write(vals) + + self.assertFalse(self.picking.empty_internal_package_on_transfer) + + line = self.picking_type_out.stock_internal_package_config_line_ids + line.empty = True + + self.assertTrue(self.picking.empty_internal_package_on_transfer) diff --git a/internal_stock_quant_package/views/stock_picking_type_views.xml b/internal_stock_quant_package/views/stock_picking_type_views.xml new file mode 100644 index 00000000000..8193c92d82c --- /dev/null +++ b/internal_stock_quant_package/views/stock_picking_type_views.xml @@ -0,0 +1,64 @@ + + + + + + stock.internal.package.config.line.form + stock.internal.package.config.line + +
+
+
+ + + + + + + + +
+
+
+ + + stock.picking.type.form (in internal_stock_quant_package) + stock.picking.type + + + + + + + + + + + + + + + + + stock.picking.type.tree (in internal_stock_quant_package) + stock.picking.type + + + + + + + + + + + + + + +
diff --git a/internal_stock_quant_package/views/stock_quant_package_views.xml b/internal_stock_quant_package/views/stock_quant_package_views.xml new file mode 100644 index 00000000000..d5cedcfcb7f --- /dev/null +++ b/internal_stock_quant_package/views/stock_quant_package_views.xml @@ -0,0 +1,49 @@ + + + + + + stock.quant.package.form (in internal_stock_quant_package) + stock.quant.package + + + + + + + + + + stock.quant.package.search (in internal_stock_quant_package) + stock.quant.package + + + + + + + + + + stock.quant.package.tree (in internal_stock_quant_package) + stock.quant.package + + + + + + + + + diff --git a/setup/internal_stock_quant_package/odoo/addons/internal_stock_quant_package b/setup/internal_stock_quant_package/odoo/addons/internal_stock_quant_package new file mode 120000 index 00000000000..00c9905e75d --- /dev/null +++ b/setup/internal_stock_quant_package/odoo/addons/internal_stock_quant_package @@ -0,0 +1 @@ +../../../../internal_stock_quant_package \ No newline at end of file diff --git a/setup/internal_stock_quant_package/setup.py b/setup/internal_stock_quant_package/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/internal_stock_quant_package/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)