diff --git a/setup/stock_release_channel_partner_delivery_window/odoo/addons/stock_release_channel_partner_delivery_window b/setup/stock_release_channel_partner_delivery_window/odoo/addons/stock_release_channel_partner_delivery_window new file mode 120000 index 00000000000..551dac8a467 --- /dev/null +++ b/setup/stock_release_channel_partner_delivery_window/odoo/addons/stock_release_channel_partner_delivery_window @@ -0,0 +1 @@ +../../../../stock_release_channel_partner_delivery_window \ No newline at end of file diff --git a/setup/stock_release_channel_partner_delivery_window/setup.py b/setup/stock_release_channel_partner_delivery_window/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/stock_release_channel_partner_delivery_window/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/stock_release_channel_partner_delivery_window/README.rst b/stock_release_channel_partner_delivery_window/README.rst new file mode 100644 index 00000000000..b3313c8e973 --- /dev/null +++ b/stock_release_channel_partner_delivery_window/README.rst @@ -0,0 +1,91 @@ +============================================= +Stock Release Channel Partner Delivery Window +============================================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:19aeedd318a1b32f8829dc2bad0e0c7a27141d473a05db3aa90b3a6694b46390 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fwms-lightgray.png?logo=github + :target: https://github.com/OCA/wms/tree/16.0/stock_release_channel_partner_delivery_window + :alt: OCA/wms +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/wms-16-0/wms-16-0-stock_release_channel_partner_delivery_window + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/wms&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module excludes the channel when its shipment date is not in Partner delivery window + +**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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Camptocamp +* BCIM + +Contributors +~~~~~~~~~~~~ + +* Nguyen Minh Chien +* Jacques-Etienne Baudoux + +Other credits +~~~~~~~~~~~~~ + +The development of this module has been financially supported by Camptocamp + +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. + +.. |maintainer-jbaudoux| image:: https://github.com/jbaudoux.png?size=40px + :target: https://github.com/jbaudoux + :alt: jbaudoux + +Current `maintainer `__: + +|maintainer-jbaudoux| + +This module is part of the `OCA/wms `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/stock_release_channel_partner_delivery_window/__init__.py b/stock_release_channel_partner_delivery_window/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/stock_release_channel_partner_delivery_window/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/stock_release_channel_partner_delivery_window/__manifest__.py b/stock_release_channel_partner_delivery_window/__manifest__.py new file mode 100644 index 00000000000..784d64df0df --- /dev/null +++ b/stock_release_channel_partner_delivery_window/__manifest__.py @@ -0,0 +1,20 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Stock Release Channel Partner Delivery Window", + "summary": """ + Allows to define an end date (and time) on a release channel and + propagate it to the concerned pickings""", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "maintainers": ["jbaudoux"], + "author": "Camptocamp, BCIM, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/wms", + "depends": [ + "stock_partner_delivery_window", + "stock_release_channel_shipment_lead_time", + ], + "data": [ + "views/stock_release_channel_view.xml", + ], +} diff --git a/stock_release_channel_partner_delivery_window/models/__init__.py b/stock_release_channel_partner_delivery_window/models/__init__.py new file mode 100644 index 00000000000..b82444463ee --- /dev/null +++ b/stock_release_channel_partner_delivery_window/models/__init__.py @@ -0,0 +1,2 @@ +from . import stock_picking +from . import stock_release_channel diff --git a/stock_release_channel_partner_delivery_window/models/stock_picking.py b/stock_release_channel_partner_delivery_window/models/stock_picking.py new file mode 100644 index 00000000000..9aad3829211 --- /dev/null +++ b/stock_release_channel_partner_delivery_window/models/stock_picking.py @@ -0,0 +1,15 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import models + + +class StockPicking(models.Model): + + _inherit = "stock.picking" + + def _find_release_channel_possible_candidate(self): + """Filter channels: make sure shipment date is in Partner window + :return: release channels + """ + channels = super()._find_release_channel_possible_candidate() + channels = channels.filter_release_channel_partner_window(self, self.partner_id) + return channels diff --git a/stock_release_channel_partner_delivery_window/models/stock_release_channel.py b/stock_release_channel_partner_delivery_window/models/stock_release_channel.py new file mode 100644 index 00000000000..33ed84b3e19 --- /dev/null +++ b/stock_release_channel_partner_delivery_window/models/stock_release_channel.py @@ -0,0 +1,42 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import fields, models + + +class StockReleaseChannel(models.Model): + + _inherit = "stock.release.channel" + + respect_partner_delivery_time_windows = fields.Boolean( + string="Respect Partner Delivery time windows", + default=False, + help=( + "If the delivery has moves linked to SO lines linked to SO that has" + " a commitment_date, then we never respect the partner time window " + "(it is not an exclusion selection criteria anymore)" + ), + ) + + def filter_release_channel_partner_window(self, picking, partner): + channels = self + if ( + not partner.delivery_time_preference + or partner.delivery_time_preference == "anytime" + ): + return channels + + for channel in self: + if not channel.shipment_date: + continue + shipment_datetime = fields.Datetime.to_datetime(channel.shipment_date) + if channel.process_end_date: + shipment_datetime = shipment_datetime.replace( + hour=channel.process_end_date.hour, + minute=channel.process_end_date.minute, + ) + if ( + channel.respect_partner_delivery_time_windows + and not picking.sale_id.commitment_date + and not partner.is_in_delivery_window(shipment_datetime) + ): + channels -= channel + return channels diff --git a/stock_release_channel_partner_delivery_window/readme/CONTRIBUTORS.rst b/stock_release_channel_partner_delivery_window/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..56d7f9ffc94 --- /dev/null +++ b/stock_release_channel_partner_delivery_window/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Nguyen Minh Chien +* Jacques-Etienne Baudoux diff --git a/stock_release_channel_partner_delivery_window/readme/CREDITS.rst b/stock_release_channel_partner_delivery_window/readme/CREDITS.rst new file mode 100644 index 00000000000..934a2b2dc64 --- /dev/null +++ b/stock_release_channel_partner_delivery_window/readme/CREDITS.rst @@ -0,0 +1 @@ +The development of this module has been financially supported by Camptocamp diff --git a/stock_release_channel_partner_delivery_window/readme/DESCRIPTION.rst b/stock_release_channel_partner_delivery_window/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..12d9a97f4f4 --- /dev/null +++ b/stock_release_channel_partner_delivery_window/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module excludes the channel when its shipment date is not in Partner delivery window diff --git a/stock_release_channel_partner_delivery_window/readme/USAGE.rst b/stock_release_channel_partner_delivery_window/readme/USAGE.rst new file mode 100644 index 00000000000..e69de29bb2d diff --git a/stock_release_channel_partner_delivery_window/static/description/icon.png b/stock_release_channel_partner_delivery_window/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/stock_release_channel_partner_delivery_window/static/description/icon.png differ diff --git a/stock_release_channel_partner_delivery_window/static/description/index.html b/stock_release_channel_partner_delivery_window/static/description/index.html new file mode 100644 index 00000000000..b7019f05fbd --- /dev/null +++ b/stock_release_channel_partner_delivery_window/static/description/index.html @@ -0,0 +1,430 @@ + + + + + + +Stock Release Channel Partner Delivery Window + + + +
+

