Add option skip send whatsapp template to meta

This commit is contained in:
younes 2025-07-20 11:10:25 +01:00
parent 7f65f42189
commit 93b28e19d8
3 changed files with 31 additions and 14 deletions

View File

@ -2505,3 +2505,8 @@ msgstr "placeholder=\"e.g. https://www.example.com\"/>"
#: model_terms:ir.ui.view,arch_db:whatsapp.whatsapp_composer_view_form #: model_terms:ir.ui.view,arch_db:whatsapp.whatsapp_composer_view_form
msgid "recipients have an invalid phone number and will be skipped." msgid "recipients have an invalid phone number and will be skipped."
msgstr "لدى المستلمين أرقام هواتف غير صحيحة وسيتم تخطيهم. " msgstr "لدى المستلمين أرقام هواتف غير صحيحة وسيتم تخطيهم. "
#. module: whatsapp
#: model:ir.model.fields,field_description:whatsapp.field_whatsapp_template__is_test
msgid "Test Mode"
msgstr "وضع الاختبار"

View File

@ -121,6 +121,7 @@ class WhatsAppTemplate(models.Model):
messages_count = fields.Integer(string="Messages Count", compute='_compute_messages_count') messages_count = fields.Integer(string="Messages Count", compute='_compute_messages_count')
has_action = fields.Boolean(string="Has Action", compute='_compute_has_action') has_action = fields.Boolean(string="Has Action", compute='_compute_has_action')
is_test = fields.Boolean(string='Test Mode')
_sql_constraints = [ _sql_constraints = [
('unique_name_account_template', 'unique(template_name, lang_code, wa_account_id)', "Duplicate template is not allowed for one Meta account.") ('unique_name_account_template', 'unique(template_name, lang_code, wa_account_id)', "Duplicate template is not allowed for one Meta account.")
@ -463,15 +464,18 @@ class WhatsAppTemplate(models.Model):
'components': components, 'components': components,
}) })
try: try:
if self.wa_template_uid: if self.is_test:
wa_api._submit_template_update(json_data, self.wa_template_uid)
self.status = 'pending' self.status = 'pending'
else: else:
response = wa_api._submit_template_new(json_data) if self.wa_template_uid:
self.write({ wa_api._submit_template_update(json_data, self.wa_template_uid)
'wa_template_uid': response['id'], self.status = 'pending'
'status': response['status'].lower() else:
}) response = wa_api._submit_template_new(json_data)
self.write({
'wa_template_uid': response['id'],
'status': response['status'].lower()
})
except WhatsAppError as we: except WhatsAppError as we:
raise UserError(str(we)) raise UserError(str(we))
@ -482,13 +486,16 @@ class WhatsAppTemplate(models.Model):
def button_sync_template(self): def button_sync_template(self):
"""Sync template from WhatsApp Business Account """ """Sync template from WhatsApp Business Account """
self.ensure_one() self.ensure_one()
wa_api = WhatsAppApi(self.wa_account_id) if self.is_test:
try: self.status = 'approved'
response = wa_api._get_template_data(wa_template_uid=self.wa_template_uid) else:
except WhatsAppError as e: wa_api = WhatsAppApi(self.wa_account_id)
raise ValidationError(str(e)) try:
if response.get('id'): response = wa_api._get_template_data(wa_template_uid=self.wa_template_uid)
self._update_template_from_response(response) except WhatsAppError as e:
raise ValidationError(str(e))
if response.get('id'):
self._update_template_from_response(response)
return { return {
'type': 'ir.actions.client', 'type': 'ir.actions.client',
'tag': 'reload', 'tag': 'reload',

View File

@ -28,6 +28,10 @@
type="object" type="object"
attrs="{'invisible': [('wa_template_uid', '=', False)]}" attrs="{'invisible': [('wa_template_uid', '=', False)]}"
groups="whatsapp.group_whatsapp_admin"/> groups="whatsapp.group_whatsapp_admin"/>
<button name="button_sync_template" string="Sync Template"
type="object" class="btn btn-primary"
attrs="{'invisible': ['|','|',('is_test', '=', False),('status','!=','pending'),('wa_template_uid', '=', True)]}"
groups="whatsapp.group_whatsapp_admin"/>
<button name="%(whatsapp_preview_action_from_template)d" string="Preview" <button name="%(whatsapp_preview_action_from_template)d" string="Preview"
type="action" target="new" type="action" target="new"
context="{'active_id': id, 'dialog_size': 'medium'}"/> context="{'active_id': id, 'dialog_size': 'medium'}"/>
@ -61,6 +65,7 @@
<field name="allowed_user_ids" <field name="allowed_user_ids"
widget="many2many_tags_avatar" widget="many2many_tags_avatar"
placeholder="Users who can use this template.If empty then public."/> placeholder="Users who can use this template.If empty then public."/>
<field name="is_test"/>
</group> </group>
<group> <group>
<field name="template_name" <field name="template_name"