Browse Source

[Fix] add changes for lint errors

pull/35/head
ITISAG-Git 5 years ago
parent
commit
3672394342
  1. 2
      .gitignore
  2. 0
      website_contact_extend/__manifest__.py
  3. 45
      website_contact_extend/controllers/contactby.py
  4. 41
      website_contact_extend/controllers/myfilter.py
  5. 0
      website_contact_extend/models/__init__.py
  6. 2
      website_contact_extend/models/res_partner.py
  7. 23
      website_contact_extend/static/src/js/contactus.js

2
.gitignore

@ -57,3 +57,5 @@ docs/_build/
# OSX Files # OSX Files
*.DS_Store *.DS_Store
.eslintrc.json

0
website_contact_extend/__manifest__.py

45
website_contact_extend/controllers/contactby.py

@ -3,8 +3,6 @@
from odoo.addons.website_form.controllers import main as parent_controller from odoo.addons.website_form.controllers import main as parent_controller
from odoo import http from odoo import http
from odoo.http import request from odoo.http import request
from odoo.exceptions import ValidationError
from psycopg2 import IntegrityError
import base64 import base64
import json import json
@ -13,7 +11,8 @@ link_data = {}
class ContactByController(http.Controller): class ContactByController(http.Controller):
@http.route('/check_user_exists/', type='json', auth="public", methods=['POST'], website=True, csrf=False)
@http.route('/check_user_exists/', type='json', auth="public",
methods=['POST'], website=True, csrf=False)
def check_user_exists(self, email_from, company_name, **kwargs): def check_user_exists(self, email_from, company_name, **kwargs):
res_part_rec = request.env['res.partner'].sudo().search([ res_part_rec = request.env['res.partner'].sudo().search([
('email', '=', email_from), ('email', '=', email_from),
@ -22,7 +21,8 @@ class ContactByController(http.Controller):
res_part_email = request.env['res.partner'].sudo().search([ res_part_email = request.env['res.partner'].sudo().search([
('email', '=', email_from)]) ('email', '=', email_from)])
if len(res_part_rec) > 0 or len(res_part_rec) == 0 and len(res_part_email) > 0:
if len(res_part_rec) > 0 or len(res_part_rec) == 0 \
and len(res_part_email) > 0:
# if partner: # if partner:
return True return True
return False return False
@ -37,7 +37,9 @@ class ContactByController(http.Controller):
# link_data =base64.b64decode(kwargs.get("data")).decode("utf-8") \ # link_data =base64.b64decode(kwargs.get("data")).decode("utf-8") \
# print('FD') # print('FD')
# print(request.session['form_data']) # print(request.session['form_data'])
return http.request.render('website_contact_extend.review_form', {'form_data': request.session['form_data'],
return http.request.render(
'website_contact_extend.review_form',
{'form_data': request.session['form_data'],
'form_data_dict': request.session['form_data_dict']}) 'form_data_dict': request.session['form_data_dict']})
@http.route('/contact_by/<string:data>', @http.route('/contact_by/<string:data>',
@ -52,7 +54,8 @@ class ContactByController(http.Controller):
# link_data =base64.b64decode(kwargs.get("data")).decode("utf-8") \ # link_data =base64.b64decode(kwargs.get("data")).decode("utf-8") \
link_data = data link_data = data
return http.request.render('website_contact_extend.contactby_form') return http.request.render('website_contact_extend.contactby_form')
# return "<center style='color:red'>You are at the right place</center>"
# return "<center style='color:red'>You are at the right \
# place</center>"
@http.route('/contact_by_send/<string:model_name>', @http.route('/contact_by_send/<string:model_name>',
type='http', type='http',
@ -130,11 +133,17 @@ class ContactByController(http.Controller):
return json.dumps({'id': partner[0].id}) return json.dumps({'id': partner[0].id})
# return http.request.render('website_contact_extend.disp_msg_template', {'message_success': 'Means of contact changed!'})
# return http.request.render('website_contact_extend.\
# disp_msg_template', {'message_success': \
# 'Means of contact changed!'})
# return "<p style='color: green'>Means of contact changed!</p>" # return "<p style='color: green'>Means of contact changed!</p>"
# else: # else:
# # return http.request.render('website_contact_extend.disp_msg_template', {'message_failure': 'Could not change your means of contact. Please request a new link'})
# return "<p style='color: red'>Could not change your means of contact. Please request a new link</p>"
# return http.request.render('website_contact_extend.\
# disp_msg_template', {'message_failure': \
# 'Could not change your means of contact. \
# Please request a new link'})
# return "<p style='color: red'>Could not change your means\
# of contact. Please request a new link</p>"
class FormReview(parent_controller.WebsiteForm): class FormReview(parent_controller.WebsiteForm):
@ -177,7 +186,8 @@ class FormReview(parent_controller.WebsiteForm):
'' ''
) )
if len(res_part_email) > 0 and len(res_part_rec) == 0 and res_part_email[0].is_verified == True:
if len(res_part_email) > 0 and len(res_part_rec) == 0 and \
res_part_email[0].is_verified is True:
print('Company change detected') print('Company change detected')
res_cat = request.env['res.partner.category'].search( res_cat = request.env['res.partner.category'].search(
@ -220,10 +230,12 @@ class FormReview(parent_controller.WebsiteForm):
if update_parent_partner and len(update_parent_partner) > 0: if update_parent_partner and len(update_parent_partner) > 0:
update_parent_partner[0].category_id = False update_parent_partner[0].category_id = False
update_parent_partner_comp = request.env['res.partner'].sudo().search([
update_parent_partner_comp = \
request.env['res.partner'].sudo().search([
('id', '=', res_part_email[0].parent_id.id)]) ('id', '=', res_part_email[0].parent_id.id)])
if update_parent_partner_comp and len(update_parent_partner_comp) > 0:
if update_parent_partner_comp and \
len(update_parent_partner_comp) > 0:
update_parent_partner_comp[0].category_id = False update_parent_partner_comp[0].category_id = False
res_partner_company_dict = res_partner_dict.copy() res_partner_company_dict = res_partner_dict.copy()
@ -234,7 +246,8 @@ class FormReview(parent_controller.WebsiteForm):
res_partner_company_dict.pop('phone') res_partner_company_dict.pop('phone')
res_partner_company_dict['name'] = res_partner_data['partner_name'] res_partner_company_dict['name'] = res_partner_data['partner_name']
res_partner_company_dict['display_name'] = res_partner_data['partner_name']
res_partner_company_dict['display_name'] = \
res_partner_data['partner_name']
res_partner_company_dict['customer'] = False res_partner_company_dict['customer'] = False
res_partner_company_dict['is_company'] = True res_partner_company_dict['is_company'] = True
res_partner_company_dict['company_type'] = 'company' res_partner_company_dict['company_type'] = 'company'
@ -252,7 +265,8 @@ class FormReview(parent_controller.WebsiteForm):
res_partner_company_dict['child_ids'] = [ res_partner_company_dict['child_ids'] = [
[6, 'virtual_1798', [id_record_res]]] [6, 'virtual_1798', [id_record_res]]]
id_record_res_company = self.insert_record(
# id_record_res_company = self.insert_record(
self.insert_record(
request, request,
request.env['ir.model'].search( request.env['ir.model'].search(
[('model', '=', 'res.partner')]), [('model', '=', 'res.partner')]),
@ -305,7 +319,8 @@ class FormReview(parent_controller.WebsiteForm):
'website_contact_extend.verification_email_template' 'website_contact_extend.verification_email_template'
).sudo().send_mail(id_record) ).sudo().send_mail(id_record)
request.env.ref('website_contact_extend.email_template_onchange_data').sudo(
request.env.ref('website_contact_extend.\
email_template_onchange_data').sudo(
).send_mail(id_record) ).send_mail(id_record)
request.session['form_builder_model_model'] = model_record.model request.session['form_builder_model_model'] = model_record.model

41
website_contact_extend/controllers/myfilter.py

@ -16,8 +16,6 @@ class VerifyController(http.Controller):
methods=['GET'], methods=['GET'],
website=True) website=True)
def verify_email(self, **kwargs): def verify_email(self, **kwargs):
print(kwargs)
if kwargs: if kwargs:
contact_url = '%s/contact_by/%s' % ( contact_url = '%s/contact_by/%s' % (
@ -80,13 +78,16 @@ class VerifyController(http.Controller):
if request_gdpdr == "True": if request_gdpdr == "True":
# print("Hit") # print("Hit")
page_render_html = page_render_html + "<br/>"\ page_render_html = page_render_html + "<br/>"\
"<div style='text-align: center'>Click <a href='" + contact_url + \
"'>here</a> to choose how you want to be contacted</div>"
"<div style='text-align: center'>"\
"Click <a href='" + contact_url + \
"'>here</a> to choose how you"\
" want to be contacted</div>"
if personal_data == "True": if personal_data == "True":
request.env.ref( request.env.ref(
'website_contact_extend.email_template_information_request'
'website_contact_extend.\
email_template_information_request'
).sudo().send_mail(int(crm_id)) ).sudo().send_mail(int(crm_id))
request.env.ref( request.env.ref(
@ -122,7 +123,6 @@ class MyFilter(parent_controller.WebsiteForm):
# need_send_email = False # need_send_email = False
try: try:
data = self.extract_data(model_record, request.params) data = self.extract_data(model_record, request.params)
print(data)
# contact_type = False # contact_type = False
phone_contact = False phone_contact = False
letter_contact = False letter_contact = False
@ -160,7 +160,7 @@ class MyFilter(parent_controller.WebsiteForm):
res_partner_data = data['record'] res_partner_data = data['record']
try: try:
contact_name = data.get("record").get("contact_name")
# contact_name = data.get("record").get("contact_name")
email = data.get("record").get("email_from") email = data.get("record").get("email_from")
company = data.get("record").get("partner_name") company = data.get("record").get("partner_name")
res_part_rec = request.env['res.partner'].sudo().search([ res_part_rec = request.env['res.partner'].sudo().search([
@ -172,7 +172,8 @@ class MyFilter(parent_controller.WebsiteForm):
res_part_email = request.env['res.partner'].sudo().search([ res_part_email = request.env['res.partner'].sudo().search([
('email', '=', email)]) ('email', '=', email)])
if len(res_part_rec) > 0 or len(res_part_rec) == 0 and len(res_part_email) > 0:
if len(res_part_rec) > 0 or len(res_part_rec) == 0 \
and len(res_part_email) > 0:
request.session['review_form'] = "/contact-us-form-review" request.session['review_form'] = "/contact-us-form-review"
print('Display review') print('Display review')
@ -248,11 +249,13 @@ class MyFilter(parent_controller.WebsiteForm):
# res_partner_data['phone'] = "" # res_partner_data['phone'] = ""
res_partner_dict['name'] = res_partner_data['contact_name'] res_partner_dict['name'] = res_partner_data['contact_name']
res_partner_dict['display_name'] = res_partner_data['contact_name']
res_partner_dict['display_name'] = \
res_partner_data['contact_name']
res_partner_dict['email'] = res_partner_data['email_from'] res_partner_dict['email'] = res_partner_data['email_from']
if 'phone' in res_partner_data: if 'phone' in res_partner_data:
res_partner_dict['phone'] = res_partner_data['phone'] res_partner_dict['phone'] = res_partner_data['phone']
res_partner_dict['company_name'] = res_partner_data['partner_name']
res_partner_dict['company_name'] = \
res_partner_data['partner_name']
res_partner_dict['category_id'] = [[6, False, [cat_id]]] res_partner_dict['category_id'] = [[6, False, [cat_id]]]
res_partner_company_dict = res_partner_dict.copy() res_partner_company_dict = res_partner_dict.copy()
@ -261,8 +264,10 @@ class MyFilter(parent_controller.WebsiteForm):
if 'phone' in res_partner_company_dict: if 'phone' in res_partner_company_dict:
res_partner_company_dict.pop('phone') res_partner_company_dict.pop('phone')
res_partner_company_dict['name'] = res_partner_data['partner_name']
res_partner_company_dict['display_name'] = res_partner_data['partner_name']
res_partner_company_dict['name'] = \
res_partner_data['partner_name']
res_partner_company_dict['display_name'] = \
res_partner_data['partner_name']
res_partner_company_dict['customer'] = False res_partner_company_dict['customer'] = False
res_partner_company_dict['is_company'] = True res_partner_company_dict['is_company'] = True
res_partner_company_dict['company_type'] = 'company' res_partner_company_dict['company_type'] = 'company'
@ -278,7 +283,7 @@ class MyFilter(parent_controller.WebsiteForm):
res_partner_dict['parent_id'] = id_record_res_company res_partner_dict['parent_id'] = id_record_res_company
id_record_res = self.insert_record(
self.insert_record(
request, request,
request.env['ir.model'].search( request.env['ir.model'].search(
[('model', '=', 'res.partner')]), [('model', '=', 'res.partner')]),
@ -312,7 +317,7 @@ class MyFilter(parent_controller.WebsiteForm):
print("RGPDR" + str(request_gdpdr)) print("RGPDR" + str(request_gdpdr))
# if request_gdpdr == True: # if request_gdpdr == True:
if request_gdpdr == True or send_mail == True:
if request_gdpdr is True or send_mail is True:
if id_record and model_name == "crm.lead": if id_record and model_name == "crm.lead":
crm_lead_obj = request.env['crm.lead'].sudo().search([ crm_lead_obj = request.env['crm.lead'].sudo().search([
('id', '=', id_record)] ('id', '=', id_record)]
@ -328,9 +333,8 @@ class MyFilter(parent_controller.WebsiteForm):
str(crm_lead_obj.create_date) str(crm_lead_obj.create_date)
print(email_data) print(email_data)
ency_email = base64.b64encode(email_data.encode()).decode(
"utf-8"
)
ency_email = base64.b64encode(email_data.encode())\
.decode("utf-8")
action_url = '%s/verify_email/?data=%s' % ( action_url = '%s/verify_email/?data=%s' % (
request.env['ir.config_parameter']. request.env['ir.config_parameter'].
sudo().get_param('web.base.url'), sudo().get_param('web.base.url'),
@ -339,7 +343,8 @@ class MyFilter(parent_controller.WebsiteForm):
if crm_lead_obj: if crm_lead_obj:
crm_lead_obj.email_link = action_url crm_lead_obj.email_link = action_url
request.env.ref( request.env.ref(
'website_contact_extend.verification_email_template'
'website_contact_extend.\
verification_email_template'
).sudo().send_mail(id_record) ).sudo().send_mail(id_record)
except IntegrityError: except IntegrityError:

0
website_contact_extend/models/__init__.py

2
website_contact_extend/models/res_partner.py

@ -25,12 +25,10 @@ class ResContacts(models.Model):
# s # s
@api.multi @api.multi
def write(self, vals): def write(self, vals):
print(vals)
return super(ResContacts, self).write(vals) return super(ResContacts, self).write(vals)
@api.model @api.model
def create(self, vals): def create(self, vals):
print(vals)
return super(ResContacts, self).create(vals) return super(ResContacts, self).create(vals)

23
website_contact_extend/static/src/js/contactus.js

@ -1,40 +1,39 @@
odoo.define('website_contact_extend.success_page', function (require) {
odoo.define('website_contact_extend.success_page', function(require) {
"use strict"; "use strict";
var ajax = require("web.ajax"); var ajax = require("web.ajax");
// function check_user_exists(){
// }
$(document).on('blur', '.input_email_from', function (ev) {
$(document).on('blur', '.input_email_from', function(ev) {
var email_from = $('.input_email_from').val(); var email_from = $('.input_email_from').val();
var company_name = $('.input_company').val(); var company_name = $('.input_company').val();
return ajax.jsonRpc('/check_user_exists', 'call', { return ajax.jsonRpc('/check_user_exists', 'call', {
email_from: email_from, email_from: email_from,
company_name: company_name, company_name: company_name,
}).then(function (res) {
}).then(function(res) {
var contactus_page = "/contactus-thank-you"; var contactus_page = "/contactus-thank-you";
if(res){
if (res) {
contactus_page = "/contact-us-form-review"; contactus_page = "/contact-us-form-review";
} }
$('form[action="/website_form/"]').attr('data-success_page',contactus_page);
var formaction_webform = 'form[action="/website_form/"]';
$(formaction_webform).attr('data-success_page', contactus_page);
}); });
}); });
$(document).on('blur', '.input_company', function (ev) {
$(document).on('blur', '.input_company', function(ev) {
var email_from = $('.input_email_from').val(); var email_from = $('.input_email_from').val();
var company_name = $('.input_company').val(); var company_name = $('.input_company').val();
return ajax.jsonRpc('/check_user_exists', 'call', { return ajax.jsonRpc('/check_user_exists', 'call', {
email_from: email_from, email_from: email_from,
company_name: company_name, company_name: company_name,
}).then(function (res) {
}).then(function(res) {
var contactus_page = "/contactus-thank-you"; var contactus_page = "/contactus-thank-you";
if(res){
if (res) {
contactus_page = "/contact-us-form-review"; contactus_page = "/contact-us-form-review";
} }
$('form[action="/website_form/"]').attr('data-success_page',contactus_page);
var formaction_webform = 'form[action="/website_form/"]';
$(formaction_webform).attr('data-success_page', contactus_page);
}); });
}); });
Loading…
Cancel
Save