[REF] website_(quote/sale), sale: move access_token in sale
Access token field is moved directly in sale module. Indeed future commits will improve customer portal and access tokens will be used in other module than website_quote. This commit already moves the field. Moreover some strange code in website_sale already uses access_token even if it does not exist in that module. Moving the field solves that issue. Finally so_token defined in stripe is renamed to access_token to have the same naming through all addons.
This commit is contained in:
@@ -42,7 +42,7 @@ odoo.define('payment_stripe.stripe', function(require) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var so_token = $("input[name='token']").val();
|
||||
var access_token = $("input[name='token']").val();
|
||||
var so_id = $("input[name='return_url']").val().match(/quote\/([0-9]+)/) || undefined;
|
||||
if (so_id) {
|
||||
so_id = parseInt(so_id[1]);
|
||||
@@ -65,7 +65,7 @@ odoo.define('payment_stripe.stripe', function(require) {
|
||||
} else {
|
||||
ajax.jsonRpc('/shop/payment/transaction/' + acquirer_id, 'call', {
|
||||
so_id: so_id,
|
||||
so_token: so_token
|
||||
access_token: access_token
|
||||
}, {'async': false}).then(function (data) {
|
||||
$form.html(data);
|
||||
handler.open({
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import uuid
|
||||
|
||||
from itertools import groupby
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
@@ -88,6 +90,9 @@ class SaleOrder(models.Model):
|
||||
return '<p class=''oe_view_nocontent_create''">%s</p>' % (help)
|
||||
return super(SaleOrder, self).get_empty_list_help(help)
|
||||
|
||||
def _get_default_access_token(self):
|
||||
return str(uuid.uuid4())
|
||||
|
||||
@api.model
|
||||
def _default_note(self):
|
||||
return self.env.user.company_id.sale_note
|
||||
@@ -110,6 +115,9 @@ class SaleOrder(models.Model):
|
||||
name = fields.Char(string='Order Reference', required=True, copy=False, readonly=True, states={'draft': [('readonly', False)]}, index=True, default=lambda self: _('New'))
|
||||
origin = fields.Char(string='Source Document', help="Reference of the document that generated this sales order request.")
|
||||
client_order_ref = fields.Char(string='Customer Reference', copy=False)
|
||||
access_token = fields.Char(
|
||||
'Security Token', copy=False,
|
||||
default=_get_default_access_token)
|
||||
|
||||
state = fields.Selection([
|
||||
('draft', 'Quotation'),
|
||||
@@ -279,6 +287,20 @@ class SaleOrder(models.Model):
|
||||
default['order_line'] = [(0, 0, line.copy_data()[0]) for line in self.order_line.filtered(lambda l: not l.is_downpayment)]
|
||||
return super(SaleOrder, self).copy_data(default)
|
||||
|
||||
@api.model_cr_context
|
||||
def _init_column(self, column_name):
|
||||
""" Initialize the value of the given column for existing rows.
|
||||
Overridden here because we skip generating unique access tokens
|
||||
for potentially tons of existing sale orders, should they be needed,
|
||||
they will be generated on the fly.
|
||||
"""
|
||||
if column_name != 'access_token':
|
||||
super(SaleOrder, self)._init_column(column_name)
|
||||
|
||||
def _generate_access_token(self):
|
||||
for order in self:
|
||||
order.access_token = self._get_default_access_token()
|
||||
|
||||
@api.multi
|
||||
def _prepare_invoice(self):
|
||||
"""
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import uuid
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
@@ -52,9 +51,6 @@ class SaleOrder(models.Model):
|
||||
if so.state not in ['sale', 'done']:
|
||||
so.website_url = '/quote/%s' % (so.id)
|
||||
|
||||
access_token = fields.Char(
|
||||
'Security Token', copy=False, default=lambda self: str(uuid.uuid4()),
|
||||
required=True)
|
||||
template_id = fields.Many2one(
|
||||
'sale.quote.template', 'Quotation Template',
|
||||
readonly=True,
|
||||
|
||||
@@ -805,9 +805,9 @@ class WebsiteSale(http.Controller):
|
||||
|
||||
# In case the route is called directly from the JS (as done in Stripe payment method)
|
||||
so_id = kwargs.get('so_id')
|
||||
so_token = kwargs.get('so_token')
|
||||
if so_id and so_token:
|
||||
order = request.env['sale.order'].sudo().search([('id', '=', so_id), ('access_token', '=', so_token)])
|
||||
access_token = kwargs.get('access_token')
|
||||
if so_id and access_token:
|
||||
order = request.env['sale.order'].sudo().search([('id', '=', so_id), ('access_token', '=', access_token)])
|
||||
elif so_id:
|
||||
order = request.env['sale.order'].search([('id', '=', so_id)])
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user