Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][ADD] stock_release_channel_partner_delivery_window #753

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions setup/stock_release_channel_partner_delivery_window/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
91 changes: 91 additions & 0 deletions stock_release_channel_partner_delivery_window/README.rst
Original file line number Diff line number Diff line change
@@ -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:9460585d6c5a5df5a9818e01dd2f5c12a8119353619459ce20b4d3841ba94900
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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 <https://github.com/OCA/wms/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 <https://github.com/OCA/wms/issues/new?body=module:%20stock_release_channel_partner_delivery_window%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
~~~~~~~

* Camptocamp
* BCIM

Contributors
~~~~~~~~~~~~

* Nguyen Minh Chien <chien@trobz.com>
* Jacques-Etienne Baudoux <je@bcim.be>

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 <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-jbaudoux|

This module is part of the `OCA/wms <https://github.com/OCA/wms/tree/16.0/stock_release_channel_partner_delivery_window>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions stock_release_channel_partner_delivery_window/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
20 changes: 20 additions & 0 deletions stock_release_channel_partner_delivery_window/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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",
],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import stock_picking
from . import stock_release_channel
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Nguyen Minh Chien <chien@trobz.com>
* Jacques-Etienne Baudoux <je@bcim.be>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The development of this module has been financially supported by Camptocamp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module excludes the channel when its shipment date is not in Partner delivery window
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_release_window
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# 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")
cls.channel.respect_partner_delivery_time_windows = True

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)

@freeze_time("2023-09-01")
def test_assign_channel_no_respect_delivery_time_window(self):
self.channel.respect_partner_delivery_time_windows = False
fields.Date.today()
self.picking.partner_id = self.customer_time_window
self._assign_picking(self.picking)
self.assertEqual(self.channel, self.picking.release_channel_id)
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<record id="allo_stock_release_channel_form_view" model="ir.ui.view">
<field name="name">stock.release.channel.form</field>
<field name="model">stock.release.channel</field>
<field
name="inherit_id"
ref="stock_release_channel.stock_release_channel_form_view"
/>
<field name="arch" type="xml">
<field name="rule_domain" position="after">
<field name="respect_partner_delivery_time_windows" />
</field>
</field>
</record>

</odoo>