From fe63028e5fcd2f040fa5a9bd28d243890403706b Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Thu, 26 Apr 2018 08:47:53 +0200 Subject: [PATCH] #15: Hide order id from users --- config/template_config.ini | 9 ++++++++- database.py | 29 ++++++++++++++++++++--------- strings.py | 20 ++++++++++++++++++-- 3 files changed, 46 insertions(+), 12 deletions(-) diff --git a/config/template_config.ini b/config/template_config.ini index cef2329..a6fd98d 100644 --- a/config/template_config.ini +++ b/config/template_config.ini @@ -1,9 +1,11 @@ # greed configuration file +# boolean parameters should be written in lowercase + # Config file parameters [Config] ; Config file version. DO NOT EDIT THIS! -version = 11 +version = 12 ; Set this to no when you are done editing the file is_template = yes @@ -49,6 +51,11 @@ email_required = yes # Require the phone number of the user phone_required = yes +# Bot appearance settings +[Appearance] +# Show the full order info to the customers +full_order_info = no + # Exception reporting settings [Error Reporting] # Optional sentry token: get the token at https://sentry.io/ diff --git a/database.py b/database.py index 2f79305..34bec3f 100644 --- a/database.py +++ b/database.py @@ -239,25 +239,36 @@ class Order(TableDeclarativeBase): def __repr__(self): return f"" - def get_text(self, session): + def get_text(self, session, user=False): joined_self = session.query(Order).filter_by(order_id=self.order_id).join(Transaction).one() items = "" for item in self.items: items += str(item) + "\n" if self.delivery_date is not None: status_emoji = strings.emoji_completed + status_text = strings.text_completed elif self.refund_date is not None: status_emoji = strings.emoji_refunded + status_text = strings.text_refunded else: status_emoji = strings.emoji_not_processed - return status_emoji + " " + \ - strings.order_number.format(id=self.order_id) + "\n" + \ - strings.order_format_string.format(user=self.user.mention(), - date=self.creation_date.isoformat(), - items=items, - notes=self.notes if self.notes is not None else "", - value=str(utils.Price(-joined_self.transaction.value))) + \ - (strings.refund_reason.format(reason=self.refund_reason) if self.refund_date is not None else "") + status_text = strings.text_not_processed + if user and configloader.config["Appearance"]["full_order_info"] == "yes": + return strings.user_order_format_string.format(status_emoji=status_emoji, + status_text=status_text, + items=items, + notes=self.notes, + value=str(utils.Price(-joined_self.transaction.value))) + \ + (strings.refund_reason.format(reason=self.refund_reason) if self.refund_date is not None else "") + else: + return status_emoji + " " + \ + strings.order_number.format(id=self.order_id) + "\n" + \ + strings.order_format_string.format(user=self.user.mention(), + date=self.creation_date.isoformat(), + items=items, + notes=self.notes if self.notes is not None else "", + value=str(utils.Price(-joined_self.transaction.value))) + \ + (strings.refund_reason.format(reason=self.refund_reason) if self.refund_date is not None else "") class OrderItem(TableDeclarativeBase): diff --git a/strings.py b/strings.py index 1a0b1f8..027272b 100644 --- a/strings.py +++ b/strings.py @@ -21,9 +21,9 @@ product_format_string = "{name}\n" \ "{cart}" # Order number, displayed in the order info -order_number = "Ordine #{id}" +order_number = "Ordine #{id}" -# Order info displayed string +# Order info string, shown to the admins order_format_string = "di {user}\n" \ "Creato {date}\n" \ "\n" \ @@ -32,6 +32,13 @@ order_format_string = "di {user}\n" \ "\n" \ "Note del cliente: {notes}" +# Order info string, shown to the user +user_order_format_string = "{status_emoji} Ordine {status_text}\n" \ + "{items}\n" \ + "TOTALE: {value}\n" \ + "\n" \ + "Note: {notes}" + # Transaction page is loading loading_transactions = "Caricamento delle transazioni in corso...\n" \ "Attendi qualche secondo, per piacere." @@ -203,6 +210,15 @@ emoji_completed = "✅" # Emoji: refunded order emoji_refunded = "✴️" +# Text: unprocessed order +text_not_processed = "in sospeso" + +# Text: completed order +text_completed = "completato" + +# Text: refunded order +text_refunded = "rimborsato" + # Add product: name? ask_product_name = "Come si deve chiamare il prodotto?"