diff --git a/odex25_mobile/odex_mobile/controllers/firebase_notifications.py b/odex25_mobile/odex_mobile/controllers/firebase_notifications.py index c704de35c..1b7ab7bd7 100644 --- a/odex25_mobile/odex_mobile/controllers/firebase_notifications.py +++ b/odex25_mobile/odex_mobile/controllers/firebase_notifications.py @@ -17,7 +17,7 @@ _logger = logging.getLogger(__name__) class NotificationController(http.Controller): - @http.route(['/rest_api/v1/notifications/','/rest_api/v1/notifications/page/'], type='http', auth='none', csrf=False, methods=['GET'], website=True) + @http.route(['/rest_api/v1/notifications/', '/rest_api/v1/notifications/page/'], type='http', auth='none', csrf=False, methods=['GET'], website=True) def index(self, page=1, **kw): """ fetch notifications @@ -40,7 +40,7 @@ class NotificationController(http.Controller): # partner_ids # search([('partner_ids','in',user.partner_id.id)]) # - domain = [("sent", "=", True),'&',("is_system", "=", True),('partner_ids','in',user.partner_id.id)] + domain = [("sent", "=", True), '&', ("is_system", "=", True), ('partner_ids', 'in', user.partner_id.id)] ids = user.env['firebase.notification'].search(domain, order="create_date desc") notifications = [] pager = request.website.pager( @@ -53,11 +53,10 @@ class NotificationController(http.Controller): records = user.env['firebase.notification'].search(domain).search( domain, limit=20, offset=pager['offset']) - for res in records: notifications.append({ 'notification':{"title":res.title, - "body": res.body,}, + "body": res.body, }, "id":res.id, "title":res.title, "body": res.body, @@ -86,7 +85,6 @@ class NotificationController(http.Controller): } return http_helper.response(message="Notifications found", data=values) - @http.route(['/rest_api/v1/notifications/'], type='http', auth='none', csrf=False, methods=['PATCH'], website=True) def open_view(self, notif=None, **kw): """ @@ -129,7 +127,6 @@ class NotificationController(http.Controller): "data": str(res.create_date), "uuid": res.uid, }) - values = { 'links': None, @@ -140,7 +137,6 @@ class NotificationController(http.Controller): } return http_helper.response(message="Notification found", data=values) - @http.route(['/rest_api/v1/notifications/'], type='http', auth='none', csrf=False, methods=['DELETE'], website=True) def delete_notification(self, notif=None, **kw): """ @@ -203,7 +199,7 @@ class NotificationController(http.Controller): # security check done successfully # - domain = [("sent", "=", True),'&',("is_system", "=", True),('partner_ids','in',user.partner_id.id)] + domain = [("sent", "=", True), '&', ("is_system", "=", True), ('partner_ids', 'in', user.partner_id.id)] ids = user.env['firebase.notification'].search(domain).unlink() values = { @@ -213,4 +209,4 @@ class NotificationController(http.Controller): }, "count": None, } - return http_helper.response(message="Delete successfully", data=values) \ No newline at end of file + return http_helper.response(message="Delete successfully", data=values) diff --git a/odex25_mobile/odex_mobile/controllers/leave.py b/odex25_mobile/odex_mobile/controllers/leave.py index d7831ba70..697cf677b 100644 --- a/odex25_mobile/odex_mobile/controllers/leave.py +++ b/odex25_mobile/odex_mobile/controllers/leave.py @@ -21,7 +21,7 @@ class LeaveController(http.Controller): def get_return_data(self,hol,approvel=None): value = {'id': hol.id, 'type': hol.holiday_status_id.name, 'type_value': hol.holiday_status_id.id, - 'reason_msg': hol.reject_reason or "", + 'reason_msg': hol.reason or "", 'alternative_chick': hol.holiday_status_id.alternative_chick, 'replacement_id': hol.replace_by.id if hol.replace_by else False, 'replacement_name': hol.replace_by.name if hol.replace_by else False, diff --git a/odex25_mobile/odex_mobile/controllers/rest_api_v2/leave.py b/odex25_mobile/odex_mobile/controllers/rest_api_v2/leave.py index 0a230bf60..a8ded7c56 100644 --- a/odex25_mobile/odex_mobile/controllers/rest_api_v2/leave.py +++ b/odex25_mobile/odex_mobile/controllers/rest_api_v2/leave.py @@ -38,7 +38,7 @@ class LeaveController(http.Controller): value = {'id': hol.id, 'type': hol.holiday_status_id.name, 'type_value': hol.holiday_status_id.id, - 'reason_msg': hol.reject_reason or "", + 'reason_msg': hol.reason or "", 'alternative_chick': hol.holiday_status_id.alternative_chick, 'replacement_id': hol.replace_by.id if hol.replace_by else False, 'replacement_name': hol.replace_by.name if hol.replace_by else False, @@ -59,7 +59,7 @@ class LeaveController(http.Controller): return value @http.route(['/rest_api/v2/leaves'], type='http', auth='none', csrf=False, methods=['GET']) - def get_leaves(self, approvel=None, page=None, **kw): + def get_leaves(self, approvel=None, done=None, page=None, **kw): http_method, body, headers, token = http_helper.parse_request() result = validator.verify_token(token) if not result['status']: @@ -89,10 +89,16 @@ class LeaveController(http.Controller): [('state', '=', 'open'), ('id', '!=', employee.id)], ['name']) if approvel: holidays = http.request.env['hr.holidays'].search( - [('state', '!=', 'draft'), ('employee_id', '!=', employee.id), ('type', '=', 'remove')], + [('state', 'in', ['confirm','validate','approved']), ('employee_id', '!=', employee.id), ('type', '=', 'remove')], offset=offset, limit=limit) count = http.request.env['hr.holidays'].search_count( - [('state', '!=', 'draft'), ('employee_id', '!=', employee.id), ('type', '=', 'remove')],) + [('state', 'not in', ['confirm','validate','approved']), ('employee_id', '!=', employee.id), ('type', '=', 'remove')],) + if done: + holidays = http.request.env['hr.holidays'].search( + [('state', 'not in', ['validate1','refuse','cancel']), ('employee_id', '!=', employee.id), ('type', '=', 'remove')], + offset=offset, limit=limit) + count = http.request.env['hr.holidays'].search_count( + [('state', 'not in', ['validate1','refuse','cancel']), ('employee_id', '!=', employee.id), ('type', '=', 'remove')],) else: holidays = http.request.env['hr.holidays'].search( [('employee_id', '=', employee.id), ('type', '=', 'remove')], offset=offset, limit=limit) diff --git a/odex25_mobile/odex_mobile/models/firebase_notification.py b/odex25_mobile/odex_mobile/models/firebase_notification.py index 271a0ed90..0bcebe393 100644 --- a/odex25_mobile/odex_mobile/models/firebase_notification.py +++ b/odex25_mobile/odex_mobile/models/firebase_notification.py @@ -56,6 +56,7 @@ class FirebaseNotification(models.Model): #@api.multi def send(self, **kwargs): + print("**********************************************") if kwargs is None: kwargs = {} for notif in self: diff --git a/odex25_mobile/odex_mobile/models/hr_firebase_notification.py b/odex25_mobile/odex_mobile/models/hr_firebase_notification.py index 9ef17310a..a6d8bb01d 100644 --- a/odex25_mobile/odex_mobile/models/hr_firebase_notification.py +++ b/odex25_mobile/odex_mobile/models/hr_firebase_notification.py @@ -95,6 +95,7 @@ class HrHolidays(models.Model): }) } _logger.warning(type(data)) + _logger.warning(data) if users: partner = users.mapped('partner_id') for part in partner: diff --git a/odex25_mobile/odex_mobile/models/res_partner.py b/odex25_mobile/odex_mobile/models/res_partner.py index 5ceca453c..edd28b51e 100644 --- a/odex25_mobile/odex_mobile/models/res_partner.py +++ b/odex25_mobile/odex_mobile/models/res_partner.py @@ -1,45 +1,58 @@ +import json +import requests +import logging + from odoo import models, fields, api -import json, requests +_logger = logging.getLogger(__name__) class Partner(models.Model): - _inherit = 'res.partner' firebase_registration_ids = fields.One2many( "firebase.registration", "partner_id", readonly=True ) - def send_notification(self, message_title, message_body,data=None, all_device=True): + def send_notification(self, message_title, message_body, data=None, all_device=True): + notification_data = { + "title": str(message_title), + "body": str(message_body), + "meta": json.dumps(data) if data else None, + "partner_ids": [(4, self.id)], + "is_system": True, + "sent": True, + } + notification = self.env['firebase.notification'].sudo().create(notification_data) + print(notification) + print(notification_data) if all_device: - import json - record = self.env['firebase.notification'].sudo().create({ - "title":str(message_title), - "body":str(message_body), - "meta": str(json.dumps(data)) if data else None, - "partner_ids":[(4,self.id)], - "is_system":True, - "sent":True - }) - for reg in self.firebase_registration_ids: - reg.with_context(lang=self.lang).send_message(message_title, message_body,data={ - "title":str(message_title), - "body":str(message_body), - "meta": str(json.dumps(data)) if data else None, - "is_system":"true", - 'viewed':"false", - "sent":"true", - "data":str(record.create_date), - "id":str(record.id) - }) + reg.with_context(lang=self.lang).send_message( + message_title, + message_body, + data={ + "title": str(message_title), + "body": str(message_body), + "meta": json.dumps(data) if data else None, + "is_system": "true", + 'viewed': "false", + "sent": "true", + "data": str(notification.create_date), + "id": str(notification.id) + } + ) else: - self.firebase_registration_ids[0].with_context(lang=self.lang).send_message(message_title, message_body, data=data) + if self.firebase_registration_ids: + self.firebase_registration_ids[0].with_context(lang=self.lang).send_message( + message_title, + message_body, + data=data + ) def user_push_notification(self, fcm_token): url = "https://fcm.googleapis.com/fcm/send" - header = { + headers = { 'Content-Type': 'application/json', - 'Authorization': 'key=%s' % (self.env.user.company_id.fcm_server_key) + 'Authorization': f'key={self.env.user.company_id.fcm_server_key}' } body = json.dumps({ "to": fcm_token, @@ -50,7 +63,9 @@ class Partner(models.Model): } }) try: - respons = requests.post(url=url, data=body, headers=header) + response = requests.post(url=url, data=body, headers=headers) + response.raise_for_status() return True - except Exception as e: + except requests.exceptions.RequestException as e: + _logger.error(f"Failed to send push notification: {e}") return False diff --git a/odex25_mobile/odoo_dynamic_workflow_mobile/controllers/controllers.py b/odex25_mobile/odoo_dynamic_workflow_mobile/controllers/controllers.py index 4cdcc0b88..50c57f523 100644 --- a/odex25_mobile/odoo_dynamic_workflow_mobile/controllers/controllers.py +++ b/odex25_mobile/odoo_dynamic_workflow_mobile/controllers/controllers.py @@ -246,8 +246,7 @@ class RestApi(Controller): context = request.env.context.copy() context.update({"active_model": btn.model}) reject_reason = kw.get('reason_msg') - if reject_reason: - context.update({"reject_reason": reject_reason}) + context.update({"active_id": int(active_id)}) request.env.context = context btn.with_context(context)._run_code(active_id, btn.model, request.env) @@ -265,6 +264,8 @@ class RestApi(Controller): ) ) users = btn_new.mapped("group_ids").mapped("users") or None + if reject_reason: + obj.write({"reason": reject_reason}) obj.firebase_notification(users) return http_helper.response(message="Successful", data=res)