Skip to content

Commit

Permalink
[ADD] stock_release_channel_plan_process_end_time
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaudoux committed Jul 28, 2023
1 parent 79c5ddd commit fd432d6
Show file tree
Hide file tree
Showing 14 changed files with 161 additions and 0 deletions.
6 changes: 6 additions & 0 deletions setup/stock_release_channel_plan_process_end_time/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,
)
1 change: 1 addition & 0 deletions stock_release_channel_plan_process_end_time/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
wait 4 da boat
1 change: 1 addition & 0 deletions stock_release_channel_plan_process_end_time/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import wizards
24 changes: 24 additions & 0 deletions stock_release_channel_plan_process_end_time/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2023 Jacques-Etienne Baudoux (BCIM) <je@bcim.be>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Stock Release Channel Plan Process End Time",
"summary": "Glue module between release channel plan and process end time",
"version": "16.0.1.0.0",
"development_status": "Beta",
"license": "AGPL-3",
"author": "BCIM,Odoo Community Association (OCA)",
"maintainers": ["jbaudoux"],
"website": "https://github.com/OCA/wms",
"depends": [
"stock_release_channel_plan",
"stock_release_channel_process_end_time",
],
"data": [
"wizards/launch_plan.xml",
],
"demo": [
"demo/stock_release_channel.xml",
],
"auto_install": True,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2023 Jacques-Etienne Baudoux (BCIM) <je@bcim.be>
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo noupdate="1">

<record model="stock.release.channel" id="stock_release_channel_plan.stock_release_channel_mon_thu1">
<field name="warehouse_id" ref="stock.warehouse0" />
<field name="process_end_time">10.0</field>
</record>
<record model="stock.release.channel" id="stock_release_channel_plan.stock_release_channel_mon_thu2">
<field name="warehouse_id" ref="stock.warehouse0" />
<field name="process_end_time">14.0</field>
</record>
<record model="stock.release.channel" id="stock_release_channel_plan.stock_release_channel_tue_fri1">
<field name="warehouse_id" ref="stock.warehouse0" />
<field name="process_end_time">10.0</field>
</record>
<record model="stock.release.channel" id="stock_release_channel_plan.stock_release_channel_tue_fri2">
<field name="warehouse_id" ref="stock.warehouse0" />
<field name="process_end_time">14.0</field>
</record>
<record model="stock.release.channel" id="stock_release_channel_plan.stock_release_channel_wed1">
<field name="warehouse_id" ref="stock.warehouse0" />
<field name="process_end_time">10.0</field>
</record>
<record model="stock.release.channel" id="stock_release_channel_plan.stock_release_channel_wed2">
<field name="warehouse_id" ref="stock.warehouse0" />
<field name="process_end_time">14.0</field>
</record>

</odoo>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Jacques-Etienne Baudoux <je@bcim.be>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**Financial support**

* Alcyon Belux
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
At launching a plan, a process end date is set on each release channel of the
plan. It is then up to you to process the content of the release channel and at
then end, close it and make it asleep.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_stock_release_channel_plan
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright 2023 Jacques-Etienne Baudoux (BCIM) <je@bcim.be>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from datetime import datetime
import pytz

from odoo import fields
from odoo.addons.partner_tz.tools.tz_utils import tz_to_utc_naive_datetime
from odoo.addons.stock_release_channel_plan.tests import test_stock_release_channel_plan
from odoo.addons.stock_release_channel_process_end_time.utils import float_to_time


class TestStockReleaseChannelPlan(
test_stock_release_channel_plan.TestStockReleaseChannelPlan
):
def test_launch_plan(self):
channel = self.plan1_channel1
channel.process_end_date = False
tz_name = "Europe/Brussels"
channel.warehouse_id.partner_id.tz = tz_name
super().test_launch_plan()
end_time = float_to_time(channel.process_end_time) # in TZ
end_date = datetime.combine(fields.Date.context_today(channel), end_time) # in TZ
end_date_utc = tz_to_utc_naive_datetime(channel.process_end_time_tz, end_date)
self.assertEqual(
channel.process_end_date,
end_date_utc,
)
# Local Time is 10
offset = pytz.timezone(tz_name).utcoffset(datetime.now()).total_seconds() /3600
self.assertEqual(
channel.process_end_date.hour,
10 - offset,
)
return
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import launch_plan
32 changes: 32 additions & 0 deletions stock_release_channel_plan_process_end_time/wizards/launch_plan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2023 Jacques-Etienne Baudoux (BCIM) <je@bcim.be>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from datetime import datetime

from odoo import api, fields, models

from odoo.addons.partner_tz.tools.tz_utils import tz_to_utc_naive_datetime
from odoo.addons.stock_release_channel_process_end_time.utils import float_to_time


class StockReleaseChannelPlanWizardLaunch(models.TransientModel):
_inherit = "stock.release.channel.plan.wizard.launch"

process_end_date = fields.Date(
required=True,
default=fields.Date.context_today,
)

@api.model
def _action_launch(self, channels):
channels_to_wakeup = channels.filtered("is_action_wake_up_allowed")
# Wake up the channels
super()._action_launch(channels)
# Override the process end date
for channel in channels_to_wakeup:
end_time = float_to_time(channel.process_end_time) # in TZ
end_date = datetime.combine(self.process_end_date, end_time) # in TZ
tz = channel.process_end_time_tz or 'UTC'
end_date_utc = tz_to_utc_naive_datetime(tz, end_date)
channel.write({"process_end_date": end_date_utc})
return
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2023 Jacques-Etienne Baudoux (BCIM) <je@bcim.be>
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>

<record model="ir.ui.view" id="stock_release_channel_plan_wizard_launch_form_view">
<field name="model">stock.release.channel.plan.wizard.launch</field>
<field
name="inherit_id"
ref="stock_release_channel_plan.stock_release_channel_plan_wizard_launch_form_view"
/>
<field name="arch" type="xml">
<form>
<field name="preparation_plan_id" position="after">
<field name="process_end_date" default_focus="1" />
</field>
</form>
</field>
</record>

</odoo>

0 comments on commit fd432d6

Please sign in to comment.