From 4bcd1866fd3fc8d5deb866dcc8cba572b624cf5f Mon Sep 17 00:00:00 2001 From: Corentin Forler Date: Wed, 13 Nov 2024 17:23:58 +0100 Subject: [PATCH 1/4] feat(booking): Accept date and datetime in API --- .../doctype/item_booking/item_booking.py | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/erpnext/venue/doctype/item_booking/item_booking.py b/erpnext/venue/doctype/item_booking/item_booking.py index 1c73db2072..596fc281c8 100644 --- a/erpnext/venue/doctype/item_booking/item_booking.py +++ b/erpnext/venue/doctype/item_booking/item_booking.py @@ -786,6 +786,21 @@ def get_availabilities( ).get_available_slots() +def _parse_date_or_datetime(s: str): + from frappe.utils.data import convert_utc_to_system_timezone + + if isinstance(s, str): + if s.endswith("Z"): + d = get_datetime(s.rstrip("Z")) + d = convert_utc_to_system_timezone(d) + return d.replace(tzinfo=None) + + if len(s) <= 10: + return datetime.datetime.strptime(s, "%Y-%m-%d") + + return get_datetime(s) + + class ItemBookingAvailabilities: def __init__( self, @@ -802,16 +817,8 @@ class ItemBookingAvailabilities: self.start = start self.end = end self.limit = int(limit) - self.init = ( - datetime.datetime.strptime(self.start, "%Y-%m-%d") - if isinstance(self.start, str) - else get_datetime(self.start) - ) - self.finish = ( - datetime.datetime.strptime(self.end, "%Y-%m-%d") - if isinstance(self.end, str) - else get_datetime(self.end) - ) + self.init = _parse_date_or_datetime(self.start) + self.finish = _parse_date_or_datetime(self.end) self.user = user or frappe.session.user if user == "*" and not frappe.has_permission("Item Booking", "read"): -- GitLab From 6de73b602df2066eb71958c3f9588298afa01b9b Mon Sep 17 00:00:00 2001 From: Corentin Forler Date: Tue, 26 Nov 2024 18:37:39 +0100 Subject: [PATCH 2/4] chore(booking): Generate type annotations --- .../booking_credit_type.json | 17 +++++++++++++-- .../booking_credit_type.py | 21 +++++++++++++++++++ .../booking_credit_type_conversions.json | 4 ++-- .../booking_credit_type_conversions.py | 16 ++++++++++++++ 4 files changed, 54 insertions(+), 4 deletions(-) diff --git a/erpnext/venue/doctype/booking_credit_type/booking_credit_type.json b/erpnext/venue/doctype/booking_credit_type/booking_credit_type.json index 3e49be9448..1be16c4d0d 100644 --- a/erpnext/venue/doctype/booking_credit_type/booking_credit_type.json +++ b/erpnext/venue/doctype/booking_credit_type/booking_credit_type.json @@ -105,7 +105,7 @@ "link_fieldname": "booking_credit_type" } ], - "modified": "2023-03-20 14:55:21.418044", + "modified": "2024-11-26 16:39:32.210780", "modified_by": "Administrator", "module": "Venue", "name": "Booking Credit Type", @@ -124,9 +124,22 @@ "select": 1, "share": 1, "write": 1 + }, + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "Venue Manager", + "select": 1, + "share": 1, + "write": 1 } ], "sort_field": "modified", "sort_order": "DESC", "states": [] -} \ No newline at end of file +} diff --git a/erpnext/venue/doctype/booking_credit_type/booking_credit_type.py b/erpnext/venue/doctype/booking_credit_type/booking_credit_type.py index 65ad370660..a423ee3ee3 100644 --- a/erpnext/venue/doctype/booking_credit_type/booking_credit_type.py +++ b/erpnext/venue/doctype/booking_credit_type/booking_credit_type.py @@ -5,6 +5,27 @@ from frappe.model.document import Document class BookingCreditType(Document): + # begin: auto-generated types + # This code is auto-generated. Do not modify anything in this block. + + from typing import TYPE_CHECKING + + if TYPE_CHECKING: + from frappe.types import DF + + from erpnext.venue.doctype.booking_credit_type_conversions.booking_credit_type_conversions import ( + BookingCreditTypeConversions, + ) + + conversion_table: DF.Table[BookingCreditTypeConversions] + credits: DF.Int + disabled: DF.Check + item: DF.Link + label: DF.Data + uom: DF.Link + validity: DF.Duration | None + # end: auto-generated types + def validate(self): self.validate_conversions() diff --git a/erpnext/venue/doctype/booking_credit_type_conversions/booking_credit_type_conversions.json b/erpnext/venue/doctype/booking_credit_type_conversions/booking_credit_type_conversions.json index 75ed1d322b..c6a8bd3c5d 100644 --- a/erpnext/venue/doctype/booking_credit_type_conversions/booking_credit_type_conversions.json +++ b/erpnext/venue/doctype/booking_credit_type_conversions/booking_credit_type_conversions.json @@ -40,7 +40,7 @@ "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2023-03-20 16:28:44.165045", + "modified": "2024-11-26 16:38:52.196041", "modified_by": "Administrator", "module": "Venue", "name": "Booking Credit Type Conversions", @@ -49,4 +49,4 @@ "sort_field": "modified", "sort_order": "DESC", "states": [] -} \ No newline at end of file +} diff --git a/erpnext/venue/doctype/booking_credit_type_conversions/booking_credit_type_conversions.py b/erpnext/venue/doctype/booking_credit_type_conversions/booking_credit_type_conversions.py index 151e1c776c..71cc503047 100644 --- a/erpnext/venue/doctype/booking_credit_type_conversions/booking_credit_type_conversions.py +++ b/erpnext/venue/doctype/booking_credit_type_conversions/booking_credit_type_conversions.py @@ -5,4 +5,20 @@ import frappe from frappe.model.document import Document class BookingCreditTypeConversions(Document): + # begin: auto-generated types + # This code is auto-generated. Do not modify anything in this block. + + from typing import TYPE_CHECKING + + if TYPE_CHECKING: + from frappe.types import DF + + credits: DF.Int + item: DF.Link + parent: DF.Data + parentfield: DF.Data + parenttype: DF.Data + uom: DF.Link + # end: auto-generated types + pass -- GitLab From f381092c76c484fc7732a7fabd6ccdd2700b3d22 Mon Sep 17 00:00:00 2001 From: Corentin Forler Date: Mon, 6 Jan 2025 14:57:17 +0100 Subject: [PATCH 3/4] chore: Typo traduction --- erpnext/locale/fr.po | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/locale/fr.po b/erpnext/locale/fr.po index c17c0ffb23..1960f34de4 100644 --- a/erpnext/locale/fr.po +++ b/erpnext/locale/fr.po @@ -57483,7 +57483,7 @@ msgstr "Cette commande contient des articles récurrents et est liée à l'abonn #: selling/doctype/sales_order/sales_order.js:599 msgid "This order contains some recurring items.
A subscription will be automatically generated on submission if a recurring period is set." -msgstr "Cette commande contient des articles récurrents.
Un abonnement sera automatiquement généré à la validation si une période de récurrence est définie." +msgstr "Cette commande contient des articles récurrents.
Un abonnement ne sera automatiquement généré à la validation que si une période de récurrence est définie." #: accounts/report/bank_transaction_categories/bank_transaction_categories.js:22 msgid "This quarter" -- GitLab From 47fa75818aee0bcc0fdf7c5c4cc1d1008d7a8f4d Mon Sep 17 00:00:00 2001 From: Corentin Forler Date: Fri, 17 Jan 2025 18:08:02 +0100 Subject: [PATCH 4/4] fix: Add remaining seats for each available slot --- erpnext/venue/doctype/item_booking/item_booking.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/erpnext/venue/doctype/item_booking/item_booking.py b/erpnext/venue/doctype/item_booking/item_booking.py index 596fc281c8..d999f4502c 100644 --- a/erpnext/venue/doctype/item_booking/item_booking.py +++ b/erpnext/venue/doctype/item_booking/item_booking.py @@ -1028,7 +1028,13 @@ class ItemBookingAvailabilities: slots.extend(self._get_all_slots(line, simultaneous_booking_allowed)) for slot in slots: - output.append(self.get_available_dict(slot)) + out = self.get_available_dict(slot) + try: + count = get_booking_count(self.item, out.get("start"), out.get("end")) + out.remaining = count.get("remaining") + except Exception: + pass + output.append(out) for scheduled_item in user_scheduled_items: added = False -- GitLab