parameters: (
          self, payment_option_id, reference_prefix, amount, currency_id, partner_id, flow,
          tokenization_requested, landing_route, is_validation=False, invoice_id=None,
          custom_create_values=None, **kwargs
      )
return_statement: return tx_sudo
docstring: Create a draft transaction based on the payment context and return it.
  
          :param int payment_option_id: The payment option handling the transaction, as a
                                        `payment.acquirer` id or a `payment.token` id
          :param str reference_prefix: The custom prefix to compute the full reference
          :param float|None amount: The amount to pay in the given currency.
                                    None if in a payment method validation operation
          :param int|None currency_id: The currency of the transaction, as a `res.currency` id.
                                       None if in a payment method validation operation
          :param int partner_id: The partner making the payment, as a `res.partner` id
          :param str flow: The online payment flow of the transaction: 'redirect', 'direct' or 'token'
          :param bool tokenization_requested: Whether the user requested that a token is created
          :param str landing_route: The route the user is redirected to after the transaction
          :param bool is_validation: Whether the operation is a validation
          :param int invoice_id: The account move for which a payment id made, as an `account.move` id
          :param dict custom_create_values: Additional create values overwriting the default ones
          :param dict kwargs: Locally unused data passed to `_is_tokenization_required` and
                              `_compute_reference`
          :return: The sudoed transaction that was created
          :rtype: recordset of `payment.transaction`
          :raise: UserError if the flow is invalid
docstring_summary: Create a draft transaction based on the payment context and return it.
docstring_tokens: Create a draft transaction based on the payment context and return it .
function: def _create_transaction(
          self, payment_option_id, reference_prefix, amount, currency_id, partner_id, flow,
          tokenization_requested, landing_route, is_validation=False, invoice_id=None,
          custom_create_values=None, **kwargs
      ):
          """ Create a draft transaction based on the payment context and return it.
  
          :param int payment_option_id: The payment option handling the transaction, as a
                                        `payment.acquirer` id or a `payment.token` id
          :param str reference_prefix: The custom prefix to compute the full reference
          :param float|None amount: The amount to pay in the given currency.
                                    None if in a payment method validation operation
          :param int|None currency_id: The currency of the transaction, as a `res.currency` id.
                                       None if in a payment method validation operation
          :param int partner_id: The partner making the payment, as a `res.partner` id
          :param str flow: The online payment flow of the transaction: 'redirect', 'direct' or 'token'
          :param bool tokenization_requested: Whether the user requested that a token is created
          :param str landing_route: The route the user is redirected to after the transaction
          :param bool is_validation: Whether the operation is a validation
          :param int invoice_id: The account move for which a payment id made, as an `account.move` id
          :param dict custom_create_values: Additional create values overwriting the default ones
          :param dict kwargs: Locally unused data passed to `_is_tokenization_required` and
                              `_compute_reference`
          :return: The sudoed transaction that was created
          :rtype: recordset of `payment.transaction`
          :raise: UserError if the flow is invalid
          """
          # Prepare create values
          if flow in ['redirect', 'direct']:  # Direct payment or payment with redirection
              acquirer_sudo = request.env['payment.acquirer'].sudo().browse(payment_option_id)
              token_id = None
              tokenization_required_or_requested = acquirer_sudo._is_tokenization_required(
                  provider=acquirer_sudo.provider, **kwargs
              ) or tokenization_requested
              tokenize = bool(
                  # Public users are not allowed to save tokens as their partner is unknown
                  not request.env.user._is_public()
                  # Don't tokenize if the user tried to force it through the browser's developer tools
                  and acquirer_sudo.allow_tokenization
                  # Token is only created if required by the flow or requested by the user
                  and tokenization_required_or_requested
              )
          elif flow == 'token':  # Payment by token
              token = request.env['payment.token'].browse(payment_option_id)
              acquirer_sudo = token.acquirer_id.sudo()
              token_id = payment_option_id
              tokenize = False
          else:
              raise UserError(
                  _("The payment should either be direct, with redirection, or made by a token.")
              )
  
          if invoice_id:
              if custom_create_values is None:
                  custom_create_values = {}
              custom_create_values['invoice_ids'] = [Command.set([int(invoice_id)])]
  
          reference = request.env['payment.transaction']._compute_reference(
              acquirer_sudo.provider,
              prefix=reference_prefix,
              **(custom_create_values or {}),
              **kwargs
          )
          if is_validation:  # Acquirers determine the amount and currency in validation operations
              amount = acquirer_sudo._get_validation_amount()
              currency_id = acquirer_sudo._get_validation_currency().id
  
          # Create the transaction
          tx_sudo = request.env['payment.transaction'].sudo().create({
              'acquirer_id': acquirer_sudo.id,
              'reference': reference,
              'amount': amount,
              'currency_id': currency_id,
              'partner_id': partner_id,
              'token_id': token_id,
              'operation': f'online_{flow}' if not is_validation else 'validation',
              'tokenize': tokenize,
              'landing_route': landing_route,
              **(custom_create_values or {}),
          })  # In sudo mode to allow writing on callback fields
  
          if flow == 'token':
              tx_sudo._send_payment_request()  # Payments by token process transactions immediately
          else:
              tx_sudo._log_sent_message()
  
          # Monitor the transaction to make it available in the portal
          PaymentPostProcessing.monitor_transactions(tx_sudo)
  
          return tx_sudo
