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

GH164696 - Stock delivery v12 #44

Open
wants to merge 3 commits into
base: 12.0
Choose a base branch
from
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions delivery_carrier_calendar/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
delivery_carrier_calendar
-------------------------

Implement a resource calendar for delivery carrier indicating which days they
operate on.
1 change: 1 addition & 0 deletions delivery_carrier_calendar/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
14 changes: 14 additions & 0 deletions delivery_carrier_calendar/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "delivery_carrier_calendar",
"summary": "Delivery Carrier Calendar",
"author": "Glo Networks",
"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",
}
2 changes: 2 additions & 0 deletions delivery_carrier_calendar/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import delivery_carrier
from . import stock_picking
38 changes: 38 additions & 0 deletions delivery_carrier_calendar/models/delivery_carrier.py
Original file line number Diff line number Diff line change
@@ -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)
32 changes: 32 additions & 0 deletions delivery_carrier_calendar/models/stock_picking.py
Original file line number Diff line number Diff line change
@@ -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()
14 changes: 14 additions & 0 deletions delivery_carrier_calendar/views/delivery_carrier.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<odoo>
<record id="view_delivery_carrier_form" model="ir.ui.view">
<field name="name">view_delivery_carrier_form</field>
<field name="model">delivery.carrier</field>
<field name="priority">75</field>
<field name="inherit_id" ref="delivery.view_delivery_carrier_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='company_id']" position="after">
<field name="carrier_calendar_id" />
<field name="lead_time"/>
</xpath>
</field>
</record>
</odoo>
6 changes: 6 additions & 0 deletions setup/delivery_carrier_calendar/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,
)
Loading