diff --git a/setup/stock_move_common_dest/odoo/addons/stock_move_common_dest b/setup/stock_move_common_dest/odoo/addons/stock_move_common_dest new file mode 120000 index 000000000..79e655cd1 --- /dev/null +++ b/setup/stock_move_common_dest/odoo/addons/stock_move_common_dest @@ -0,0 +1 @@ +../../../../stock_move_common_dest \ No newline at end of file diff --git a/setup/stock_move_common_dest/setup.py b/setup/stock_move_common_dest/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/stock_move_common_dest/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/stock_move_common_dest/README.rst b/stock_move_common_dest/README.rst new file mode 100644 index 000000000..b55c751d9 --- /dev/null +++ b/stock_move_common_dest/README.rst @@ -0,0 +1,75 @@ +============================= +Stock Move Common Destination +============================= + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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--warehouse-lightgray.png?logo=github + :target: https://github.com/OCA/stock-logistics-warehouse/tree/13.0/stock_move_common_dest + :alt: OCA/stock-logistics-warehouse +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-13-0/stock-logistics-warehouse-13-0-stock_move_common_dest + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/153/13.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds a M2m field `common_dest_move_ids` on `stock.move` in order +to compute all the moves having a chained destination move sharing the same +picking as the actual move's destination move. + +**Table of contents** + +.. contents:: + :local: + +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 +~~~~~~~ + +* Camptocamp + +Contributors +~~~~~~~~~~~~ + +* Akim Juillerat + +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-warehouse `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/stock_move_common_dest/__init__.py b/stock_move_common_dest/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/stock_move_common_dest/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/stock_move_common_dest/__manifest__.py b/stock_move_common_dest/__manifest__.py new file mode 100644 index 000000000..a032c6d46 --- /dev/null +++ b/stock_move_common_dest/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2020 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +{ + "name": "Stock Move Common Destination", + "summary": "Adds field for common destination moves", + "version": "14.0.1.0.0", + "category": "Warehouse Management", + "website": "https://github.com/OCA/stock-logistics-warehouse", + "author": "Camptocamp, Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": ["stock"], + "data": ["views/stock_move.xml"], +} diff --git a/stock_move_common_dest/i18n/stock_move_common_dest.pot b/stock_move_common_dest/i18n/stock_move_common_dest.pot new file mode 100644 index 000000000..89b734306 --- /dev/null +++ b/stock_move_common_dest/i18n/stock_move_common_dest.pot @@ -0,0 +1,36 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_move_common_dest +# +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_move_common_dest +#: model:ir.model.fields,help:stock_move_common_dest.field_stock_move__common_dest_move_ids +msgid "" +"All the stock moves having a chained destination move sharing the same " +"picking as the actual move's destination move" +msgstr "" + +#. module: stock_move_common_dest +#: model:ir.model.fields,field_description:stock_move_common_dest.field_stock_move__common_dest_move_ids +msgid "Common Dest Move" +msgstr "" + +#. module: stock_move_common_dest +#: model_terms:ir.ui.view,arch_db:stock_move_common_dest.view_move_form_inherit +msgid "Common destination moves" +msgstr "" + +#. module: stock_move_common_dest +#: model:ir.model,name:stock_move_common_dest.model_stock_move +msgid "Stock Move" +msgstr "" diff --git a/stock_move_common_dest/models/__init__.py b/stock_move_common_dest/models/__init__.py new file mode 100644 index 000000000..6bda2d242 --- /dev/null +++ b/stock_move_common_dest/models/__init__.py @@ -0,0 +1 @@ +from . import stock_move diff --git a/stock_move_common_dest/models/stock_move.py b/stock_move_common_dest/models/stock_move.py new file mode 100644 index 000000000..7cb652daf --- /dev/null +++ b/stock_move_common_dest/models/stock_move.py @@ -0,0 +1,74 @@ +# Copyright 2020 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +from odoo import api, fields, models +from odoo.osv.expression import FALSE_DOMAIN + + +class StockMove(models.Model): + + _inherit = "stock.move" + + common_dest_move_ids = fields.Many2many( + "stock.move", + compute="_compute_common_dest_move_ids", + search="_search_compute_dest_move_ids", + help="All the stock moves having a chained destination move sharing the" + " same picking as the actual move's destination move", + ) + + def _flush_common_dest_move_query(self): + # flush is necessary before a SELECT + self.flush(["move_orig_ids", "move_dest_ids"]) + + def _common_dest_move_query(self): + sql = """SELECT smmr.move_orig_id move_id + , array_agg(smmr2.move_orig_id) common_move_dest_ids + FROM stock_move_move_rel smmr + , stock_move sm_dest + , stock_picking sp + , stock_move sm_pick + , stock_move_move_rel smmr2 + WHERE smmr.move_dest_id = sm_dest.id + AND sm_dest.picking_id = sp.id + AND sp.id = sm_pick.picking_id + AND sm_pick.id = smmr2.move_dest_id + AND smmr.move_orig_id != smmr2.move_orig_id + AND smmr.move_orig_id IN %s + GROUP BY smmr.move_orig_id; + """ + return sql + + @api.depends( + "move_dest_ids", + "move_dest_ids.picking_id", + "move_dest_ids.picking_id.move_lines", + "move_dest_ids.picking_id.move_lines.move_orig_ids", + ) + def _compute_common_dest_move_ids(self): + self._flush_common_dest_move_query() + sql = self._common_dest_move_query() + self.env.cr.execute(sql, (tuple(self.ids),)) + res = { + row.get("move_id"): row.get("common_move_dest_ids") + for row in self.env.cr.dictfetchall() + } + for move in self: + common_move_ids = res.get(move.id) + if common_move_ids: + move.common_dest_move_ids = [(6, 0, common_move_ids)] + else: + move.common_dest_move_ids = [(5, 0, 0)] + + def _search_compute_dest_move_ids(self, operator, value): + moves = self.search([("id", operator, value)]) + if not moves: + return FALSE_DOMAIN + self._flush_common_dest_move_query() + sql = self._common_dest_move_query() + self.env.cr.execute(sql, (tuple(moves.ids),)) + res = [ + move_dest_id + for row in self.env.cr.dictfetchall() + for move_dest_id in row.get("common_move_dest_ids") or [] + ] + return [("id", "in", res)] diff --git a/stock_move_common_dest/readme/CONTRIBUTORS.rst b/stock_move_common_dest/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..e31e2f0c4 --- /dev/null +++ b/stock_move_common_dest/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Akim Juillerat diff --git a/stock_move_common_dest/readme/DESCRIPTION.rst b/stock_move_common_dest/readme/DESCRIPTION.rst new file mode 100644 index 000000000..84a7e9bea --- /dev/null +++ b/stock_move_common_dest/readme/DESCRIPTION.rst @@ -0,0 +1,3 @@ +This module adds a M2m field `common_dest_move_ids` on `stock.move` in order +to compute all the moves having a chained destination move sharing the same +picking as the actual move's destination move. diff --git a/stock_move_common_dest/static/description/icon.png b/stock_move_common_dest/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/stock_move_common_dest/static/description/icon.png differ diff --git a/stock_move_common_dest/static/description/index.html b/stock_move_common_dest/static/description/index.html new file mode 100644 index 000000000..86ef79acd --- /dev/null +++ b/stock_move_common_dest/static/description/index.html @@ -0,0 +1,421 @@ + + + + + + +Stock Move Common Destination + + + +
+