function_tokens: def _create_transaction ( self , payment_option_id , reference_prefix , amount , currency_id , partner_id , flow , tokenization_requested , landing_route , is_validation = False , invoice_id = None , custom_create_values = None , * * kwargs ) : # Prepare create values if flow in [ 'redirect' , 'direct' ] : # Direct payment or payment with redirection acquirer_sudo = request . env [ 'payment.acquirer' ] . sudo ( ) . browse ( payment_option_id ) token_id = None tokenization_required_or_requested = acquirer_sudo . _is_tokenization_required ( provider = acquirer_sudo . provider , * * kwargs ) or tokenization_requested tokenize = bool ( # Public users are not allowed to save tokens as their partner is unknown not request . env . user . _is_public ( ) # Don't tokenize if the user tried to force it through the browser's developer tools and acquirer_sudo . allow_tokenization # Token is only created if required by the flow or requested by the user and tokenization_required_or_requested ) elif flow == 'token' : # Payment by token token = request . env [ 'payment.token' ] . browse ( payment_option_id ) acquirer_sudo = token . acquirer_id . sudo ( ) token_id = payment_option_id tokenize = False else : raise UserError ( _ ( "The payment should either be direct, with redirection, or made by a token." ) ) if invoice_id : if custom_create_values is None : custom_create_values = { } custom_create_values [ 'invoice_ids' ] = [ Command . set ( [ int ( invoice_id ) ] ) ] reference = request . env [ 'payment.transaction' ] . _compute_reference ( acquirer_sudo . provider , prefix = reference_prefix , * * ( custom_create_values or { } ) , * * kwargs ) if is_validation : # Acquirers determine the amount and currency in validation operations amount = acquirer_sudo . _get_validation_amount ( ) currency_id = acquirer_sudo . _get_validation_currency ( ) . id # Create the transaction tx_sudo = request . env [ 'payment.transaction' ] . sudo ( ) . create ( { 'acquirer_id' : acquirer_sudo . id , 'reference' : reference , 'amount' : amount , 'currency_id' : currency_id , 'partner_id' : partner_id , 'token_id' : token_id , 'operation' : f'online_{flow}' if not is_validation else 'validation' , 'tokenize' : tokenize , 'landing_route' : landing_route , * * ( custom_create_values or { } ) , } ) # In sudo mode to allow writing on callback fields if flow == 'token' : tx_sudo . _send_payment_request ( ) # Payments by token process transactions immediately else : tx_sudo . _log_sent_message ( ) # Monitor the transaction to make it available in the portal PaymentPostProcessing . monitor_transactions ( tx_sudo ) return tx_sudo