Stock Release Channel Partner Delivery Window

+ + +

Beta License: AGPL-3 OCA/wms Translate me on Weblate Try me on Runboat

+

This module excludes the channel when its shipment date is not in Partner delivery window

+

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 to smash it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Camptocamp
  • +
  • BCIM
  • +
+
+
+

Contributors

+ +
+
+

Other credits

+

The development of this module has been financially supported by 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.

+

Current maintainer:

+

jbaudoux

+

This module is part of the OCA/wms project on GitHub.

+

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

+
+
+
+ + diff --git a/stock_release_channel_partner_delivery_window/tests/__init__.py b/stock_release_channel_partner_delivery_window/tests/__init__.py new file mode 100644 index 00000000000..ae6271e4aa7 --- /dev/null +++ b/stock_release_channel_partner_delivery_window/tests/__init__.py @@ -0,0 +1 @@ +from . import test_release_window diff --git a/stock_release_channel_partner_delivery_window/tests/test_release_window.py b/stock_release_channel_partner_delivery_window/tests/test_release_window.py new file mode 100644 index 00000000000..2dad8a55bc5 --- /dev/null +++ b/stock_release_channel_partner_delivery_window/tests/test_release_window.py @@ -0,0 +1,95 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from datetime import timedelta + +from freezegun import freeze_time + +from odoo import fields + +from odoo.addons.stock_release_channel.tests.common import ChannelReleaseCase + + +class ReleaseChannelEndDateCase(ChannelReleaseCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) + cls.customer_anytime = cls.env["res.partner"].create( + {"name": "Anytime", "delivery_time_preference": "anytime"} + ) + cls.customer_working_days = cls.env["res.partner"].create( + {"name": "Working Days", "delivery_time_preference": "workdays"} + ) + cls.customer_time_window = cls.env["res.partner"].create( + { + "name": "Time Window", + "delivery_time_preference": "time_windows", + "delivery_time_window_ids": [ + ( + 0, + 0, + { + "time_window_start": 0.00, + "time_window_end": 23.99, + "time_window_weekday_ids": [ + ( + 6, + 0, + [ + cls.env.ref( + "base_time_window.time_weekday_thursday" + ).id, + cls.env.ref( + "base_time_window.time_weekday_saturday" + ).id, + ], + ) + ], + }, + ) + ], + } + ) + cls.product = cls.env.ref("product.product_product_9") + cls.picking_type_delivery = cls.env.ref("stock.picking_type_out") + cls.location_stock = cls.env.ref("stock.stock_location_stock") + cls.location_customers = cls.env.ref("stock.stock_location_customers") + + def _assign_picking(self, picking): + picking.release_channel_id = False + picking.assign_release_channel() + + @freeze_time("2023-09-01") + def test_assign_channel_anytime(self): + today = fields.Date.today() + self.channel.process_end_time = 0 + self.channel.process_end_date = today + timedelta(days=1) # 2023-09-02 + # Anytime + self.picking.partner_id = self.customer_anytime + self._assign_picking(self.picking) + self.assertEqual(self.channel, self.picking.release_channel_id) + + @freeze_time("2023-09-01") + def test_assign_channel_workdays(self): + # Workdays + today = fields.Date.today() + self.channel.process_end_time = 0 + self.channel.process_end_date = today + timedelta(days=1) # 2023-09-02 + self.picking.partner_id = self.customer_working_days + self._assign_picking(self.picking) + self.assertNotEqual(self.channel, self.picking.release_channel_id) + self.channel.process_end_date = today + timedelta(days=4) # 2023-09-05 + self._assign_picking(self.picking) + self.assertEqual(self.channel, self.picking.release_channel_id) + + @freeze_time("2023-09-01") + def test_assign_channel_window(self): + # Window + today = fields.Date.today() + self.picking.partner_id = self.customer_time_window + self._assign_picking(self.picking) + self.assertNotEqual(self.channel, self.picking.release_channel_id) + self.channel.process_end_date = today + timedelta( + days=6 + ) # 2023-09-05: Thursday + self._assign_picking(self.picking) + self.assertEqual(self.channel, self.picking.release_channel_id) diff --git a/stock_release_channel_partner_delivery_window/views/stock_release_channel_view.xml b/stock_release_channel_partner_delivery_window/views/stock_release_channel_view.xml new file mode 100644 index 00000000000..eeb15dc4c56 --- /dev/null +++ b/stock_release_channel_partner_delivery_window/views/stock_release_channel_view.xml @@ -0,0 +1,18 @@ + + + + + stock.release.channel.form + stock.release.channel + + + + + + + + +