mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
[REF] website_sale_signifyd: initial rename from connector_signifyd
This commit is contained in:
2
website_sale_signifyd/__init__.py
Normal file
2
website_sale_signifyd/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
from . import controllers
|
||||
from . import models
|
||||
24
website_sale_signifyd/__manifest__.py
Normal file
24
website_sale_signifyd/__manifest__.py
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
'name': 'Signifyd Connector',
|
||||
'author': 'Hibou Corp. <hello@hibou.io>',
|
||||
'version': '13.0.1.0.0',
|
||||
'category': 'Sale',
|
||||
'description': """
|
||||
Automate Order Fraud Detection with the Signifyd API.
|
||||
""",
|
||||
'website': 'https://hibou.io/',
|
||||
'depends': [
|
||||
'website_sale',
|
||||
],
|
||||
'data': [
|
||||
'security/ir.model.access.csv',
|
||||
'views/company_views.xml',
|
||||
'views/partner_views.xml',
|
||||
'views/sale_views.xml',
|
||||
'views/signifyd_views.xml',
|
||||
'views/stock_views.xml',
|
||||
'views/web_assets.xml',
|
||||
],
|
||||
'installable': True,
|
||||
'application': False,
|
||||
}
|
||||
2
website_sale_signifyd/controllers/__init__.py
Normal file
2
website_sale_signifyd/controllers/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
from . import main
|
||||
from . import signifyd
|
||||
21
website_sale_signifyd/controllers/main.py
Normal file
21
website_sale_signifyd/controllers/main.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from odoo.http import request, route
|
||||
from odoo.addons.website_sale.controllers.main import WebsiteSale
|
||||
|
||||
|
||||
class WebsiteSale(WebsiteSale):
|
||||
|
||||
@route(['/shop/confirmation'], type='http', auth="public", website=True, sitemap=False)
|
||||
def payment_confirmation(self, **post):
|
||||
res = super(WebsiteSale, self).payment_confirmation()
|
||||
order_session_id = request.session.session_token
|
||||
checkout_token = request.session.session_token
|
||||
browser_ip_address = request.httprequest.environ['REMOTE_ADDR']
|
||||
sale_order_id = request.session.get('sale_last_order_id')
|
||||
if sale_order_id:
|
||||
order = request.env['sale.order'].sudo().browse(sale_order_id)
|
||||
# Post completed order to Signifyd
|
||||
signifyd = request.env.company.signifyd_connector_id
|
||||
if signifyd:
|
||||
order.sudo().post_signifyd_case(order_session_id, checkout_token, browser_ip_address)
|
||||
|
||||
return res
|
||||
36
website_sale_signifyd/controllers/signifyd.py
Normal file
36
website_sale_signifyd/controllers/signifyd.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import json
|
||||
from odoo.http import Controller, request, route
|
||||
from odoo.http import Response
|
||||
|
||||
|
||||
class SignifydWebhooks(Controller):
|
||||
@route(['/cases/creation'], type='json', auth='public', methods=['POST'], csrf=False)
|
||||
def case_creation(self, *args, **post):
|
||||
data = json.loads(request.httprequest.data)
|
||||
vals = request.env['signifyd.connector'].process_post_values(data)
|
||||
# Update case with info
|
||||
case = request.env['signifyd.case'].sudo().search([('case_id', '=', vals['case_id'])])
|
||||
if case:
|
||||
case.sudo().update_case_info(vals)
|
||||
# Request guarantee for case if eligible
|
||||
try:
|
||||
case.request_guarantee()
|
||||
if case.guarantee_requested and not case.guarantee_eligible:
|
||||
# Only alert Signifyd to stop trying if we have at least tried once already
|
||||
return Response({'response': 'success'}, status=200, mimetype='application/json')
|
||||
except:
|
||||
# Signifyd API will try again up to 15 times if a non-2** code is returned
|
||||
return Response({'response': 'failed'}, status=500, mimetype='application/json')
|
||||
|
||||
@route(['/cases/update'], type='json', auth='public', methods=['POST'], csrf=False)
|
||||
def case_update(self, *args, **post):
|
||||
data = json.loads(request.httprequest.data)
|
||||
vals = request.env['signifyd.connector'].process_post_values(data)
|
||||
case = request.env['signifyd.case'].sudo().search([('case_id', '=', vals['case_id'])])
|
||||
if case:
|
||||
case.update_case_info(vals)
|
||||
|
||||
outcome = vals.get('guarantee_disposition')
|
||||
if case and outcome == 'DECLINED':
|
||||
for user in request.env.company.signifyd_connector_id.notify_user_ids:
|
||||
case.sudo().create_notification(user, outcome)
|
||||
6
website_sale_signifyd/models/__init__.py
Normal file
6
website_sale_signifyd/models/__init__.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from . import company
|
||||
from . import partner
|
||||
from . import sale_order
|
||||
from . import signifyd
|
||||
from . import signifyd_connector
|
||||
from . import stock
|
||||
7
website_sale_signifyd/models/company.py
Normal file
7
website_sale_signifyd/models/company.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class ResCompany(models.Model):
|
||||
_inherit = 'res.company'
|
||||
|
||||
signifyd_connector_id = fields.Many2one('signifyd.connector')
|
||||
19
website_sale_signifyd/models/partner.py
Normal file
19
website_sale_signifyd/models/partner.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class ResPartner(models.Model):
|
||||
_inherit = 'res.partner'
|
||||
|
||||
signifyd_case_ids = fields.One2many('signifyd.case', 'partner_id', string='Signifyd Cases')
|
||||
signifyd_case_count = fields.Integer(compute='_compute_signifyd_stats', string='Signifyd Cases')
|
||||
signifyd_average_score = fields.Float(compute='_compute_signifyd_stats', string='Signifyd Score')
|
||||
|
||||
def _compute_signifyd_stats(self):
|
||||
for record in self:
|
||||
cases = record.signifyd_case_ids
|
||||
if cases:
|
||||
record.signifyd_case_count = len(cases)
|
||||
record.signifyd_average_score = sum(cases.mapped('score')) / record.signifyd_case_count
|
||||
else:
|
||||
record.signifyd_case_count = 0
|
||||
record.signifyd_average_score = 0
|
||||
149
website_sale_signifyd/models/sale_order.py
Normal file
149
website_sale_signifyd/models/sale_order.py
Normal file
@@ -0,0 +1,149 @@
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class SaleOrder(models.Model):
|
||||
_inherit = 'sale.order'
|
||||
|
||||
signifyd_case_id = fields.Many2one('signifyd.case', readonly=1)
|
||||
singifyd_score = fields.Float(related='signifyd_case_id.score', readonly=1)
|
||||
signifyd_disposition_status = fields.Selection(related='signifyd_case_id.guarantee_disposition', tracking=True)
|
||||
|
||||
def action_view_signifyd_case(self):
|
||||
self.ensure_one()
|
||||
form_id = self.env.ref('gcl_signifyd_connector.signifyd_case_form_view').id
|
||||
context = {'create': False, 'delete': False, 'id': self.signifyd_case_id.id}
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'name': 'Signifyd Case',
|
||||
'view_mode': 'form',
|
||||
'views': [(form_id, 'form')],
|
||||
'res_model': 'signifyd.case',
|
||||
'res_id': self.signifyd_case_id.id,
|
||||
'context': context,
|
||||
}
|
||||
|
||||
def post_signifyd_case(self, order_session_id, checkout_token, browser_ip_address):
|
||||
# Session values for Signifyd post
|
||||
data = {
|
||||
'order_session_id': order_session_id,
|
||||
'checkout_token': checkout_token,
|
||||
'browser_ip_address': browser_ip_address,
|
||||
}
|
||||
sig_vals = self.prepare_signifyd_case_values(data)
|
||||
|
||||
case_res = self.env['signifyd.case'].post_case(sig_vals)
|
||||
|
||||
success_response = case_res.get('investigationId')
|
||||
if success_response:
|
||||
new_case = self.env['signifyd.case'].create({
|
||||
'order_id': self.id,
|
||||
'case_id': success_response,
|
||||
'name': success_response,
|
||||
})
|
||||
self.write({'signifyd_case_id': new_case.id})
|
||||
self.partner_id.write({
|
||||
'signifyd_case_ids': [(4, new_case.id)],
|
||||
})
|
||||
return new_case
|
||||
|
||||
@api.model
|
||||
def prepare_signifyd_case_values(self, data):
|
||||
order_session_id = data.get('order_session_id')
|
||||
checkout_token = data.get('checkout_token')
|
||||
browser_ip_address = data.get('browser_ip_address')
|
||||
|
||||
new_case_vals = {}
|
||||
|
||||
new_case_vals['purchase'] = {
|
||||
"orderSessionId": order_session_id,
|
||||
"orderId": self.id,
|
||||
"checkoutToken": checkout_token,
|
||||
"browserIpAddress": browser_ip_address,
|
||||
"currency": self.partner_id.currency_id.name,
|
||||
"orderChannel": "WEB",
|
||||
"totalPrice": self.amount_total,
|
||||
}
|
||||
|
||||
new_case_vals['purchase']['products'] = []
|
||||
for line in self.order_line:
|
||||
product = line.product_id
|
||||
vals = {
|
||||
"itemId": product.id,
|
||||
"itemName": product.name,
|
||||
"itemIsDigital": False,
|
||||
"itemCategory": product.categ_id.name,
|
||||
"itemUrl": product.website_url,
|
||||
"itemQuantity": line.product_uom_qty,
|
||||
"itemPrice": line.price_unit,
|
||||
"itemWeight": product.weight,
|
||||
}
|
||||
new_case_vals['purchase']['products'].append(vals)
|
||||
|
||||
new_case_vals['purchase']['shipments'] = []
|
||||
if self.carrier_id:
|
||||
vals = {
|
||||
"shipper": self.carrier_id.name,
|
||||
"shippingMethod": "ground",
|
||||
"shippingPrice": self.amount_delivery,
|
||||
}
|
||||
new_case_vals['purchase']['shipments'].append(vals)
|
||||
|
||||
new_case_vals['recipients'] = []
|
||||
recipients = [self.partner_invoice_id, self.partner_shipping_id]
|
||||
for partner in recipients:
|
||||
vals = {
|
||||
"fullName": partner.name,
|
||||
"confirmationEmail": partner.email,
|
||||
"confirmationPhone": partner.phone,
|
||||
"organization": partner.company_id.name,
|
||||
"deliveryAddress": {
|
||||
"streetAddress": partner.street,
|
||||
"unit": partner.street2,
|
||||
"city": partner.city,
|
||||
"provinceCode": partner.state_id.code,
|
||||
"postalCode": partner.zip,
|
||||
"countryCode": partner.country_id.code,
|
||||
}
|
||||
}
|
||||
new_case_vals['recipients'].append(vals)
|
||||
|
||||
new_case_vals['transactions'] = []
|
||||
# payment.transaction
|
||||
for tx in self.transaction_ids:
|
||||
tx_status_type = {
|
||||
'draft': 'FAILURE',
|
||||
'pending': 'PENDING',
|
||||
'authorized': 'SUCCESS',
|
||||
'done': 'SUCCESS',
|
||||
'cancel': 'FAILURE',
|
||||
'error': 'ERROR',
|
||||
}
|
||||
|
||||
tx_status = tx_status_type[tx.state]
|
||||
|
||||
vals = {
|
||||
"parentTransactionId": None,
|
||||
"transactionId": tx.id,
|
||||
"gateway": tx.acquirer_id.name,
|
||||
"paymentMethod": "CREDIT_CARD",
|
||||
"gatewayStatusCode": tx_status,
|
||||
"type": "AUTHORIZATION",
|
||||
"currency": self.partner_id.currency_id.name,
|
||||
"amount": tx.amount,
|
||||
"avsResponseCode": "Y",
|
||||
"cvvResponseCode": "N",
|
||||
"checkoutPaymentDetails": {
|
||||
"holderName": tx.partner_id.name,
|
||||
"billingAddress": {
|
||||
"streetAddress": tx.partner_id.street,
|
||||
"unit": tx.partner_id.street2,
|
||||
"city": tx.partner_id.city,
|
||||
"provinceCode": tx.partner_id.state_id.code,
|
||||
"postalCode": tx.partner_id.zip,
|
||||
"countryCode": tx.partner_id.country_id.code,
|
||||
}
|
||||
}
|
||||
}
|
||||
new_case_vals['transactions'].append(vals)
|
||||
|
||||
return new_case_vals
|
||||
163
website_sale_signifyd/models/signifyd.py
Normal file
163
website_sale_signifyd/models/signifyd.py
Normal file
@@ -0,0 +1,163 @@
|
||||
import requests
|
||||
import json
|
||||
from datetime import datetime as dt
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
class SignifydCase(models.Model):
|
||||
_name = 'signifyd.case'
|
||||
_description = 'Stores Signifyd case information on orders.'
|
||||
|
||||
order_id = fields.Many2one('sale.order')
|
||||
partner_id = fields.Many2one('res.partner')
|
||||
case_id = fields.Char(string='Case ID')
|
||||
uuid = fields.Char(string='Unique ID')
|
||||
status = fields.Selection([
|
||||
('OPEN', 'Open'),
|
||||
('DISMISSED', 'Dismissed'),
|
||||
], string='Case Status')
|
||||
|
||||
name = fields.Char(string='Headline')
|
||||
team_name = fields.Char(string='Team Name')
|
||||
team_id = fields.Char(string='Team ID')
|
||||
last_update = fields.Date('Last Update')
|
||||
|
||||
review_disposition = fields.Selection([
|
||||
('UNSET', 'Pending'),
|
||||
('FRAUD', 'Fraudulent'),
|
||||
('GOOD', 'Good'),
|
||||
], string='Review Status')
|
||||
|
||||
order_outcome = fields.Selection([
|
||||
('PENDING', 'pending'),
|
||||
('SUCCESSFUL', 'Successful'),
|
||||
])
|
||||
|
||||
guarantee_disposition = fields.Selection([
|
||||
('IN_REVIEW', 'Reviewing'),
|
||||
('PENDING', 'Pending'),
|
||||
('APPROVED', 'Approved'),
|
||||
('DECLINED', 'Declined'),
|
||||
('CANCELED', 'Canceled'),
|
||||
], string='Guarantee Status')
|
||||
disposition_reason = fields.Char('Disposition Reason')
|
||||
guarantee_eligible = fields.Boolean('Eligible for Guarantee')
|
||||
guarantee_requested = fields.Boolean('Requested Guarantee')
|
||||
score = fields.Float(string='Transaction Score')
|
||||
adjusted_score = fields.Float(string='Adjusted Score')
|
||||
signifyd_url = fields.Char('Signifyd.com', compute='_compute_signifyd_url')
|
||||
|
||||
@api.model
|
||||
def _compute_signifyd_url(self):
|
||||
for record in self:
|
||||
if record.case_id:
|
||||
self.signifyd_url = 'https://app.signifyd.com/cases/%s' % record.case_id
|
||||
else:
|
||||
self.signifyd_url = ''
|
||||
|
||||
def write(self, vals):
|
||||
res = super(SignifydCase, self).write(vals)
|
||||
disposition = vals.get('guarantee_disposition')
|
||||
if disposition:
|
||||
self.order_id.message_post(body=_('Signifyd Updated Record to %s' % vals['guarantee_disposition']),
|
||||
subtype='gcl_signifyd_connector.disposition_change')
|
||||
return res
|
||||
|
||||
@api.model
|
||||
def post_case(self, values):
|
||||
signifyd = self.env['signifyd.connector']
|
||||
headers = signifyd.get_headers()
|
||||
data = json.dumps(values, indent=4, sort_keys=True, default=str)
|
||||
|
||||
r = requests.post(
|
||||
signifyd.API_URL + '/cases',
|
||||
headers=headers,
|
||||
data=data,
|
||||
)
|
||||
return r.json()
|
||||
|
||||
@api.model
|
||||
def get_case(self):
|
||||
signifyd = self.env['signifyd.connector']
|
||||
headers = signifyd.get_headers()
|
||||
r = requests.get(
|
||||
signifyd.API_URL + '/cases/' + str(self.case_id),
|
||||
headers=headers
|
||||
)
|
||||
return r.json()
|
||||
|
||||
@api.model
|
||||
def request_guarantee(self, *args):
|
||||
signifyd = self.env['signifyd.connector']
|
||||
headers = signifyd.get_headers()
|
||||
values = json.dumps({"caseId": self.case_id})
|
||||
r = requests.post(
|
||||
signifyd.API_URL + '/async/guarantees',
|
||||
headers=headers,
|
||||
data=values,
|
||||
)
|
||||
|
||||
if 200 <= r.status_code < 300:
|
||||
self.write({'guarantee_requested': True})
|
||||
else:
|
||||
msg = r.content.decode("utf-8")
|
||||
raise UserError(_(msg))
|
||||
|
||||
def action_request_guarantee(self):
|
||||
for record in self:
|
||||
record.request_guarantee()
|
||||
|
||||
def action_force_update_case(self):
|
||||
for record in self:
|
||||
record.update_case_info()
|
||||
|
||||
@api.model
|
||||
def update_case_info(self, vals=None):
|
||||
if not vals:
|
||||
case = self.get_case()
|
||||
case_id = case.get('caseId')
|
||||
team_id = case.get('teamId')
|
||||
team_name = case.get('teamName')
|
||||
uuid = case.get('uuid')
|
||||
status = case.get('status')
|
||||
review_disposition = case.get('reviewDisposition')
|
||||
order_outcome = case.get('orderOutcome')
|
||||
guarantee_disposition = case.get('guaranteeDisposition')
|
||||
adjusted_score = case.get('adjustedScore')
|
||||
score = case.get('score')
|
||||
guarantee_eligible = case.get('guaranteeEligible')
|
||||
# order_id = case.get('orderId')
|
||||
|
||||
vals = {
|
||||
'case_id': case_id,
|
||||
'team_id': team_id,
|
||||
'team_name': team_name,
|
||||
'uuid': uuid,
|
||||
'status': status,
|
||||
'review_disposition': review_disposition,
|
||||
'order_outcome': order_outcome,
|
||||
'adjusted_score': adjusted_score,
|
||||
'guarantee_disposition': guarantee_disposition,
|
||||
'score': score,
|
||||
'guarantee_eligible': guarantee_eligible,
|
||||
'last_update': dt.now(),
|
||||
}
|
||||
|
||||
outcome = vals.get('guarantee_disposition')
|
||||
if outcome == 'DECLINED':
|
||||
for user in self.env.company.signifyd_connector_id.notify_user_ids:
|
||||
self.create_notification(user, outcome)
|
||||
|
||||
self.write(vals)
|
||||
|
||||
def create_notification(self, user, outcome):
|
||||
self.ensure_one()
|
||||
vals = {
|
||||
'summary': 'Signifyd Case %s %s' % (self.case_id, outcome),
|
||||
'activity_type_id': self.env.ref('mail.mail_activity_data_todo').id,
|
||||
'user_id': user.id,
|
||||
'res_id': self.order_id.id,
|
||||
'res_model_id': self.env['ir.model']._get('sale.order').id,
|
||||
}
|
||||
self.env['mail.activity'].create(vals)
|
||||
134
website_sale_signifyd/models/signifyd_connector.py
Normal file
134
website_sale_signifyd/models/signifyd_connector.py
Normal file
@@ -0,0 +1,134 @@
|
||||
import requests
|
||||
from datetime import datetime as dt
|
||||
from base64 import b64encode
|
||||
import json
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class SignifydConnector(models.Model):
|
||||
_name = 'signifyd.connector'
|
||||
_description = 'Interact with Signifyd API'
|
||||
|
||||
name = fields.Char(string='Connector Name')
|
||||
test_mode = fields.Boolean(string='Test Mode')
|
||||
user_key = fields.Char(string='Username')
|
||||
secret_key = fields.Char(string='API Key')
|
||||
user_key_test = fields.Char(string='TEST Username')
|
||||
secret_key_test = fields.Char(string='TEST API Key')
|
||||
open_so_cap = fields.Integer(string='Cap requests at:')
|
||||
webhooks_registered = fields.Boolean(string='Successfully Registered Webhooks')
|
||||
notify_user_ids = fields.Many2many('res.users', string='Receive event notifications')
|
||||
|
||||
API_URL = 'https://api.signifyd.com/v2'
|
||||
|
||||
def get_headers(self):
|
||||
# Check for prod or test mode
|
||||
signifyd = self.env.company.signifyd_connector_id
|
||||
if not signifyd:
|
||||
return False
|
||||
|
||||
if signifyd.test_mode:
|
||||
api_key = signifyd.secret_key_test
|
||||
else:
|
||||
api_key = signifyd.secret_key
|
||||
|
||||
b64_auth_key = b64encode(api_key.encode('utf-8'))
|
||||
|
||||
headers = {
|
||||
'Authorization': 'Basic ' + str(b64_auth_key, 'utf-8').replace('=', ''),
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
|
||||
return headers
|
||||
|
||||
def register_webhooks(self):
|
||||
headers = self.get_headers()
|
||||
base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
|
||||
values = {
|
||||
"webhooks": [
|
||||
{
|
||||
"event": "CASE_CREATION",
|
||||
"url": base_url + "/cases/creation"
|
||||
},
|
||||
{
|
||||
"event": "CASE_RESCORE",
|
||||
"url": base_url + "/cases/update"
|
||||
},
|
||||
{
|
||||
"event": "CASE_REVIEW",
|
||||
"url": base_url + "/cases/update"
|
||||
},
|
||||
{
|
||||
"event": "GUARANTEE_COMPLETION",
|
||||
"url": base_url + "/cases/update"
|
||||
},
|
||||
]
|
||||
}
|
||||
data = json.dumps(values, indent=4)
|
||||
r = requests.post(
|
||||
self.API_URL + '/teams/webhooks',
|
||||
headers=headers,
|
||||
data=data,
|
||||
)
|
||||
# r.raise_for_status()
|
||||
return r
|
||||
|
||||
def action_register_webhooks(self):
|
||||
|
||||
notification = {
|
||||
'type': 'ir.actions.client',
|
||||
'tag': 'display_notification',
|
||||
'params': {
|
||||
'title': ('Signifyd Connector'),
|
||||
'sticky': True,
|
||||
},
|
||||
}
|
||||
|
||||
res = self.register_webhooks()
|
||||
|
||||
if 200 <= res.status_code < 300:
|
||||
notification['params']['type'] = 'success'
|
||||
notification['params']['message'] = 'Successfully registered webhooks with Signifyd.'
|
||||
self.webhooks_registered = True
|
||||
return notification
|
||||
|
||||
else:
|
||||
notification['params']['type'] = 'danger'
|
||||
notification['params']['message'] = res.content.decode('utf-8')
|
||||
return notification
|
||||
|
||||
def process_post_values(self, post):
|
||||
# Construct dict from request data for endpoints
|
||||
guarantee_eligible = post.get('guaranteeEligible')
|
||||
uuid = post.get('uuid')
|
||||
case_id = post.get('caseId')
|
||||
team_name = post.get('teamName')
|
||||
team_id = post.get('teamId')
|
||||
review_disposition = post.get('reviewDisposition')
|
||||
guarantee_disposition = post.get('guaranteeDisposition')
|
||||
order_outcome = post.get('orderOutcome')
|
||||
status = post.get('status')
|
||||
score = post.get('score')
|
||||
disposition_reason = post.get('dispositionReason')
|
||||
disposition = post.get('disposition')
|
||||
last_update = str(dt.now())
|
||||
|
||||
values = {}
|
||||
|
||||
# Validate that the order and case match the request
|
||||
values.update({'guarantee_eligible': guarantee_eligible}) if guarantee_eligible else ''
|
||||
values.update({'uuid': uuid}) if uuid else ''
|
||||
values.update({'team_name': team_name}) if team_name else ''
|
||||
values.update({'team_id': team_id}) if team_id else ''
|
||||
values.update({'review_disposition': review_disposition}) if review_disposition else ''
|
||||
values.update({'guarantee_disposition': guarantee_disposition}) if guarantee_disposition else ''
|
||||
values.update({'order_outcome': order_outcome}) if order_outcome else ''
|
||||
values.update({'status': status}) if status else ''
|
||||
values.update({'score': score}) if score else ''
|
||||
values.update({'case_id': case_id}) if case_id else ''
|
||||
values.update({'disposition_reason': disposition_reason}) if disposition_reason else ''
|
||||
values.update({'disposition': disposition}) if disposition else ''
|
||||
values.update({'last_update': last_update})
|
||||
|
||||
return values
|
||||
22
website_sale_signifyd/models/stock.py
Normal file
22
website_sale_signifyd/models/stock.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class StockPicking(models.Model):
|
||||
_inherit = 'stock.picking'
|
||||
|
||||
singifyd_case_id = fields.Many2one(related='sale_id.signifyd_case_id')
|
||||
signifyd_hold = fields.Selection(related='sale_id.signifyd_disposition_status')
|
||||
|
||||
def action_view_signifyd_case(self):
|
||||
self.ensure_one()
|
||||
form_id = self.env.ref('gcl_signifyd_connector.signifyd_case_form_view').id
|
||||
context = {'create': False, 'delete': False, 'id': self.sale_id.signifyd_case_id.id}
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'name': 'Signifyd Case',
|
||||
'view_mode': 'form',
|
||||
'views': [(form_id, 'form')],
|
||||
'res_model': 'signifyd.case',
|
||||
'res_id': self.singifyd_case_id.id,
|
||||
'context': context,
|
||||
}
|
||||
9
website_sale_signifyd/security/ir.model.access.csv
Normal file
9
website_sale_signifyd/security/ir.model.access.csv
Normal file
@@ -0,0 +1,9 @@
|
||||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||
manage_signifyd_connector,manage_signifyd_connector,model_signifyd_connector,base.group_erp_manager,1,1,1,1
|
||||
access_signifyd_connector,access_signifyd_connector,model_signifyd_connector,base.group_user,1,1,1,0
|
||||
public_signifyd_connector,public_signifyd_connector,model_signifyd_connector,base.group_public,1,1,1,0
|
||||
portal_signifyd_connector,portal_signifyd_connector,model_signifyd_connector,base.group_portal,1,1,1,0
|
||||
manage_signifyd_case,manage_signifyd_case,model_signifyd_case,base.group_erp_manager,1,1,1,1
|
||||
access_signifyd_case,access_signifyd_case,model_signifyd_case,base.group_user,1,1,1,0
|
||||
public_signifyd_case,public_signifyd_case,model_signifyd_case,base.group_public,1,1,1,0
|
||||
portal_signifyd_case,portal_signifyd_case,model_signifyd_case,base.group_portal,1,1,1,0
|
||||
|
23
website_sale_signifyd/views/company_views.xml
Normal file
23
website_sale_signifyd/views/company_views.xml
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
|
||||
<record id="res_company_form_view_inherit" model="ir.ui.view">
|
||||
<field name="name">res.company.form.inherit</field>
|
||||
<field name="model">res.company</field>
|
||||
<field name="inherit_id" ref="base.view_company_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//notebook//page[last()]" position="after">
|
||||
<page name="signifyd" string="Signifyd">
|
||||
<div class="oe_title">
|
||||
<h3>
|
||||
Connector
|
||||
</h3>
|
||||
</div>
|
||||
<label for="signifyd_connector_id" string="Settings"/>
|
||||
<field name="signifyd_connector_id"/>
|
||||
</page>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
43
website_sale_signifyd/views/partner_views.xml
Normal file
43
website_sale_signifyd/views/partner_views.xml
Normal file
@@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
|
||||
<record id="partner_view_form_view_inherit" model="ir.ui.view">
|
||||
<field name="name">res.partner.form.inherit</field>
|
||||
<field name="model">res.partner</field>
|
||||
<field name="inherit_id" ref="base.view_partner_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//div[@name='button_box']" position="inside">
|
||||
<field name="signifyd_case_count" invisible="1"/>
|
||||
<field name="signifyd_average_score" invisible="1"/>
|
||||
<button class="oe_stat_button text-success" icon="fa-flag-checkered"
|
||||
attrs="{'invisible': [('signifyd_average_score', '<=', 600)]}">
|
||||
<field string="Signifyd Score" name="signifyd_average_score" widget="statinfo"/>
|
||||
</button>
|
||||
<button class="oe_stat_button text-warning" icon="fa-flag"
|
||||
attrs="{'invisible': [ '|', ('signifyd_average_score', '>', 600), ('signifyd_average_score', '<', 300)]}">
|
||||
<field string="Signifyd Score" name="signifyd_average_score" widget="statinfo"/>
|
||||
</button>
|
||||
<button class="oe_stat_button text-danger" icon="fa-flag"
|
||||
attrs="{'invisible': [('signifyd_average_score', '>', 300)]}">
|
||||
<field string="Signifyd Score" name="signifyd_average_score" widget="statinfo"/>
|
||||
</button>
|
||||
</xpath>
|
||||
<!-- Page for Signifyd info -->
|
||||
<xpath expr="//notebook//page[last()]" position="after">
|
||||
<page string="Signifyd Cases">
|
||||
<field name="signifyd_case_ids" widget="section_and_note_one2many" mode="tree">
|
||||
<tree create="false" delete="false">
|
||||
<field name="create_date" readonly="1"/>
|
||||
<field name="name" string="ID" readonly="1"/>
|
||||
<field name="order_id" readonly="1"/>
|
||||
<field name="score" readonly="1"/>
|
||||
<field name="guarantee_disposition" readonly="1"/>
|
||||
<field name="last_update" string="Last Update" readonly="1"/>
|
||||
</tree>
|
||||
</field>
|
||||
</page>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
56
website_sale_signifyd/views/sale_views.xml
Normal file
56
website_sale_signifyd/views/sale_views.xml
Normal file
@@ -0,0 +1,56 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
|
||||
<record id="sale_order_form_view_inherit" model="ir.ui.view">
|
||||
<field name="name">sale.order.form.inherit</field>
|
||||
<field name="model">sale.order</field>
|
||||
<field name="inherit_id" ref="sale.view_order_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='state']" position="after">
|
||||
<field name="singifyd_score" invisible="1"/>
|
||||
</xpath>
|
||||
<xpath expr="//div[@name='button_box']" position="inside">
|
||||
<field name="signifyd_case_id" invisible="1"/>
|
||||
<button name="action_view_signifyd_case" type="object" class="oe_stat_button text-success"
|
||||
icon="fa-flag-checkered"
|
||||
attrs="{'invisible': [ '|', ('singifyd_score', '<=', 600), ('signifyd_case_id', '=', False)]}">
|
||||
<field string="Signifyd Score" name="singifyd_score" widget="statinfo"/>
|
||||
</button>
|
||||
<button name="action_view_signifyd_case" type="object" class="oe_stat_button text-warning"
|
||||
icon="fa-flag"
|
||||
attrs="{'invisible': [ '|', '|', ('singifyd_score', '>', 600), ('singifyd_score', '<=', 300), ('signifyd_case_id', '=', False)]}">
|
||||
<field string="Signifyd Score" name="singifyd_score" widget="statinfo"/>
|
||||
</button>
|
||||
<button name="action_view_signifyd_case" type="object" class="oe_stat_button text-danger" icon="fa-flag"
|
||||
attrs="{'invisible': [ '|', ('singifyd_score', '>', 300), ('signifyd_case_id', '=', False)]}">
|
||||
<field string="Signifyd Score" name="singifyd_score" widget="statinfo"/>
|
||||
</button>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='payment_term_id']" position="after">
|
||||
<field name="signifyd_case_id" attrs="{'invisible': [('signifyd_case_id', '=', False)]}"/>
|
||||
<field name="signifyd_disposition_status" string="Signifyd Status"
|
||||
attrs="{'invisible': [('signifyd_case_id', '=', False)]}"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="sale_view_order_tree_inherit" model="ir.ui.view">
|
||||
<field name="name">sale.order.tree.inherit</field>
|
||||
<field name="model">sale.order</field>
|
||||
<field name="inherit_id" ref="sale.view_order_tree"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='invoice_status']" position="after">
|
||||
<field name="signifyd_disposition_status"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="disposition_change" model="mail.message.subtype">
|
||||
<field name="name">Signifyd Updated</field>
|
||||
<field name="res_model">sale.order</field>
|
||||
<field name="default" eval="True"/>
|
||||
<field name="description">Signifyd Status Updated</field>
|
||||
<field name="relation_field">signifyd_case_id.guarantee_disposition</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
128
website_sale_signifyd/views/signifyd_views.xml
Normal file
128
website_sale_signifyd/views/signifyd_views.xml
Normal file
@@ -0,0 +1,128 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
|
||||
<record id="signifyd_case_form_view" model="ir.ui.view">
|
||||
<field name="name">signifyd.form.view</field>
|
||||
<field name="model">signifyd.case</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Signifyd Case" class="o_signifyd_case">
|
||||
<header>
|
||||
<button name="action_force_update_case" type="object"
|
||||
string="Force Update" class="oe_highlight"/>
|
||||
</header>
|
||||
<sheet>
|
||||
<field name="score" invisible="1"/>
|
||||
<div class="oe_button_box" name="button_box">
|
||||
<field name="score" invisible="1"/>
|
||||
<button class="oe_stat_button text-success" icon="fa-flag-checkered"
|
||||
attrs="{'invisible': [('score', '<=', 600)]}">
|
||||
<field string="Score" name="score" widget="statinfo"/>
|
||||
</button>
|
||||
<button class="oe_stat_button text-warning" icon="fa-flag"
|
||||
attrs="{'invisible': [ '|', ('score', '>', 600), ('score', '<', 300)]}">
|
||||
<field string="Score" name="score" widget="statinfo"/>
|
||||
</button>
|
||||
<button class="oe_stat_button text-danger" icon="fa-flag"
|
||||
attrs="{'invisible': [('score', '>', 300)]}">
|
||||
<field string="Score" name="score" widget="statinfo"/>
|
||||
</button>
|
||||
<button class="oe_stat_button text-success"
|
||||
icon="fa-share-square-o"
|
||||
type="object"
|
||||
name="action_request_guarantee"
|
||||
string="Request Guarantee"
|
||||
attrs="{'invisible': [ '|', ('guarantee_eligible', '=', False), ('guarantee_requested', '=', True)]}">
|
||||
|
||||
</button>
|
||||
</div>
|
||||
<div class="oe_title">
|
||||
<h1>
|
||||
<field name="name" readonly="1"/>
|
||||
</h1>
|
||||
<field name="signifyd_url" widget="url"/>
|
||||
</div>
|
||||
|
||||
<group>
|
||||
<group>
|
||||
<field name="last_update"/>
|
||||
<field name="uuid"/>
|
||||
<field name="case_id"/>
|
||||
<field name="status"/>
|
||||
<field name="order_outcome"/>
|
||||
<field name="review_disposition"/>
|
||||
<field name="guarantee_eligible"/>
|
||||
<field name="guarantee_requested"/>
|
||||
<field name="guarantee_disposition"/>
|
||||
<field name="disposition_reason"/>
|
||||
</group>
|
||||
|
||||
</group>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
<record id="action_signifyd_case_form" model="ir.actions.act_window">
|
||||
<field name="name">Signifyd Case Information</field>
|
||||
<field name="res_model">signifyd.case</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="view_id" ref="gcl_signifyd_connector.signifyd_case_form_view"/>
|
||||
</record>
|
||||
|
||||
<record id="signifyd_connector_form_view" model="ir.ui.view">
|
||||
<field name="name">signifyd.form.view</field>
|
||||
<field name="model">signifyd.connector</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Signifyd Connector" class="o_signifyd_connector">
|
||||
<header>
|
||||
<button name="action_register_webhooks" type="object"
|
||||
string="Register Webhooks" class="oe_highlight"
|
||||
attrs="{'invisible': [('webhooks_registered', '=', True)]}"/>
|
||||
</header>
|
||||
<sheet>
|
||||
|
||||
<div name="status_box">
|
||||
<field name="webhooks_registered" invisible="1"/>
|
||||
<div class="text-success float-right"
|
||||
attrs="{'invisible': [('webhooks_registered', '=', False)]}">
|
||||
<i class="fa fa-check-square"></i>
|
||||
<strong>
|
||||
Webhooks Active
|
||||
</strong>
|
||||
</div>
|
||||
<div class="text-danger float-right"
|
||||
attrs="{'invisible': [('webhooks_registered', '=', True)]}">
|
||||
<i class="fa fa-square"></i>
|
||||
<strong>
|
||||
Webhooks Inactive
|
||||
</strong>
|
||||
</div>
|
||||
</div>
|
||||
<div class="oe_title">
|
||||
<label for="test_mode"/>
|
||||
<field name="test_mode"/>
|
||||
<h1>
|
||||
<field name="name"/>
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<group>
|
||||
<group>
|
||||
<field name="user_key" attrs="{'invisible': [('test_mode', '=', True)]}"/>
|
||||
<field name="secret_key" attrs="{'invisible': [('test_mode', '=', True)]}"/>
|
||||
<field name="user_key_test" attrs="{'invisible': [('test_mode', '!=', True)]}"/>
|
||||
<field name="secret_key_test" attrs="{'invisible': [('test_mode', '!=', True)]}"/>
|
||||
<p class="text-muted">
|
||||
Optional: Add users to be notified if a sale order is declined by Signifyd.
|
||||
</p>
|
||||
<field name="notify_user_ids" widget="many2many_tags"/>
|
||||
</group>
|
||||
|
||||
</group>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
22
website_sale_signifyd/views/stock_views.xml
Normal file
22
website_sale_signifyd/views/stock_views.xml
Normal file
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
|
||||
<record id="stock_picking_form_inherit" model="ir.ui.view">
|
||||
<field name="name">stock.picking.form.view.inherit</field>
|
||||
<field name="model">stock.picking</field>
|
||||
<field name="inherit_id" ref="stock.view_picking_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//div[@name='button_box']" position="inside">
|
||||
<field name="signifyd_hold" invisible="1"/>
|
||||
<field name="singifyd_case_id" invisible="1"/>
|
||||
<button name="action_view_signifyd_case" string="On Hold" type="object" class="oe_stat_button text-danger"
|
||||
icon="fa-hand-stop-o" attrs="{'invisible': [ '|', ('signifyd_hold', '=', 'APPROVED'), ('singifyd_case_id', '=', False)]}"/>
|
||||
|
||||
<button name="action_view_signifyd_case" string="Approved" type="object" class="oe_stat_button text-success"
|
||||
icon="fa-thumbs-o-up" attrs="{'invisible': [ '|', ('signifyd_hold', '!=', 'APPROVED'), ('singifyd_case_id', '=', False)]}"/>
|
||||
</xpath>
|
||||
</field>
|
||||
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
11
website_sale_signifyd/views/web_assets.xml
Normal file
11
website_sale_signifyd/views/web_assets.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
|
||||
<template id="sig_web_assets_frontend" inherit_id="website.assets_frontend">
|
||||
<xpath expr="//script[last()]" position="after">
|
||||
<script defer="1" type="text/javascript" id="sig-api" t-att-data-order-session-id="request.session.session_token"
|
||||
src="https://cdn-scripts.signifyd.com/api/script-tag.js"></script>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user