diff --git a/setup/stock_picking_type_shipping_policy_group_by/odoo/addons/stock_picking_type_shipping_policy_group_by b/setup/stock_picking_type_shipping_policy_group_by/odoo/addons/stock_picking_type_shipping_policy_group_by new file mode 120000 index 00000000000..29376692591 --- /dev/null +++ b/setup/stock_picking_type_shipping_policy_group_by/odoo/addons/stock_picking_type_shipping_policy_group_by @@ -0,0 +1 @@ +../../../../stock_picking_type_shipping_policy_group_by \ No newline at end of file diff --git a/setup/stock_picking_type_shipping_policy_group_by/setup.py b/setup/stock_picking_type_shipping_policy_group_by/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/stock_picking_type_shipping_policy_group_by/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/stock_picking_type_shipping_policy/models/stock_move.py b/stock_picking_type_shipping_policy/models/stock_move.py index 8e249eb8bac..f5eaadb85d1 100644 --- a/stock_picking_type_shipping_policy/models/stock_move.py +++ b/stock_picking_type_shipping_policy/models/stock_move.py @@ -7,11 +7,17 @@ class StockMove(models.Model): _inherit = "stock.move" - def _get_new_picking_values(self): - res = super()._get_new_picking_values() + def _shipping_policy_from_picking_type(self): picking_type = self.mapped("picking_type_id") if picking_type.shipping_policy == "force_as_soon_as_possible": - res["move_type"] = "direct" + return "direct" elif picking_type.shipping_policy == "force_all_products_ready": - res["move_type"] = "one" + return "one" + return None + + def _get_new_picking_values(self): + res = super()._get_new_picking_values() + picking_type_move_type = self._shipping_policy_from_picking_type() + if picking_type_move_type: + res["move_type"] = picking_type_move_type return res diff --git a/stock_picking_type_shipping_policy_group_by/__init__.py b/stock_picking_type_shipping_policy_group_by/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/stock_picking_type_shipping_policy_group_by/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/stock_picking_type_shipping_policy_group_by/__manifest__.py b/stock_picking_type_shipping_policy_group_by/__manifest__.py new file mode 100644 index 00000000000..49722f9dae9 --- /dev/null +++ b/stock_picking_type_shipping_policy_group_by/__manifest__.py @@ -0,0 +1,21 @@ +# Copyright 2020 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +{ + "name": "Stock Picking Type Shipping Policy - Group By Partner and Carrier", + "summary": "Glue module for Picking Type Shipping Policy" + " and Group Transfers by Partner and Carrier", + "version": "13.0.1.0.0", + "category": "Hidden", + "website": "https://github.com/OCA/wms", + "author": "Camptocamp, Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "auto_install": True, + "depends": [ + "stock_picking_type_shipping_policy", + # in stock-logistics-workflow + "stock_picking_group_by_partner_by_carrier", + ], + "data": [], +} diff --git a/stock_picking_type_shipping_policy_group_by/models/__init__.py b/stock_picking_type_shipping_policy_group_by/models/__init__.py new file mode 100644 index 00000000000..6bda2d2428e --- /dev/null +++ b/stock_picking_type_shipping_policy_group_by/models/__init__.py @@ -0,0 +1 @@ +from . import stock_move diff --git a/stock_picking_type_shipping_policy_group_by/models/stock_move.py b/stock_picking_type_shipping_policy_group_by/models/stock_move.py new file mode 100644 index 00000000000..16f4c2bf4cb --- /dev/null +++ b/stock_picking_type_shipping_policy_group_by/models/stock_move.py @@ -0,0 +1,14 @@ +# Copyright 2020 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +from odoo import models + + +class StockMove(models.Model): + _inherit = "stock.move" + + def _domain_search_picking_handle_move_type(self): + picking_type_move_type = self._shipping_policy_from_picking_type() + if picking_type_move_type: + return [("move_type", "=", picking_type_move_type)] + else: + return super()._domain_search_picking_handle_move_type() diff --git a/stock_picking_type_shipping_policy_group_by/readme/CONTRIBUTORS.rst b/stock_picking_type_shipping_policy_group_by/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..48286263cd3 --- /dev/null +++ b/stock_picking_type_shipping_policy_group_by/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Guewen Baconnier diff --git a/stock_picking_type_shipping_policy_group_by/readme/DESCRIPTION.rst b/stock_picking_type_shipping_policy_group_by/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..e59704c660c --- /dev/null +++ b/stock_picking_type_shipping_policy_group_by/readme/DESCRIPTION.rst @@ -0,0 +1,4 @@ +Technical module to make the following addons work properly together: + +* ``stock_picking_type_shipping_policy`` +* ``stock_picking_group_by_partner_by_carrier`` diff --git a/stock_picking_type_shipping_policy_group_by/static/description/icon.png b/stock_picking_type_shipping_policy_group_by/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/stock_picking_type_shipping_policy_group_by/static/description/icon.png differ diff --git a/stock_picking_type_shipping_policy_group_by/tests/__init__.py b/stock_picking_type_shipping_policy_group_by/tests/__init__.py new file mode 100644 index 00000000000..5437c31a2e9 --- /dev/null +++ b/stock_picking_type_shipping_policy_group_by/tests/__init__.py @@ -0,0 +1,2 @@ +# Copyright 2020 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) diff --git a/stock_picking_type_shipping_policy_group_by/tests/test_stock_picking_type_shipping_policy.py b/stock_picking_type_shipping_policy_group_by/tests/test_stock_picking_type_shipping_policy.py new file mode 100644 index 00000000000..79e1f1a1c8b --- /dev/null +++ b/stock_picking_type_shipping_policy_group_by/tests/test_stock_picking_type_shipping_policy.py @@ -0,0 +1,48 @@ +# Copyright 2020 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +from odoo.tests import SavepointCase + + +class TestPickingTypeShippingPolicyGroupBy(SavepointCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) + cls.warehouse = cls.env.ref("stock.warehouse0") + cls.pick_type = cls.warehouse.pick_type_id + cls.pick_type.group_pickings = True + cls.product = cls.env.ref("product.product_product_9") + cls.group = cls.env["procurement.group"].create( + {"name": "Test 1", "move_type": "direct"} + ) + + def _create_single_move(self, picking_type, group, product): + move_vals = { + "name": product.name, + "picking_type_id": picking_type.id, + "product_id": product.id, + "product_uom_qty": 1.0, + "product_uom": product.uom_id.id, + "location_id": picking_type.default_location_src_id.id, + "location_dest_id": picking_type.default_location_dest_id.id, + "state": "confirmed", + "procure_method": "make_to_stock", + "group_id": group.id, + } + return self.env["stock.move"].create(move_vals) + + def test_shipping_policy_force_picking_type_one(self): + """When the picking type changes move_type to 'one' + + If the picking type creates a stock.picking for move1 with move_type + 'one', ensure that the method that assign move2 to a new picking search + using the same move_type. + """ + self.group.move_type = "direct" + self.pick_type.shipping_policy = "force_all_products_ready" + move1 = self._create_single_move(self.pick_type, self.group, self.product) + move1._assign_picking() + move2 = self._create_single_move(self.pick_type, self.group, self.product) + move2._assign_picking() + self.assertEqual(move1.picking_id, move2.picking_id) + self.assertEqual(move1.picking_id.move_type, "one")