mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
[IMP] hibou_professional: use token authentication and change quote behavior
This commit is contained in:
@@ -13,6 +13,8 @@ class PublisherWarrantyContract(models.AbstractModel):
|
|||||||
CONFIG_HIBOU_URL = 'https://odoo-hibou-test12.hibou-test-odoo.us-w-p1.hibou.me/hibouapi/v1/professional'
|
CONFIG_HIBOU_URL = 'https://odoo-hibou-test12.hibou-test-odoo.us-w-p1.hibou.me/hibouapi/v1/professional'
|
||||||
# CONFIG_HIBOU_MESSAGE_URL = 'https://hibou.io/hibouapi/v1/professional/message'
|
# CONFIG_HIBOU_MESSAGE_URL = 'https://hibou.io/hibouapi/v1/professional/message'
|
||||||
CONFIG_HIBOU_MESSAGE_URL = 'https://odoo-hibou-test12.hibou-test-odoo.us-w-p1.hibou.me/hibouapi/v1/professional/message'
|
CONFIG_HIBOU_MESSAGE_URL = 'https://odoo-hibou-test12.hibou-test-odoo.us-w-p1.hibou.me/hibouapi/v1/professional/message'
|
||||||
|
# CONFIG_HIBOU_QUOTE_URL = 'https://hibou.io/hibouapi/v1/professional/quote'
|
||||||
|
CONFIG_HIBOU_QUOTE_URL = 'https://odoo-hibou-test12.hibou-test-odoo.us-w-p1.hibou.me/hibouapi/v1/professional/quote'
|
||||||
DAYS_ENDING_SOON = 7
|
DAYS_ENDING_SOON = 7
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
@@ -70,11 +72,25 @@ class PublisherWarrantyContract(models.AbstractModel):
|
|||||||
if not allow_message:
|
if not allow_message:
|
||||||
raise UserError('You are not allowed to send messages at this time.')
|
raise UserError('You are not allowed to send messages at this time.')
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def hibou_professional_quote(self):
|
||||||
|
get_param = self.env['ir.config_parameter'].sudo().get_param
|
||||||
|
try:
|
||||||
|
self._hibou_install()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
dbuuid = get_param('database.uuid')
|
||||||
|
dbtoken = get_param('database.hibou_token')
|
||||||
|
if dbuuid and dbtoken:
|
||||||
|
return {'url': self.CONFIG_HIBOU_QUOTE_URL + '/%s/%s' % (dbuuid, dbtoken)}
|
||||||
|
return {}
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def hibou_professional_send_message(self, type, priority, subject, body, user_url, res_id):
|
def hibou_professional_send_message(self, type, priority, subject, body, user_url, res_id):
|
||||||
self._check_message_allow()
|
self._check_message_allow()
|
||||||
get_param = self.env['ir.config_parameter'].sudo().get_param
|
get_param = self.env['ir.config_parameter'].sudo().get_param
|
||||||
dbuuid = get_param('database.uuid')
|
dbuuid = get_param('database.uuid')
|
||||||
|
dbtoken = get_param('database.hibou_token')
|
||||||
user_name = self.env.user.name
|
user_name = self.env.user.name
|
||||||
user_email = self.env.user.email or self.env.user.login
|
user_email = self.env.user.email or self.env.user.login
|
||||||
company_name = self.env.user.company_id.name
|
company_name = self.env.user.company_id.name
|
||||||
@@ -94,20 +110,29 @@ class PublisherWarrantyContract(models.AbstractModel):
|
|||||||
'res_id': res_id,
|
'res_id': res_id,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
r = requests.post(self.CONFIG_HIBOU_MESSAGE_URL + '/new', json=data, timeout=30)
|
if dbtoken:
|
||||||
r.raise_for_status()
|
data['params']['dbtoken'] = dbtoken
|
||||||
wrapper = r.json()
|
try:
|
||||||
return wrapper.get('result', {})
|
r = requests.post(self.CONFIG_HIBOU_MESSAGE_URL + '/new', json=data, timeout=30)
|
||||||
|
r.raise_for_status()
|
||||||
|
wrapper = r.json()
|
||||||
|
return wrapper.get('result', {})
|
||||||
|
except:
|
||||||
|
return {'error': 'Error sending message.'}
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def hibou_professional_get_messages(self):
|
def hibou_professional_get_messages(self):
|
||||||
self._check_message_allow()
|
self._check_message_allow()
|
||||||
get_param = self.env['ir.config_parameter'].sudo().get_param
|
get_param = self.env['ir.config_parameter'].sudo().get_param
|
||||||
dbuuid = get_param('database.uuid')
|
dbuuid = get_param('database.uuid')
|
||||||
r = requests.get(self.CONFIG_HIBOU_MESSAGE_URL + '/get/%s' % (dbuuid, ), timeout=30)
|
dbtoken = get_param('database.hibou_token')
|
||||||
r.raise_for_status()
|
try:
|
||||||
# not jsonrpc
|
r = requests.get(self.CONFIG_HIBOU_MESSAGE_URL + '/get/%s/%s' % (dbuuid, dbtoken), timeout=30)
|
||||||
return r.json()
|
r.raise_for_status()
|
||||||
|
# not jsonrpc
|
||||||
|
return r.json()
|
||||||
|
except:
|
||||||
|
return {'error': 'Error retrieving messages, maybe the token is wrong.'}
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def hibou_professional_update(self, professional_code):
|
def hibou_professional_update(self, professional_code):
|
||||||
@@ -128,6 +153,7 @@ class PublisherWarrantyContract(models.AbstractModel):
|
|||||||
IrParamSudo = self.env['ir.config_parameter'].sudo()
|
IrParamSudo = self.env['ir.config_parameter'].sudo()
|
||||||
|
|
||||||
dbuuid = IrParamSudo.get_param('database.uuid')
|
dbuuid = IrParamSudo.get_param('database.uuid')
|
||||||
|
dbtoken = IrParamSudo.get_param('database.hibou_token')
|
||||||
db_create_date = IrParamSudo.get_param('database.create_date')
|
db_create_date = IrParamSudo.get_param('database.create_date')
|
||||||
user = self.env.user
|
user = self.env.user
|
||||||
professional_code = IrParamSudo.get_param('database.hibou_professional_code')
|
professional_code = IrParamSudo.get_param('database.hibou_professional_code')
|
||||||
@@ -148,6 +174,8 @@ class PublisherWarrantyContract(models.AbstractModel):
|
|||||||
"modules": '\n'.join(modules),
|
"modules": '\n'.join(modules),
|
||||||
"professional_code": professional_code,
|
"professional_code": professional_code,
|
||||||
}
|
}
|
||||||
|
if dbtoken:
|
||||||
|
msg['dbtoken'] = dbtoken
|
||||||
if user.partner_id.company_id:
|
if user.partner_id.company_id:
|
||||||
company_id = user.partner_id.company_id
|
company_id = user.partner_id.company_id
|
||||||
msg.update(company_id.read(["name", "email", "phone"])[0])
|
msg.update(company_id.read(["name", "email", "phone"])[0])
|
||||||
@@ -158,7 +186,10 @@ class PublisherWarrantyContract(models.AbstractModel):
|
|||||||
set_param = self.env['ir.config_parameter'].sudo().set_param
|
set_param = self.env['ir.config_parameter'].sudo().set_param
|
||||||
set_param('database.hibou_professional_expiration_date', result['professional_info'].get('expiration_date'))
|
set_param('database.hibou_professional_expiration_date', result['professional_info'].get('expiration_date'))
|
||||||
set_param('database.hibou_professional_expiration_reason', result['professional_info'].get('expiration_reason', 'trial'))
|
set_param('database.hibou_professional_expiration_reason', result['professional_info'].get('expiration_reason', 'trial'))
|
||||||
set_param('database.hibou_professional_code', result['professional_info'].get('professional_code'))
|
if result['professional_info'].get('professional_code'):
|
||||||
|
set_param('database.hibou_professional_code', result['professional_info'].get('professional_code'))
|
||||||
|
if result['professional_info'].get('dbtoken'):
|
||||||
|
set_param('database.hibou_token', result['professional_info'].get('dbtoken'))
|
||||||
|
|
||||||
def _hibou_install(self):
|
def _hibou_install(self):
|
||||||
data = self._get_hibou_message()
|
data = self._get_hibou_message()
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ var HibouProfessionalSystrayWidget = Widget.extend({
|
|||||||
self.expiring = false;
|
self.expiring = false;
|
||||||
self.expired = false;
|
self.expired = false;
|
||||||
self.dbuuid = false;
|
self.dbuuid = false;
|
||||||
|
self.quote_url = false;
|
||||||
self.is_admin = false;
|
self.is_admin = false;
|
||||||
self.allow_admin_message = false;
|
self.allow_admin_message = false;
|
||||||
self.allow_message = false;
|
self.allow_message = false;
|
||||||
@@ -36,6 +37,10 @@ var HibouProfessionalSystrayWidget = Widget.extend({
|
|||||||
return [];
|
return [];
|
||||||
},
|
},
|
||||||
|
|
||||||
|
set_error: function(error) {
|
||||||
|
this.$('.hibou_professional_error').text(error);
|
||||||
|
},
|
||||||
|
|
||||||
update_message_type: function(el) {
|
update_message_type: function(el) {
|
||||||
var selected_type = this.$('select.hibou_message_type').val();
|
var selected_type = this.$('select.hibou_message_type').val();
|
||||||
if (selected_type && this.$('.hibou_subject_selection_option.' + selected_type).length > 0) {
|
if (selected_type && this.$('.hibou_subject_selection_option.' + selected_type).length > 0) {
|
||||||
@@ -105,6 +110,24 @@ var HibouProfessionalSystrayWidget = Widget.extend({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
button_quote: function() {
|
||||||
|
var self = this;
|
||||||
|
var message_p = self.$('.button-quote-link p');
|
||||||
|
message_p.text('Retrieving URL...');
|
||||||
|
self._rpc({
|
||||||
|
model: 'publisher_warranty.contract',
|
||||||
|
method: 'hibou_professional_quote',
|
||||||
|
}).then(function (result) {
|
||||||
|
if (result && result['url']) {
|
||||||
|
self.quote_url = result.url
|
||||||
|
self.$('.button-quote-link').attr('href', self.quote_url);
|
||||||
|
message_p.text('Quote URL ready. Click again!');
|
||||||
|
} else {
|
||||||
|
message_p.text('Error with quote url. Maybe the database token is incorrect.');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
button_send_message: function() {
|
button_send_message: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
var message_type = self.$('select.hibou_message_type').val();
|
var message_type = self.$('select.hibou_message_type').val();
|
||||||
@@ -155,8 +178,14 @@ var HibouProfessionalSystrayWidget = Widget.extend({
|
|||||||
args: [],
|
args: [],
|
||||||
}).then(function (result) {
|
}).then(function (result) {
|
||||||
$button.prop('disabled', false);
|
$button.prop('disabled', false);
|
||||||
self.update_message_subjects(result.message_subjects);
|
if (result['message_subjects']) {
|
||||||
setTimeout(function (){self.$('.dropdown-toggle').click();}, 100);
|
self.update_message_subjects(result.message_subjects);
|
||||||
|
setTimeout(function () {
|
||||||
|
self.$('.dropdown-toggle').click();
|
||||||
|
}, 100);
|
||||||
|
} else if (result['error']) {
|
||||||
|
self.set_error(result['error']);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -187,6 +216,16 @@ var HibouProfessionalSystrayWidget = Widget.extend({
|
|||||||
self.button_get_messages();
|
self.button_get_messages();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Retrieve quote URL
|
||||||
|
this.$('.button-quote-link').on('click', function(e){
|
||||||
|
if (self.quote_url) {
|
||||||
|
return; // allow default url click event
|
||||||
|
}
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
self.button_quote();
|
||||||
|
});
|
||||||
|
|
||||||
// Update Message Preferences Button
|
// Update Message Preferences Button
|
||||||
this.$('.update_message_preferences').on('click', function(e){
|
this.$('.update_message_preferences').on('click', function(e){
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
<div>
|
<div>
|
||||||
<p>We're here to help!<br/>Click here to review Hibou's help resources or to contact us today.</p>
|
<p>We're here to help!<br/>Click here to review Hibou's help resources or to contact us today.</p>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="text-danger hibou_professional_error"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
@@ -82,8 +83,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<t t-if="widget.expiration_reason == 'trial' || (! widget.expiration_reason) || widget.expired || widget.expiring">
|
<t t-if="widget.expiration_reason == 'trial' || (! widget.expiration_reason) || widget.expired || widget.expiring">
|
||||||
<a t-attf-href="https://odoo-hibou-test12.hibou-test-odoo.us-w-p1.hibou.me/hibouapi/v1/professional/quote/#{widget.dbuuid}" target="_blank">
|
<a class="button-quote-link" target="_blank">
|
||||||
<!-- <a t-attf-href="https://hibou.io/hibouapi/v1/professional/quote/#{widget.dbuuid}" target="_blank">-->
|
|
||||||
<div class="o_mail_preview">
|
<div class="o_mail_preview">
|
||||||
<div class="o_preview_info">
|
<div class="o_preview_info">
|
||||||
<div class="o_preview_title">
|
<div class="o_preview_title">
|
||||||
|
|||||||
Reference in New Issue
Block a user