From 53609cc20e5c1700d0a3e867cf490f3281021acf Mon Sep 17 00:00:00 2001 From: shridhar Date: Mon, 19 Aug 2024 12:26:00 +0530 Subject: [PATCH] feat: add multilingual templates support --- .../doctype/whatsapp_message/whatsapp_message.py | 6 +++--- .../doctype/whatsapp_templates/whatsapp_templates.json | 6 +++--- .../doctype/whatsapp_templates/whatsapp_templates.py | 2 -- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/frappe_whatsapp/frappe_whatsapp/doctype/whatsapp_message/whatsapp_message.py b/frappe_whatsapp/frappe_whatsapp/doctype/whatsapp_message/whatsapp_message.py index 1d71ef9..e7a6d38 100644 --- a/frappe_whatsapp/frappe_whatsapp/doctype/whatsapp_message/whatsapp_message.py +++ b/frappe_whatsapp/frappe_whatsapp/doctype/whatsapp_message/whatsapp_message.py @@ -89,10 +89,10 @@ def send_template(self): header_parameters = [] template_header_parameters = [] + ref_doc = frappe.get_doc(self.reference_doctype, self.reference_name) for field_name in field_names: - value = frappe.db.get_value( - self.reference_doctype, self.reference_name, field_name.strip() - ) + value = ref_doc.get_formatted(field_name.strip()) + header_parameters.append({"type": "text", "text": value}) template_header_parameters.append(value) diff --git a/frappe_whatsapp/frappe_whatsapp/doctype/whatsapp_templates/whatsapp_templates.json b/frappe_whatsapp/frappe_whatsapp/doctype/whatsapp_templates/whatsapp_templates.json index c43996f..71fdbfd 100644 --- a/frappe_whatsapp/frappe_whatsapp/doctype/whatsapp_templates/whatsapp_templates.json +++ b/frappe_whatsapp/frappe_whatsapp/doctype/whatsapp_templates/whatsapp_templates.json @@ -1,7 +1,7 @@ { "actions": [], "allow_rename": 1, - "autoname": "field:template_name", + "autoname": "format:{template_name}-{language_code}", "creation": "2022-10-28 13:39:09.887817", "doctype": "DocType", "editable_grid": 1, @@ -150,11 +150,11 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2024-08-19 12:00:25.447511", + "modified": "2024-08-19 12:22:17.367586", "modified_by": "Administrator", "module": "Frappe Whatsapp", "name": "WhatsApp Templates", - "naming_rule": "By fieldname", + "naming_rule": "Expression", "owner": "Administrator", "permissions": [ { diff --git a/frappe_whatsapp/frappe_whatsapp/doctype/whatsapp_templates/whatsapp_templates.py b/frappe_whatsapp/frappe_whatsapp/doctype/whatsapp_templates/whatsapp_templates.py index 94a0c64..b85437e 100644 --- a/frappe_whatsapp/frappe_whatsapp/doctype/whatsapp_templates/whatsapp_templates.py +++ b/frappe_whatsapp/frappe_whatsapp/doctype/whatsapp_templates/whatsapp_templates.py @@ -13,8 +13,6 @@ class WhatsAppTemplates(Document): """Create whatsapp template.""" - def autoname(self): - self.name = self.template_name.lower().replace(" ", "_") def validate(self): if not self.language_code or self.has_value_changed("language"):