commit
f459770466
|
|
@ -32,6 +32,11 @@ msgstr " تسجيل الدخول"
|
|||
msgid " Sign-out"
|
||||
msgstr " تسجيل الخروج"
|
||||
|
||||
#. module: odex_mobile
|
||||
#: model_terms:ir.ui.view,arch_db:odex_mobile.res_config_settings_view_form
|
||||
msgid "Odex SS App"
|
||||
msgstr "تطبيق أودكس SS"
|
||||
|
||||
#. module: odex_mobile
|
||||
#: model_terms:ir.ui.view,arch_db:odex_mobile.privacy_policy
|
||||
msgid "<strong>Changes to This Privacy Policy</strong>"
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@ class ResConfigSettings(models.TransientModel):
|
|||
|
||||
auto_checkout = fields.Integer(related="company_id.auto_checkout" ,string="Auto Checkout After",readonly=False)
|
||||
fcm_server_key = fields.Char(string='Server Key:', related="company_id.fcm_server_key", readonly=False)
|
||||
service_account = fields.Binary(string='Service Account:', related="company_id.service_account", readonly=False)
|
||||
sender_id = fields.Char(string='Sender ID:', related="company_id.sender_id", readonly=False)
|
||||
|
||||
class ResCompany(models.Model):
|
||||
|
|
@ -69,5 +70,6 @@ class ResCompany(models.Model):
|
|||
|
||||
auto_checkout = fields.Integer(string="Auto Checkout After")
|
||||
fcm_server_key = fields.Char(string='Server Key')
|
||||
service_account = fields.Binary(string='Service Account', attachment=True)
|
||||
sender_id = fields.Char(string='Sender ID')
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,14 @@ from odoo.exceptions import ValidationError
|
|||
import random
|
||||
import json
|
||||
import json, requests
|
||||
import json, requests, base64
|
||||
import google.auth.transport.requests
|
||||
from google.oauth2 import service_account
|
||||
|
||||
BASE_URL = 'https://fcm.googleapis.com'
|
||||
SCOPES = ['https://www.googleapis.com/auth/firebase.messaging']
|
||||
import tempfile
|
||||
import os
|
||||
|
||||
|
||||
class HrEmployee(models.Model):
|
||||
|
|
@ -15,18 +23,50 @@ class HrEmployee(models.Model):
|
|||
attendance_log_ids = fields.One2many('attendance.log','employee_id',string="Attendance Log")
|
||||
message_sent = fields.Boolean(string="Message Sent", default=False)
|
||||
def user_push_notification(self, notification):
|
||||
url = "https://fcm.googleapis.com/fcm/send"
|
||||
header = {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'key=%s' % (self.env.user.company_id.fcm_server_key)
|
||||
}
|
||||
body = json.dumps({
|
||||
"to": self.fcm_token,
|
||||
"direct_boot_ok": True,
|
||||
"notification": notification
|
||||
})
|
||||
def _get_access_token(json_file):
|
||||
"""Retrieve a valid access token that can be used to authorize requests.
|
||||
|
||||
:return: Access token.
|
||||
"""
|
||||
credentials = service_account.Credentials.from_service_account_file(
|
||||
json_file, scopes=SCOPES)
|
||||
request = google.auth.transport.requests.Request()
|
||||
credentials.refresh(request)
|
||||
return credentials.token
|
||||
|
||||
try:
|
||||
respons = requests.post(url=url, data=body, headers=header)
|
||||
json_file_name = 'service-account'
|
||||
base64_service_account = base64.decodebytes(self.env.user.company_id.service_account)
|
||||
service_account_json = json.loads(base64_service_account)
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
temp_file_path = os.path.join(temp_dir, json_file_name)
|
||||
with open(temp_file_path, 'w') as temp_file:
|
||||
temp_file.write(base64_service_account.decode('UTF-8'))
|
||||
header = {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer %s' % (_get_access_token(temp_file_path))
|
||||
}
|
||||
body = json.dumps({
|
||||
"message": {
|
||||
"token": self.fcm_token_web,
|
||||
"notification": notification,
|
||||
"android": {
|
||||
"notification": {
|
||||
"sound": "default"
|
||||
}
|
||||
},
|
||||
"apns": {
|
||||
"payload": {
|
||||
"aps": {
|
||||
"sound": "default"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
FCM_ENDPOINT = 'v1/projects/' + service_account_json['project_id'] + '/messages:send'
|
||||
FCM_URL = BASE_URL + '/' + FCM_ENDPOINT
|
||||
respons = requests.post(url=FCM_URL, data=body, headers=header)
|
||||
return True
|
||||
except Exception as e:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -81,10 +81,17 @@
|
|||
<field name="inherit_id" ref="base.res_config_settings_view_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//div[hasclass('settings')]" position="inside">
|
||||
<div class="app_settings_block" data-string="MobileAttendance" string="Mobile Attendance" data-key="spl">
|
||||
<h2>Mobile Attendance</h2>
|
||||
<div class="app_settings_block" data-string="MobileAttendance" string="Odex SS App" data-key="spl-mobile">
|
||||
<h2>Odex SS App</h2>
|
||||
<div class="row mt16 o_settings_container">
|
||||
|
||||
<div class="col-xs-12 col-md-6 o_setting_box">
|
||||
<div class="o_setting_right_pane">
|
||||
<label for="service_account"/>
|
||||
<field name="service_account"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-xs-12 col-md-6 o_setting_box">
|
||||
<div class="o_setting_right_pane">
|
||||
<label for="auto_checkout"/>
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
<field name="inherit_id" ref="base.res_config_settings_view_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//div[hasclass('settings')]" position="inside">
|
||||
<div class="app_settings_block" data-string="Web App Configuration" string="Web App" data-key="spl">
|
||||
<div class="app_settings_block" data-string="Web App Configuration" string="Web App" data-key="spl-web">
|
||||
<h2>WebMobile Configuration</h2>
|
||||
<div id="web_fcm_settings">
|
||||
<div class="row mt16 o_settings_container">
|
||||
|
|
|
|||
Loading…
Reference in New Issue