From d4db3901f408557843fa1fbc6108766ae07ec443 Mon Sep 17 00:00:00 2001 From: Ahmed Hagi Date: Thu, 5 Dec 2024 14:53:58 +0000 Subject: [PATCH 1/3] GH164696 - Stock delivery v12 --- delivery_carrier_calendar/README.rst | 5 +++ delivery_carrier_calendar/__init__.py | 1 + delivery_carrier_calendar/__manifest__.py | 14 +++++++ delivery_carrier_calendar/models/__init__.py | 2 + .../models/delivery_carrier.py | 38 +++++++++++++++++++ .../models/stock_picking.py | 32 ++++++++++++++++ .../views/delivery_carrier.xml | 14 +++++++ .../odoo/addons/delivery_carrier_calendar | 1 + setup/delivery_carrier_calendar/setup.py | 6 +++ 9 files changed, 113 insertions(+) create mode 100644 delivery_carrier_calendar/README.rst create mode 100644 delivery_carrier_calendar/__init__.py create mode 100644 delivery_carrier_calendar/__manifest__.py create mode 100644 delivery_carrier_calendar/models/__init__.py create mode 100644 delivery_carrier_calendar/models/delivery_carrier.py create mode 100644 delivery_carrier_calendar/models/stock_picking.py create mode 100644 delivery_carrier_calendar/views/delivery_carrier.xml create mode 120000 setup/delivery_carrier_calendar/odoo/addons/delivery_carrier_calendar create mode 100644 setup/delivery_carrier_calendar/setup.py diff --git a/delivery_carrier_calendar/README.rst b/delivery_carrier_calendar/README.rst new file mode 100644 index 0000000..8a24d9b --- /dev/null +++ b/delivery_carrier_calendar/README.rst @@ -0,0 +1,5 @@ +delivery_carrier_calendar +------------------------- + +Implement a resource calendar for delivery carrier indicating which days they +operate on. diff --git a/delivery_carrier_calendar/__init__.py b/delivery_carrier_calendar/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/delivery_carrier_calendar/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/delivery_carrier_calendar/__manifest__.py b/delivery_carrier_calendar/__manifest__.py new file mode 100644 index 0000000..fc5d9b0 --- /dev/null +++ b/delivery_carrier_calendar/__manifest__.py @@ -0,0 +1,14 @@ +{ + "name": "delivery_carrier_calendar", + "summary": "Delivery Carrier Calendar", + "author": "Glodo", + "website": "https://github.com/GlodoUK/odoo-addons", + "category": "Delivery", + "version": "12.0.1.0.0", + "depends": ["delivery", "resource"], + "data": [ + "views/delivery_carrier.xml", + ], + "demo": [], + "license": "Other proprietary", +} diff --git a/delivery_carrier_calendar/models/__init__.py b/delivery_carrier_calendar/models/__init__.py new file mode 100644 index 0000000..6edba1a --- /dev/null +++ b/delivery_carrier_calendar/models/__init__.py @@ -0,0 +1,2 @@ +from . import delivery_carrier +from . import stock_picking diff --git a/delivery_carrier_calendar/models/delivery_carrier.py b/delivery_carrier_calendar/models/delivery_carrier.py new file mode 100644 index 0000000..9751682 --- /dev/null +++ b/delivery_carrier_calendar/models/delivery_carrier.py @@ -0,0 +1,38 @@ +from dateutil.relativedelta import relativedelta + +from odoo import fields, models + + +class DeliveryCarrier(models.Model): + _inherit = "delivery.carrier" + + carrier_calendar_id = fields.Many2one("resource.calendar") + lead_time = fields.Integer( + string="Lead Days", + help="Lead time for this carrier, in days.", + default=0, + ) + + def plan_days( + self, + day_dt, + days=1, + compute_leaves=True, + domain=None, + safety_lead_days=1 + ): + self.ensure_one() + + lead_days = 0 + + if self.lead_time: + lead_days += self.lead_time + elif safety_lead_days: + lead_days += safety_lead_days + + if self.carrier_calendar_id: + return self.carrier_calendar_id.plan_days( + days + lead_days, day_dt, compute_leaves=compute_leaves, domain=domain + ) + + return day_dt + relativedelta(days=lead_days) \ No newline at end of file diff --git a/delivery_carrier_calendar/models/stock_picking.py b/delivery_carrier_calendar/models/stock_picking.py new file mode 100644 index 0000000..5a5a9e8 --- /dev/null +++ b/delivery_carrier_calendar/models/stock_picking.py @@ -0,0 +1,32 @@ +from odoo import api, fields, models + + +class StockPicking(models.Model): + _inherit = "stock.picking" + + @api.one + @api.depends("move_lines.date_expected") + # XXX: This is @api.one to preserve compatibility with upstream + # pylint: disable=api-one-deprecated + def _compute_scheduled_date(self): + scheduled_date = False + + if self.carrier_id.carrier_calendar_id: + if self.move_type == "direct": + scheduled_date = min( + self.move_lines.mapped("date_expected") or [fields.Datetime.now()] + ) + else: + scheduled_date = max( + self.move_lines.mapped("date_expected") or [fields.Datetime.now()] + ) + + scheduled_date = self.carrier_id.plan_days( + scheduled_date, safety_lead_days=0 + ) + + if scheduled_date: + self.scheduled_date = scheduled_date + return + + return super()._compute_scheduled_date() diff --git a/delivery_carrier_calendar/views/delivery_carrier.xml b/delivery_carrier_calendar/views/delivery_carrier.xml new file mode 100644 index 0000000..49df5c7 --- /dev/null +++ b/delivery_carrier_calendar/views/delivery_carrier.xml @@ -0,0 +1,14 @@ + + + view_delivery_carrier_form + delivery.carrier + 75 + + + + + + + + + diff --git a/setup/delivery_carrier_calendar/odoo/addons/delivery_carrier_calendar b/setup/delivery_carrier_calendar/odoo/addons/delivery_carrier_calendar new file mode 120000 index 0000000..15e0aef --- /dev/null +++ b/setup/delivery_carrier_calendar/odoo/addons/delivery_carrier_calendar @@ -0,0 +1 @@ +../../../../delivery_carrier_calendar \ No newline at end of file diff --git a/setup/delivery_carrier_calendar/setup.py b/setup/delivery_carrier_calendar/setup.py new file mode 100644 index 0000000..28c57bb --- /dev/null +++ b/setup/delivery_carrier_calendar/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) From 311df06dd300ec29459db7da06147f09db74c546 Mon Sep 17 00:00:00 2001 From: Ahmed Hagi Date: Thu, 5 Dec 2024 14:57:43 +0000 Subject: [PATCH 2/3] pre-commit --- delivery_carrier_calendar/__manifest__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/delivery_carrier_calendar/__manifest__.py b/delivery_carrier_calendar/__manifest__.py index fc5d9b0..b27add3 100644 --- a/delivery_carrier_calendar/__manifest__.py +++ b/delivery_carrier_calendar/__manifest__.py @@ -1,7 +1,7 @@ { "name": "delivery_carrier_calendar", "summary": "Delivery Carrier Calendar", - "author": "Glodo", + "author": "Glo Networks", "website": "https://github.com/GlodoUK/odoo-addons", "category": "Delivery", "version": "12.0.1.0.0", From fdd3000fd1ab40a0a7fc8bf3436d9bdc0580df82 Mon Sep 17 00:00:00 2001 From: Ahmed Hagi Date: Thu, 5 Dec 2024 15:04:34 +0000 Subject: [PATCH 3/3] missing new line --- delivery_carrier_calendar/models/delivery_carrier.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/delivery_carrier_calendar/models/delivery_carrier.py b/delivery_carrier_calendar/models/delivery_carrier.py index 9751682..1246c26 100644 --- a/delivery_carrier_calendar/models/delivery_carrier.py +++ b/delivery_carrier_calendar/models/delivery_carrier.py @@ -35,4 +35,4 @@ def plan_days( days + lead_days, day_dt, compute_leaves=compute_leaves, domain=domain ) - return day_dt + relativedelta(days=lead_days) \ No newline at end of file + return day_dt + relativedelta(days=lead_days)