Replace checkout wizard by values returned by button_action
Closes #14076
This commit is contained in:
@@ -24,7 +24,6 @@ def register():
|
|||||||
module='account_payment_braintree', type_='model')
|
module='account_payment_braintree', type_='model')
|
||||||
Pool.register(
|
Pool.register(
|
||||||
account.PaymentBraintreeCustomerPaymentMethodDelete,
|
account.PaymentBraintreeCustomerPaymentMethodDelete,
|
||||||
account.PaymentBraintreeCheckout,
|
|
||||||
party.Replace,
|
party.Replace,
|
||||||
module='account_payment_braintree', type_='wizard')
|
module='account_payment_braintree', type_='wizard')
|
||||||
Pool.register(
|
Pool.register(
|
||||||
|
|||||||
@@ -30,8 +30,7 @@ from trytond.report import Report
|
|||||||
from trytond.tools import sql_pairing
|
from trytond.tools import sql_pairing
|
||||||
from trytond.transaction import Transaction
|
from trytond.transaction import Transaction
|
||||||
from trytond.url import http_host
|
from trytond.url import http_host
|
||||||
from trytond.wizard import (
|
from trytond.wizard import Button, StateTransition, StateView, Wizard
|
||||||
Button, StateAction, StateTransition, StateView, Wizard)
|
|
||||||
|
|
||||||
from .common import BraintreeCustomerMethodMixin
|
from .common import BraintreeCustomerMethodMixin
|
||||||
from .exceptions import BraintreeAccountWarning
|
from .exceptions import BraintreeAccountWarning
|
||||||
@@ -115,20 +114,24 @@ class CheckoutMixin:
|
|||||||
return super().copy(records, default=default)
|
return super().copy(records, default=default)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ModelView.button_action('account_payment_braintree.wizard_checkout')
|
@ModelView.button_action('account_payment_braintree.url_checkout')
|
||||||
def braintree_checkout(cls, records):
|
def braintree_checkout(cls, records):
|
||||||
for record in records:
|
for record in records:
|
||||||
record.braintree_checkout_id = uuid.uuid4().hex
|
record.braintree_checkout_id = uuid.uuid4().hex
|
||||||
cls.save(records)
|
record.save()
|
||||||
|
return {
|
||||||
|
'url': record.braintree_checkout_url,
|
||||||
|
}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def braintree_checkout_url(self):
|
def braintree_checkout_url(self):
|
||||||
pool = Pool()
|
pool = Pool()
|
||||||
database = Transaction().database.name
|
database = Transaction().database.name
|
||||||
Checkout = pool.get(
|
ModelData = pool.get('ir.model.data')
|
||||||
'account.payment.braintree.checkout', type='wizard')
|
URL = pool.get('ir.action.url')
|
||||||
action = Checkout.checkout.get_action()
|
action = URL(ModelData.get_id(
|
||||||
return action['url'] % {
|
'account_payment_braintree.url_checkout'))
|
||||||
|
return action.url % {
|
||||||
'http_host': http_host(),
|
'http_host': http_host(),
|
||||||
'database': database,
|
'database': database,
|
||||||
'model': self.__class__.__name__,
|
'model': self.__class__.__name__,
|
||||||
@@ -1261,15 +1264,5 @@ class PaymentBraintreeCustomerPaymentMethodDeleteAsk(ModelView):
|
|||||||
return methods
|
return methods
|
||||||
|
|
||||||
|
|
||||||
class PaymentBraintreeCheckout(Wizard):
|
|
||||||
__name__ = 'account.payment.braintree.checkout'
|
|
||||||
start_state = 'checkout'
|
|
||||||
checkout = StateAction('account_payment_braintree.url_checkout')
|
|
||||||
|
|
||||||
def do_checkout(self, action):
|
|
||||||
action['url'] = self.record.braintree_checkout_url
|
|
||||||
return action, {}
|
|
||||||
|
|
||||||
|
|
||||||
class PaymentBraintreeCheckoutPage(Report):
|
class PaymentBraintreeCheckoutPage(Report):
|
||||||
__name__ = 'account.payment.braintree.checkout'
|
__name__ = 'account.payment.braintree.checkout'
|
||||||
|
|||||||
@@ -293,11 +293,6 @@ this repository contains the full copyright notices and license terms. -->
|
|||||||
<field name="name">customer_payment_method_delete_ask_form</field>
|
<field name="name">customer_payment_method_delete_ask_form</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
<record model="ir.action.wizard" id="wizard_checkout">
|
|
||||||
<field name="name">Braintree Checkout</field>
|
|
||||||
<field name="wiz_name">account.payment.braintree.checkout</field>
|
|
||||||
</record>
|
|
||||||
|
|
||||||
<record model="ir.action.url" id="url_checkout">
|
<record model="ir.action.url" id="url_checkout">
|
||||||
<field name="name">Braintree Checkout</field>
|
<field name="name">Braintree Checkout</field>
|
||||||
<field name="url">%(http_host)s/%(database)s/account_payment_braintree/checkout/%(model)s/%(id)s</field>
|
<field name="url">%(http_host)s/%(database)s/account_payment_braintree/checkout/%(model)s/%(id)s</field>
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ def register():
|
|||||||
ir.Cron,
|
ir.Cron,
|
||||||
module='account_payment_stripe', type_='model')
|
module='account_payment_stripe', type_='model')
|
||||||
Pool.register(
|
Pool.register(
|
||||||
payment.Checkout,
|
|
||||||
payment.CustomerSourceDetach,
|
payment.CustomerSourceDetach,
|
||||||
party.Replace,
|
party.Replace,
|
||||||
module='account_payment_stripe', type_='wizard')
|
module='account_payment_stripe', type_='wizard')
|
||||||
|
|||||||
@@ -30,8 +30,7 @@ from trytond.tools import sql_pairing
|
|||||||
from trytond.tools.email_ import set_from_header
|
from trytond.tools.email_ import set_from_header
|
||||||
from trytond.transaction import Transaction
|
from trytond.transaction import Transaction
|
||||||
from trytond.url import http_host
|
from trytond.url import http_host
|
||||||
from trytond.wizard import (
|
from trytond.wizard import Button, StateTransition, StateView, Wizard
|
||||||
Button, StateAction, StateTransition, StateView, Wizard)
|
|
||||||
|
|
||||||
from .common import StripeCustomerMethodMixin
|
from .common import StripeCustomerMethodMixin
|
||||||
from .exceptions import StripeAccountWarning
|
from .exceptions import StripeAccountWarning
|
||||||
@@ -87,19 +86,23 @@ class CheckoutMixin:
|
|||||||
return super().copy(records, default=default)
|
return super().copy(records, default=default)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ModelView.button_action('account_payment_stripe.wizard_checkout')
|
@ModelView.button_action('account_payment_stripe.url_checkout')
|
||||||
def stripe_checkout(cls, records):
|
def stripe_checkout(cls, records):
|
||||||
for record in records:
|
for record in records:
|
||||||
record.stripe_checkout_id = uuid.uuid4().hex
|
record.stripe_checkout_id = uuid.uuid4().hex
|
||||||
cls.save(records)
|
record.save()
|
||||||
|
return {
|
||||||
|
'url': record.stripe_checkout_url,
|
||||||
|
}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def stripe_checkout_url(self):
|
def stripe_checkout_url(self):
|
||||||
pool = Pool()
|
pool = Pool()
|
||||||
database = Transaction().database.name
|
database = Transaction().database.name
|
||||||
Checkout = pool.get('account.payment.stripe.checkout', type='wizard')
|
ModelData = pool.get('ir.model.data')
|
||||||
action = Checkout.checkout.get_action()
|
URL = pool.get('ir.action.url')
|
||||||
return action['url'] % {
|
action = URL(ModelData.get_id('account_payment_stripe.url_checkout'))
|
||||||
|
return action.url % {
|
||||||
'http_host': http_host(),
|
'http_host': http_host(),
|
||||||
'database': database,
|
'database': database,
|
||||||
'model': self.__class__.__name__,
|
'model': self.__class__.__name__,
|
||||||
@@ -1947,16 +1950,6 @@ class CustomerIdentical(ModelSQL):
|
|||||||
where=source.customer != target.customer))
|
where=source.customer != target.customer))
|
||||||
|
|
||||||
|
|
||||||
class Checkout(Wizard):
|
|
||||||
__name__ = 'account.payment.stripe.checkout'
|
|
||||||
start_state = 'checkout'
|
|
||||||
checkout = StateAction('account_payment_stripe.url_checkout')
|
|
||||||
|
|
||||||
def do_checkout(self, action):
|
|
||||||
action['url'] = self.record.stripe_checkout_url
|
|
||||||
return action, {}
|
|
||||||
|
|
||||||
|
|
||||||
class CheckoutPage(Report):
|
class CheckoutPage(Report):
|
||||||
__name__ = 'account.payment.stripe.checkout'
|
__name__ = 'account.payment.stripe.checkout'
|
||||||
|
|
||||||
|
|||||||
@@ -289,12 +289,6 @@ this repository contains the full copyright notices and license terms. -->
|
|||||||
<field name="string">Find Identical</field>
|
<field name="string">Find Identical</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
<record model="ir.action.wizard" id="wizard_checkout">
|
|
||||||
<field name="name">Stripe Checkout</field>
|
|
||||||
<field name="wiz_name">account.payment.stripe.checkout</field>
|
|
||||||
<field name="model" eval="None"/>
|
|
||||||
</record>
|
|
||||||
|
|
||||||
<record model="ir.action.report" id="report_checkout">
|
<record model="ir.action.report" id="report_checkout">
|
||||||
<field name="name">Stripe Checkout</field>
|
<field name="name">Stripe Checkout</field>
|
||||||
<field name="model" eval="None"/>
|
<field name="model" eval="None"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user