commit
be41df14d4
|
|
@ -195,7 +195,7 @@ class LeaveController(http.Controller):
|
|||
attach = http.request.env['ir.attachment'].create({
|
||||
'name': body['attachment'].filename,
|
||||
'datas': base64.b64encode(body['attachment'].read()),
|
||||
'datas_fname': body['attachment'].filename,
|
||||
'store_fname': body['attachment'].filename,
|
||||
'res_model': 'hr.holidays',
|
||||
'res_id': holidays.id,
|
||||
})
|
||||
|
|
@ -261,7 +261,7 @@ class LeaveController(http.Controller):
|
|||
attach = http.request.env['ir.attachment'].create({
|
||||
'name': body['attachment'].filename,
|
||||
'datas': base64.b64encode(body['attachment'].read()),
|
||||
'datas_fname': body['attachment'].filename,
|
||||
'store_fname': body['attachment'].filename,
|
||||
'res_model': 'hr.holidays',
|
||||
'res_id': holidays.id,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ class PermissionController(http.Controller):
|
|||
attach = http.request.env['ir.attachment'].sudo().create({
|
||||
'name': body['attachment'].filename,
|
||||
'datas': base64.b64encode(body['attachment'].read()),
|
||||
'datas_fname': body['attachment'].filename,
|
||||
'store_fname': body['attachment'].filename,
|
||||
'res_model': 'hr.personal.permission',
|
||||
'res_id': permission.id,
|
||||
'personal_permission_id': permission.id,
|
||||
|
|
@ -165,7 +165,7 @@ class PermissionController(http.Controller):
|
|||
attach = http.request.env['ir.attachment'].create({
|
||||
'name': body['attachment'].filename,
|
||||
'datas': base64.b64encode(body['attachment'].read()),
|
||||
'datas_fname': body['attachment'].filename,
|
||||
'store_fname': body['attachment'].filename,
|
||||
'res_model': 'hr.personal.permission',
|
||||
'res_id': permission.id,
|
||||
'personal_permission_id': permission.id,
|
||||
|
|
|
|||
|
|
@ -314,7 +314,6 @@ class AttendanceController(http.Controller):
|
|||
"You are not allowed to perform this operation. please check with one of your team admins"),
|
||||
success=False)
|
||||
try:
|
||||
print("******************employee.message_sent:",employee.message_sent)
|
||||
if json.loads(body['in_zone']):
|
||||
records = employee.attendance_log_ids.sudo().filtered(lambda r: str(r.date) == str(datetime.today().date()) and r.old == False)
|
||||
for r in records:
|
||||
|
|
@ -382,7 +381,6 @@ class AttendanceController(http.Controller):
|
|||
return http_helper.errcode(code=403, message=message)
|
||||
|
||||
def send_msg(self, emp, msg, subject):
|
||||
print("*****************************send")
|
||||
if emp.user_id.partner_id:
|
||||
partner_id = emp.user_id.partner_id
|
||||
partner_id.send_notification(subject, msg, data=None, all_device=True)
|
||||
|
|
|
|||
|
|
@ -227,7 +227,7 @@ class LeaveController(http.Controller):
|
|||
attach = http.request.env['ir.attachment'].sudo().create({
|
||||
'name': body['attachment'].filename,
|
||||
'datas': base64.b64encode(body['attachment'].read()),
|
||||
'datas_fname': body['attachment'].filename,
|
||||
'store_fname': body['attachment'].filename,
|
||||
'res_model': 'hr.holidays',
|
||||
'res_id': holidays.id,
|
||||
})
|
||||
|
|
@ -296,7 +296,7 @@ class LeaveController(http.Controller):
|
|||
attach = http.request.env['ir.attachment'].sudo().create({
|
||||
'name': body['attachment'].filename,
|
||||
'datas': base64.b64encode(body['attachment'].read()),
|
||||
'datas_fname': body['attachment'].filename,
|
||||
'store_fname': body['attachment'].filename,
|
||||
'res_model': 'hr.holidays',
|
||||
'res_id': holidays.id,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ class PermissionController(http.Controller):
|
|||
attach = http.request.env['ir.attachment'].sudo().create({
|
||||
'name': body['attachment'].filename,
|
||||
'datas': base64.b64encode(body['attachment'].read()),
|
||||
'datas_fname': body['attachment'].filename,
|
||||
'store_fname': body['attachment'].filename,
|
||||
'res_model': 'hr.personal.permission',
|
||||
'res_id': permission.id,
|
||||
'personal_permission_id': permission.id,
|
||||
|
|
@ -162,7 +162,7 @@ class PermissionController(http.Controller):
|
|||
attach = http.request.env['ir.attachment'].sudo().create({
|
||||
'name': body['attachment'].filename,
|
||||
'datas': base64.b64encode(body['attachment'].read()),
|
||||
'datas_fname': body['attachment'].filename,
|
||||
'store_fname': body['attachment'].filename,
|
||||
'res_model': 'hr.personal.permission',
|
||||
'res_id': permission.id,
|
||||
'personal_permission_id': permission.id,
|
||||
|
|
@ -203,7 +203,7 @@ class PermissionController(http.Controller):
|
|||
attach = http.request.env['ir.attachment'].sudo().create({
|
||||
'name': body['attachment'].filename,
|
||||
'datas': base64.b64encode(body['attachment'].read()),
|
||||
'datas_fname': body['attachment'].filename,
|
||||
'store_fname': body['attachment'].filename,
|
||||
'res_model': 'hr.personal.permission',
|
||||
'res_id': permission.id,
|
||||
'personal_permission_id': permission.id,
|
||||
|
|
|
|||
|
|
@ -20,6 +20,5 @@ class Base(models.AbstractModel):
|
|||
_inherit = 'base'
|
||||
|
||||
def firebase_notification(self,users=None):
|
||||
print("******************************firebase_notification******************************")
|
||||
return True
|
||||
|
||||
|
|
|
|||
|
|
@ -56,7 +56,6 @@ class FirebaseNotification(models.Model):
|
|||
|
||||
#@api.multi
|
||||
def send(self, **kwargs):
|
||||
# print("**********************************************")
|
||||
if kwargs is None:
|
||||
kwargs = {}
|
||||
for notif in self:
|
||||
|
|
|
|||
|
|
@ -60,11 +60,11 @@ class FirebaseRegistration(models.Model):
|
|||
"message_title"), self.env.context.get("message_body")
|
||||
)
|
||||
|
||||
|
||||
#@api.multi
|
||||
def send_message(self, message_title, message_body, data=None):
|
||||
if data is None:
|
||||
data = {}
|
||||
|
||||
if not firebase_app:
|
||||
_logger.error(
|
||||
"google_application_credentials is not correctly "
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from odoo import models, fields, api,_
|
||||
from odoo import models, fields, api, _
|
||||
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT
|
||||
import logging
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
|
@ -11,9 +11,9 @@ from ..validator import validator
|
|||
class Timesheet(models.Model):
|
||||
_inherit = 'hr_timesheet.sheet'
|
||||
|
||||
def firebase_notification(self,users=None):
|
||||
def firebase_notification(self, users=None):
|
||||
# def timesheet_notification(self,users=None):
|
||||
if self.employee_id :
|
||||
if self.employee_id:
|
||||
record = False
|
||||
_logger.warning("Write inner");
|
||||
lines = []
|
||||
|
|
@ -51,7 +51,7 @@ class Timesheet(models.Model):
|
|||
for part in partner:
|
||||
part.send_notification(
|
||||
_("Employee %s Timesheet Waiting Your Approve") % (self.employee_id.name),
|
||||
" %s - %s" % (self.date_start, self.date_end),data=data, all_device=True)
|
||||
" %s - %s" % (self.date_start, self.date_end), data=data, all_device=True)
|
||||
self.employee_id.user_id.partner_id.send_notification(
|
||||
_("Timesheet Has been Updated to %s") % (validator.get_state_name(self, self.state)),
|
||||
" %s - %s" % (self.date_start, self.date_end),
|
||||
|
|
@ -67,11 +67,11 @@ class Timesheet(models.Model):
|
|||
class HrHolidays(models.Model):
|
||||
_inherit = 'hr.holidays'
|
||||
|
||||
def firebase_notification(self,users=None):
|
||||
def firebase_notification(self, users=None):
|
||||
# def holiday_notification(self,users=None):
|
||||
if self.employee_id :
|
||||
if self.employee_id:
|
||||
_logger.warning("Write inner");
|
||||
value = {'employee_id':self.employee_id.id,'employee_name':self.employee_id.name,
|
||||
value = {'employee_id':self.employee_id.id, 'employee_name':self.employee_id.name,
|
||||
'id': self.id, 'type': self.holiday_status_id.name, 'type_value': self.holiday_status_id.id,
|
||||
'replacement_id': self.replace_by.id if self.replace_by else False,
|
||||
'replacement_name': self.replace_by.name if self.replace_by else False,
|
||||
|
|
@ -100,14 +100,14 @@ class HrHolidays(models.Model):
|
|||
partner = users.mapped('partner_id')
|
||||
for part in partner:
|
||||
part.send_notification(_("Employee %s Leave Waiting Your Approve") % (self.employee_id.name),
|
||||
" %s - %s" % (self.date_from, self.date_to),data=data, all_device=True)
|
||||
" %s - %s" % (str(self.date_from), str(self.date_to)), data=data, all_device=True)
|
||||
self.employee_id.user_id.partner_id.send_notification(
|
||||
_("Leave Request Has Been Updated to %s") % (validator.get_state_name(self, self.state)),
|
||||
" %s - %s " % (self.date_from, self.date_to),
|
||||
data=data, all_device=True)
|
||||
|
||||
def get_attchment(self,res_id):
|
||||
attachment = self.env['ir.attachment'].search([('res_model','=','hr.holidays'),('res_id','=',res_id.id)])
|
||||
def get_attchment(self, res_id):
|
||||
attachment = self.env['ir.attachment'].search([('res_model', '=', 'hr.holidays'), ('res_id', '=', res_id.id)])
|
||||
li = []
|
||||
if attachment:
|
||||
url_base = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
|
||||
|
|
@ -116,10 +116,11 @@ class HrHolidays(models.Model):
|
|||
li.append(url)
|
||||
return li
|
||||
|
||||
|
||||
class Overtime(models.Model):
|
||||
_inherit = 'employee.overtime.request'
|
||||
|
||||
def firebase_notification(self,users=None):
|
||||
def firebase_notification(self, users=None):
|
||||
# def overtime_notification(self,users=None):
|
||||
records = False
|
||||
value = {'id': self.id, 'transfer_type': self.transfer_type, 'request_date': str(self.request_date),
|
||||
|
|
@ -129,7 +130,7 @@ class Overtime(models.Model):
|
|||
'reason': self.reason}
|
||||
record = value
|
||||
for rec in self.line_ids_over_time:
|
||||
if rec.employee_id :
|
||||
if rec.employee_id:
|
||||
_logger.warning("Write inner");
|
||||
li = []
|
||||
if self.line_ids_over_time:
|
||||
|
|
@ -160,18 +161,18 @@ class Overtime(models.Model):
|
|||
all_device=True)
|
||||
if rec.employee_id.user_id:
|
||||
rec.employee_id.user_id.partner_id.send_notification(
|
||||
_("Overtime Request has been Updated to %s ")%(validator.get_state_name(self,self.state)), " %s - %s" % (self.date_from, self.date_to),
|
||||
_("Overtime Request has been Updated to %s ") % (validator.get_state_name(self, self.state)), " %s - %s" % (self.date_from, self.date_to),
|
||||
data=data, all_device=True)
|
||||
|
||||
|
||||
class HrPersonalPermission(models.Model):
|
||||
_inherit = 'hr.personal.permission'
|
||||
|
||||
|
||||
#@api.multi
|
||||
def firebase_notification(self,users=None):
|
||||
# @api.multi
|
||||
def firebase_notification(self, users=None):
|
||||
# def permission_notification(self,users=None):
|
||||
if self.employee_id:
|
||||
value = {'employee_id':self.employee_id.id,'employee_name':self.employee_id.name,'id': self.id, 'date_from': str(self.date_from), 'date_to': str(self.date_to), 'duration': self.duration,
|
||||
value = {'employee_id':self.employee_id.id, 'employee_name':self.employee_id.name, 'id': self.id, 'date_from': str(self.date_from), 'date_to': str(self.date_to), 'duration': self.duration,
|
||||
'date': str(self.date), 'state_name': self.state,
|
||||
'state': validator.get_state_name(self, self.state), 'early_exit': self.early_exit,
|
||||
'attachment': self.get_attchment(self)}
|
||||
|
|
@ -190,7 +191,7 @@ class HrPersonalPermission(models.Model):
|
|||
part.send_notification(_("Employee %s Permission Waiting Your Approve") % (self.employee_id.name),
|
||||
" %s - %s" % (self.date_from, self.date_to), data=data, all_device=True)
|
||||
self.employee_id.user_id.partner_id.send_notification(
|
||||
_("Permission Request has been updated to %s ") %(validator.get_state_name(self,self.state)) ," %s - %s" % (self.date_from, self.date_to),
|
||||
_("Permission Request has been updated to %s ") % (validator.get_state_name(self, self.state)) , " %s - %s" % (self.date_from, self.date_to),
|
||||
data=data, all_device=True)
|
||||
|
||||
def get_attchment(self, res_id):
|
||||
|
|
@ -202,18 +203,20 @@ class HrPersonalPermission(models.Model):
|
|||
url = url_base + "/web/content/%s" % (att.id)
|
||||
li.append(url)
|
||||
return li
|
||||
|
||||
|
||||
#
|
||||
class HrSalaryAdvance(models.Model):
|
||||
_inherit = 'hr.loan.salary.advance'
|
||||
|
||||
#@api.multi
|
||||
def firebase_notification(self,users=None):
|
||||
# @api.multi
|
||||
def firebase_notification(self, users=None):
|
||||
# def firebase_notification(self, users=None):
|
||||
if self.employee_id :
|
||||
if self.employee_id:
|
||||
_logger.warning("Write inner");
|
||||
value = {'employee_id':self.employee_id.id,'employee_name':self.employee_id.name,'id': self.id, 'code': self.code, 'expect_amount': self.emp_expect_amount, 'date': str(self.date),
|
||||
value = {'employee_id':self.employee_id.id, 'employee_name':self.employee_id.name, 'id': self.id, 'code': self.code, 'expect_amount': self.emp_expect_amount, 'date': str(self.date),
|
||||
'installment_amount': self.installment_amount, 'state': validator.get_state_name(self, self.state),
|
||||
'months': self.months,'state_name': self.state,
|
||||
'months': self.months, 'state_name': self.state,
|
||||
|
||||
'request_type_id': self.request_type.id, 'request_type_name': self.request_type.name}
|
||||
lines = []
|
||||
|
|
@ -236,8 +239,8 @@ class HrSalaryAdvance(models.Model):
|
|||
if users:
|
||||
partner = users.mapped('partner_id')
|
||||
for part in partner:
|
||||
part.send_notification(_("Employee %s Loan %s Waiting Your Approve") % (self.employee_id.name,self.code),
|
||||
_("Loan %s Waiting Your Approve")%(self.code), data=data, all_device=True)
|
||||
part.send_notification(_("Employee %s Loan %s Waiting Your Approve") % (self.employee_id.name, self.code),
|
||||
_("Loan %s Waiting Your Approve") % (self.code), data=data, all_device=True)
|
||||
self.employee_id.user_id.partner_id.send_notification(
|
||||
_("Loan %s") %(self.code),_("Has been updated to %s") % (validator.get_state_name(self, self.state)),
|
||||
_("Loan %s") % (self.code), _("Has been updated to %s") % (validator.get_state_name(self, self.state)),
|
||||
data=data, all_device=True)
|
||||
|
|
|
|||
|
|
@ -12,6 +12,16 @@ class Partner(models.Model):
|
|||
"firebase.registration", "partner_id", readonly=True
|
||||
)
|
||||
|
||||
def send_msg(self, partner_ids, msg, subject):
|
||||
emp = self.env['hr.employee'].sudo().search([('user_id', 'in', partner_ids.user_ids.ids)])
|
||||
if emp.user_id.partner_id:
|
||||
partner_id = emp.user_id.partner_id
|
||||
# partner_id.send_notification(subject, msg, data=None, all_device=True)
|
||||
data = {
|
||||
'title':subject,
|
||||
'body':msg,
|
||||
}
|
||||
emp.user_push_notification(data)
|
||||
def send_notification(self, message_title, message_body, data=None, all_device=True):
|
||||
notification_data = {
|
||||
"title": str(message_title),
|
||||
|
|
@ -22,7 +32,9 @@ class Partner(models.Model):
|
|||
"sent": True,
|
||||
}
|
||||
notification = self.env['firebase.notification'].sudo().create(notification_data)
|
||||
|
||||
if all_device:
|
||||
self.send_msg(notification.partner_ids,str(message_title),str(message_body))
|
||||
for reg in self.firebase_registration_ids:
|
||||
reg.with_context(lang=self.lang).send_message(
|
||||
message_title,
|
||||
|
|
|
|||
|
|
@ -110,7 +110,6 @@ class Validator:
|
|||
algorithm='HS256'
|
||||
)
|
||||
# payload = jwt.decode(token, SECRET_KEY ,algorithms='HS256')
|
||||
print(token)
|
||||
self.save_token(token, user['id'], exp)
|
||||
|
||||
return token
|
||||
|
|
|
|||
|
|
@ -110,7 +110,6 @@ class Validator:
|
|||
algorithm='HS256'
|
||||
)
|
||||
# payload = jwt.decode(token, SECRET_KEY ,algorithms='HS256')
|
||||
print(token)
|
||||
self.save_token(token, user['id'], exp)
|
||||
|
||||
return token
|
||||
|
|
|
|||
|
|
@ -247,22 +247,11 @@ class RestApi(Controller):
|
|||
btn.with_context(context)._run_code(active_id, btn.model, request.env)
|
||||
res = obj.read(["id", "state"])[0]
|
||||
state = res["state"]
|
||||
btn_new = (
|
||||
request.env[BTN]
|
||||
.sudo()
|
||||
.search(
|
||||
[
|
||||
("workflow_id", "=", int(btn.workflow_id.id)),
|
||||
(("node_id.node_name", "=", state)),
|
||||
],
|
||||
[],
|
||||
)
|
||||
)
|
||||
btn_new = request.env[BTN].sudo().search([("workflow_id", "=", int(btn.workflow_id.id)), (("node_id.node_name", "=", state)), ], [],)
|
||||
group_ids = btn_new.mapped("group_ids")
|
||||
users = group_ids.mapped("users") or None
|
||||
print("***************************************users", users)
|
||||
users_list = self.access_users(group_ids, btn)
|
||||
print("***************************************users_list", users_list)
|
||||
rule_groups = btn_new.mapped("group_ids").mapped("rule_groups").filtered(lambda rec:rec.model_id.model == obj._name)
|
||||
users_list = self.access_users(group_ids, obj)
|
||||
users = request.env['res.users'].sudo().search([('id', 'in', users_list)])
|
||||
if reject_reason:
|
||||
obj.write({"reason": reject_reason})
|
||||
obj.firebase_notification(users)
|
||||
|
|
@ -276,17 +265,16 @@ class RestApi(Controller):
|
|||
|
||||
def has_access(self, user_id, record, mode='read'):
|
||||
try:
|
||||
access = record.with_user(user_id).check_access_rule(mode)
|
||||
print("-----------------------",access)
|
||||
record.with_user(user_id).check_access_rule(mode)
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
|
||||
def access_users(self, groups, record):
|
||||
users = []
|
||||
print(groups,record)
|
||||
for group in groups:
|
||||
for user in group.users:
|
||||
if self.has_access(user_id=user.id, record=record, mode='read'):
|
||||
users.append(user)
|
||||
users.append(int(user.id))
|
||||
return users
|
||||
|
||||
|
|
|
|||
|
|
@ -251,12 +251,10 @@ class OdooWorkflow(models.Model):
|
|||
|
||||
def firebase_notification(self):
|
||||
super(OdooWorkflow,self).firebase_notification()
|
||||
print("abzuar")
|
||||
|
||||
# @api.multi
|
||||
def btn_nodes(self):
|
||||
for rec in self:
|
||||
print("**************************************************")
|
||||
rec.firebase_notification()
|
||||
act = {
|
||||
'name': _('Nodes'),
|
||||
|
|
@ -522,7 +520,6 @@ class OdooWorkflowBtnWizard(models.Model):
|
|||
if not rec.invisible_attrs:
|
||||
return True
|
||||
cx = self.env.context.copy() or {}
|
||||
# print(cx)
|
||||
obj = rec.env[cx.get('active_model', False)].browse(cx.get('active_id', 0))
|
||||
locals_dict = {
|
||||
'env': rec.env,
|
||||
|
|
|
|||
Loading…
Reference in New Issue