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] website_sale_commitment_date #1004

Open
wants to merge 1 commit into
base: 16.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
6 changes: 6 additions & 0 deletions setup/website_sale_commitment_date/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,
)
92 changes: 92 additions & 0 deletions website_sale_commitment_date/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
============================
Website Sale Commitment Date
============================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:70c786255989ea550c4a2717056ac5be90a46d847d4d13bab338daefb3f41453
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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%2Fe--commerce-lightgray.png?logo=github
:target: https://github.com/OCA/e-commerce/tree/16.0/website_sale_commitment_date
:alt: OCA/e-commerce
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/e-commerce-16-0/e-commerce-16-0-website_sale_commitment_date
: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/e-commerce&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This addon allows selecting the delivery date when purchasing from the e-commerce platform,
configuring excluded days of the week, minimum or maximum days to limit the selection
from the current date. All of this is configurable from the shipping method.

**Table of contents**

.. contents::
:local:

Usage
=====


To use this addon, you need to go to the shipping method and activate the "allow commitment date" option.
Then, you can configure various settings right there. Afterward,
go to the cart in the e-commerce platform, and you will see that if you select that shipping method,
the option to choose the delivery day will appear.
When using a shipping method that requires specifying the delivery date,
the button will not appear until a date is selected.


Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/e-commerce/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/e-commerce/issues/new?body=module:%20website_sale_commitment_date%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
~~~~~~~

* Binhex

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

* `Binhex <https://www.binhex.cloud/>`_:

* Adasat Torres de León <a.torres@binhex.cloud>

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.

This module is part of the `OCA/e-commerce <https://github.com/OCA/e-commerce/tree/16.0/website_sale_commitment_date>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
4 changes: 4 additions & 0 deletions website_sale_commitment_date/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2025 Binhex - Adasat Torres de León
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import models
from . import controllers
23 changes: 23 additions & 0 deletions website_sale_commitment_date/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2025 Binhex - Adasat Torres de León
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Website Sale Commitment Date",
"version": "16.0.1.0.0",
"category": "Website",
"author": "Binhex, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/e-commerce",
"license": "AGPL-3",
"summary": "Allow to set a commitment date on the sale order from to the e-commerce",
"depends": ["website_sale_delivery"],
"data": [
"security/ir.model.access.csv",
"views/delivery_carrier_views.xml",
"views/delivery_carrier_templates.xml",
"data/delivery_carrier_weekday_data.xml",
],
"assets": {
"web.assets_frontend": [
"website_sale_commitment_date/static/src/**/*",
],
},
}
1 change: 1 addition & 0 deletions website_sale_commitment_date/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import main
88 changes: 88 additions & 0 deletions website_sale_commitment_date/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Copyright 2025 Binhex - Adasat Torres de León
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import logging
from datetime import datetime

from dateutil.relativedelta import relativedelta

from odoo import http
from odoo.http import request
from odoo.tools import DEFAULT_SERVER_DATE_FORMAT, format_date

from odoo.addons.website_sale_delivery.controllers.main import WebsiteSaleDelivery

_logger = logging.getLogger(__name__)


class WebsiteSaleCommitmentDate(WebsiteSaleDelivery):
@http.route()
def payment(self, **post):
res = super().payment(**post)
order = request.website.sale_get_order()

Check warning on line 21 in website_sale_commitment_date/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

website_sale_commitment_date/controllers/main.py#L20-L21

Added lines #L20 - L21 were not covered by tests
if order and order.carrier_id:
res.qcontext.update(

Check warning on line 23 in website_sale_commitment_date/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

website_sale_commitment_date/controllers/main.py#L23

Added line #L23 was not covered by tests
"allow_commitment_date", order.carrier_id.allow_commitment_date
)
return res

Check warning on line 26 in website_sale_commitment_date/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

website_sale_commitment_date/controllers/main.py#L26

Added line #L26 was not covered by tests

@http.route(
"/shop/update_commitment_date", type="json", auth="public", website=True
)
def update_commitment_date(self, **post):
order = request.website.sale_get_order()
string_date = post.get("date")
lang = request.env["res.lang"]._lang_get(
request.env.context.get("lang", False) or request.env.user.lang
)
if order:
date_obj = datetime.strptime(
string_date,
lang.date_format if lang else DEFAULT_SERVER_DATE_FORMAT,
)
order.commitment_date = date_obj
return {
"success": order.commitment_date.date() == date_obj.date(),
"date": format_date(request.env, date_obj.date()),
}

@http.route()
def update_eshop_carrier(self, **post):
res = super().update_eshop_carrier(**post)
order = request.website.sale_get_order()
if order.carrier_id and not order.carrier_id.allow_commitment_date:
order.commitment_date = False
return res

def _update_website_sale_delivery_return(self, order, **post):
res = super()._update_website_sale_delivery_return(order, **post)
if order and order.carrier_id:
res["allow_commitment_date"] = order.carrier_id.allow_commitment_date
return res

@http.route("/calendar/commitment_date", type="json", auth="public", website=True)
def commitment_date(self, **post):
order = request.website.sale_get_order()
carrier = order.carrier_id
value = {}
lang = request.env["res.lang"]._lang_get(
request.env.context.get("lang", False) or request.env.user.lang
)
action = post.get("action", False)
start = post.get("start", False)
if start:
start = datetime.strptime(
start, lang.date_format if lang else DEFAULT_SERVER_DATE_FORMAT
).date()

if carrier:
if action == "prev":
value = carrier._get_calendar_context(
start=start - relativedelta(months=1)
)
elif action == "next":
value = carrier._get_calendar_context(
start=start + relativedelta(months=1)
)
else:
value = carrier._get_calendar_context()
return value
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo noupdate="1">
<record id="monday_weekday" model="delivery.carrier.weekday">
<field name="name">Monday</field>
<field name="value">0</field>
</record>
<record id="tuesday_weekday" model="delivery.carrier.weekday">
<field name="name">Tuesday</field>
<field name="value">1</field>
</record>
<record id="wednesday_weekday" model="delivery.carrier.weekday">
<field name="name">Wednesday</field>
<field name="value">2</field>
</record>
<record id="thursday_weekday" model="delivery.carrier.weekday">
<field name="name">Thursday</field>
<field name="value">3</field>
</record>
<record id="friday_weekday" model="delivery.carrier.weekday">
<field name="name">Friday</field>
<field name="value">4</field>
</record>
<record id="saturday_weekday" model="delivery.carrier.weekday">
<field name="name">Saturday</field>
<field name="value">5</field>
</record>
<record id="sunday_weekday" model="delivery.carrier.weekday">
<field name="name">Sunday</field>
<field name="value">6</field>
</record>
</odoo>
Loading
Loading