19.0 vanilla

This commit is contained in:
Ernad Husremovic 2026-03-09 09:29:53 +01:00
parent 6e54c1af6c
commit 3ca647e428
1087 changed files with 132065 additions and 108499 deletions

View file

@ -2,4 +2,3 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import pos_payment_method
from . import pos_session

View file

@ -1,14 +1,11 @@
# coding: utf-8
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import logging
import requests
import werkzeug
from odoo import fields, models, api, _
from odoo.exceptions import ValidationError, UserError, AccessError
_logger = logging.getLogger(__name__)
TIMEOUT = 10
class PosPaymentMethod(models.Model):
_inherit = 'pos.payment.method'
@ -19,6 +16,12 @@ class PosPaymentMethod(models.Model):
# Stripe
stripe_serial_number = fields.Char(help='[Serial number of the stripe terminal], for example: WSC513105011295', copy=False)
@api.model
def _load_pos_data_fields(self, config):
params = super()._load_pos_data_fields(config)
params += ['stripe_serial_number']
return params
@api.constrains('stripe_serial_number')
def _check_stripe_serial_number(self):
for payment_method in self:
@ -28,8 +31,8 @@ class PosPaymentMethod(models.Model):
('stripe_serial_number', '=', payment_method.stripe_serial_number)],
limit=1)
if existing_payment_method:
raise ValidationError(_('Terminal %s is already used on payment method %s.',\
payment_method.stripe_serial_number, existing_payment_method.display_name))
raise ValidationError(_('Terminal %(terminal)s is already used on payment method %(payment_method)s.',
terminal=payment_method.stripe_serial_number, payment_method=existing_payment_method.display_name))
def _get_stripe_payment_provider(self):
stripe_payment_provider = self.env['payment.provider'].search([
@ -42,29 +45,12 @@ class PosPaymentMethod(models.Model):
return stripe_payment_provider
@api.model
def _get_stripe_secret_key(self):
stripe_secret_key = self._get_stripe_payment_provider().stripe_secret_key
if not stripe_secret_key:
raise ValidationError(_('Complete the Stripe onboarding for company %s.', self.env.company.name))
return stripe_secret_key
@api.model
def stripe_connection_token(self):
if not self.env.user.has_group('point_of_sale.group_pos_user'):
raise AccessError(_("Do not have access to fetch token from Stripe"))
endpoint = 'https://api.stripe.com/v1/terminal/connection_tokens'
try:
resp = requests.post(endpoint, auth=(self.sudo()._get_stripe_secret_key(), ''), timeout=TIMEOUT)
except requests.exceptions.RequestException:
_logger.exception("Failed to call stripe_connection_token endpoint")
raise UserError(_("There are some issues between us and Stripe, try again later."))
return resp.json()
return self.sudo()._get_stripe_payment_provider()._send_api_request('POST', 'terminal/connection_tokens')
def _stripe_calculate_amount(self, amount):
currency = self.journal_id.currency_id or self.company_id.currency_id
@ -76,7 +62,6 @@ class PosPaymentMethod(models.Model):
# For Terminal payments, the 'payment_method_types' parameter must include
# at least 'card_present' and the 'capture_method' must be set to 'manual'.
endpoint = 'https://api.stripe.com/v1/payment_intents'
currency = self.journal_id.currency_id or self.company_id.currency_id
params = [
@ -93,17 +78,7 @@ class PosPaymentMethod(models.Model):
elif currency.name == 'CAD' and self.company_id.country_code == 'CA':
params.append(("payment_method_types[]", "interac_present"))
try:
data = werkzeug.urls.url_encode(params)
resp = requests.post(endpoint, data=data, auth=(self.sudo()._get_stripe_secret_key(), ''), timeout=TIMEOUT)
resp = resp.json()
redacted_resp = {k: '<redacted in odoo logs>' if k == 'client_secret' else v for k, v in resp.items()}
_logger.info("Stripe payment intent response: %s", redacted_resp)
except requests.exceptions.RequestException:
_logger.exception("Failed to call stripe_payment_intent endpoint")
raise UserError(_("There are some issues between us and Stripe, try again later."))
return resp
return self.sudo()._get_stripe_payment_provider()._send_api_request('POST', 'payment_intents', data=params)
@api.model
def stripe_capture_payment(self, paymentIntentId, amount=None):
@ -121,11 +96,13 @@ class PosPaymentMethod(models.Model):
data = None
if amount is not None:
# No rounding values stored in a model method
rounding = self.env.context.get('stripe_currency_rounding', 0.01)
data = {
"amount_to_capture": self._stripe_calculate_amount(amount),
"amount_to_capture": round(amount / rounding),
}
return self.sudo()._get_stripe_payment_provider()._stripe_make_request(endpoint, data)
return self.sudo()._get_stripe_payment_provider()._send_api_request('POST', endpoint, data=data)
def action_stripe_key(self):
res_id = self._get_stripe_payment_provider().id

View file

@ -1,13 +0,0 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models
class PosSession(models.Model):
_inherit = 'pos.session'
def _loader_params_pos_payment_method(self):
result = super()._loader_params_pos_payment_method()
result['search_params']['fields'].append('stripe_serial_number')
return result