Stock Move Common Destination

+ + +

Beta License: AGPL-3 OCA/stock-logistics-warehouse Translate me on Weblate Try me on Runbot

+

This module adds a M2m field common_dest_move_ids on stock.move in order +to compute all the moves having a chained destination move sharing the same +picking as the actual move’s destination move.

+

Table of contents

+ +
+

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

+
    +
  • Camptocamp
  • +
+
+ +
+

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-warehouse project on GitHub.

+

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

+
+
+
+ + diff --git a/stock_move_common_dest/tests/__init__.py b/stock_move_common_dest/tests/__init__.py new file mode 100644 index 000000000..d59b1a6af --- /dev/null +++ b/stock_move_common_dest/tests/__init__.py @@ -0,0 +1 @@ +from . import test_move_common_dest diff --git a/stock_move_common_dest/tests/test_move_common_dest.py b/stock_move_common_dest/tests/test_move_common_dest.py new file mode 100644 index 000000000..9af07ff05 --- /dev/null +++ b/stock_move_common_dest/tests/test_move_common_dest.py @@ -0,0 +1,174 @@ +# Copyright 2020 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +from odoo.tests import SavepointCase + + +class TestCommonMoveDest(SavepointCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) + cls.partner_delta = cls.env.ref("base.res_partner_4") + cls.warehouse = cls.env.ref("stock.warehouse0") + cls.warehouse.write({"delivery_steps": "pick_pack_ship"}) + cls.customers_location = cls.env.ref("stock.stock_location_customers") + cls.output_location = cls.env.ref("stock.stock_location_output") + cls.packing_location = cls.env.ref("stock.location_pack_zone") + cls.stock_shelf_location = cls.env.ref("stock.stock_location_components") + cls.stock_shelf_2_location = cls.env.ref("stock.stock_location_14") + + cls.out_type = cls.warehouse.out_type_id + cls.pack_type = cls.warehouse.pack_type_id + cls.pick_type = cls.warehouse.pick_type_id + + cls.product_1 = cls.env["product.product"].create( + {"name": "Product 1", "type": "product"} + ) + cls.product_2 = cls.env["product.product"].create( + {"name": "Product 2", "type": "product"} + ) + + cls.procurement_group_1 = cls.env["procurement.group"].create( + {"name": "Test 1"} + ) + + def _init_inventory(self): + # Product 1 on shelf 1 + # Product 2 on shelf 2 + inventory = self.env["stock.inventory"].create({"name": "Test init"}) + inventory.action_start() + product_location_list = [ + (self.product_1, self.stock_shelf_location), + (self.product_2, self.stock_shelf_2_location), + ] + lines_vals = list() + for product, location in product_location_list: + lines_vals.append( + ( + 0, + 0, + { + "product_id": product.id, + "product_uom_id": product.uom_id.id, + "product_qty": 10.0, + "location_id": location.id, + }, + ) + ) + inventory.write({"line_ids": lines_vals}) + inventory.action_validate() + + def _create_pickings(self): + # Create delivery order + ship_order = self.env["stock.picking"].create( + { + "partner_id": self.partner_delta.id, + "location_id": self.output_location.id, + "location_dest_id": self.customers_location.id, + "picking_type_id": self.out_type.id, + } + ) + pack_order = self.env["stock.picking"].create( + { + "partner_id": self.partner_delta.id, + "location_id": self.packing_location.id, + "location_dest_id": self.output_location.id, + "picking_type_id": self.pack_type.id, + } + ) + pick_order = self.env["stock.picking"].create( + { + "partner_id": self.partner_delta.id, + "location_id": self.stock_shelf_location.id, + "location_dest_id": self.packing_location.id, + "picking_type_id": self.pick_type.id, + } + ) + pick_order_2 = self.env["stock.picking"].create( + { + "partner_id": self.partner_delta.id, + "location_id": self.stock_shelf_2_location.id, + "location_dest_id": self.packing_location.id, + "picking_type_id": self.pick_type.id, + } + ) + return ship_order, pack_order, pick_order, pick_order_2 + + def _create_move( + self, + picking, + product, + state="waiting", + procure_method="make_to_order", + move_dest=None, + ): + move_vals = { + "name": product.name, + "product_id": product.id, + "product_uom_qty": 2.0, + "product_uom": product.uom_id.id, + "picking_id": picking.id, + "location_id": picking.location_id.id, + "location_dest_id": picking.location_dest_id.id, + "state": state, + "procure_method": procure_method, + "group_id": self.procurement_group_1.id, + } + if move_dest: + move_vals["move_dest_ids"] = [(4, move_dest.id, False)] + return self.env["stock.move"].create(move_vals) + + def test_packing_sub_location(self): + self._init_inventory() + ( + ship_order_1, + pack_order_1, + pick_order_1a, + pick_order_1b, + ) = self._create_pickings() + ship_move_1a = self._create_move(ship_order_1, self.product_1) + pack_move_1a = self._create_move( + pack_order_1, self.product_1, move_dest=ship_move_1a + ) + pick_move_1a = self._create_move( + pick_order_1a, + self.product_1, + state="confirmed", + procure_method="make_to_stock", + move_dest=pack_move_1a, + ) + ship_move_1b = self._create_move(ship_order_1, self.product_2) + pack_move_1b = self._create_move( + pack_order_1, self.product_2, move_dest=ship_move_1b + ) + pick_move_1b = self._create_move( + pick_order_1b, + self.product_2, + state="confirmed", + procure_method="make_to_stock", + move_dest=pack_move_1b, + ) + self.assertEqual(pick_move_1a.common_dest_move_ids, pick_move_1b) + self.assertEqual(pick_move_1b.common_dest_move_ids, pick_move_1a) + self.assertEqual(pack_move_1a.common_dest_move_ids, pack_move_1b) + self.assertEqual(pack_move_1b.common_dest_move_ids, pack_move_1a) + self.assertFalse(ship_move_1a.common_dest_move_ids) + self.assertFalse(ship_move_1b.common_dest_move_ids) + self.assertEqual( + self.env["stock.move"].search( + [("common_dest_move_ids", "=", pick_move_1b.id)] + ), + pick_move_1a, + ) + self.assertEqual( + self.env["stock.move"].search( + [("common_dest_move_ids", "=", pick_move_1a.id)] + ), + pick_move_1b, + ) + self.assertEqual( + self.env["stock.move"].search( + [("common_dest_move_ids", "in", (pick_move_1a | pick_move_1b).ids)] + ), + pick_move_1a | pick_move_1b, + ) diff --git a/stock_move_common_dest/views/stock_move.xml b/stock_move_common_dest/views/stock_move.xml new file mode 100644 index 000000000..d18574a01 --- /dev/null +++ b/stock_move_common_dest/views/stock_move.xml @@ -0,0 +1,27 @@ + + + + stock.move.form.inherit + stock.move + + + + + + + + + + + + + + + + + +