From d3ef98eafe1d8c2bd9e5c72cf1815a068dae9666 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 31 Mar 2019 13:31:29 +0200 Subject: [PATCH] Add setter to stripe_customer_source and write stripe_token in scenario Since issue7985, Function fields must have a setter method if they are not read only. And proteus does not save anymore readonly fields. --- payment.py | 9 +++++---- tests/scenario_account_payment_stripe.rst | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/payment.py b/payment.py index 01c0cbe8df..de2ce2b09f 100644 --- a/payment.py +++ b/payment.py @@ -162,7 +162,7 @@ class Payment(metaclass=PoolMeta): }, depends=[ 'stripe_account', 'stripe_token', 'stripe_customer', 'state']), - 'get_stripe_customer_source') + 'get_stripe_customer_source', setter='set_stripe_customer_source') stripe_account = fields.Function(fields.Many2One( 'account.payment.stripe.account', "Stripe Account"), 'on_change_with_stripe_account') @@ -190,9 +190,6 @@ class Payment(metaclass=PoolMeta): 'depends': ['state', 'stripe_capture_needed'], }, }) - # As there is not setter to avoid the cost of validation, - # the readonly attribute must be unset. - cls.stripe_customer_source_selection._field.readonly = False @classmethod def __register__(cls, module_name): @@ -258,6 +255,10 @@ class Payment(metaclass=PoolMeta): def get_stripe_customer_source(self, name): return self.stripe_customer_source + @classmethod + def set_stripe_customer_source(cls, payments, name, value): + pass + def get_stripe_checkout_needed(self, name): return (self.journal.process_method == 'stripe' and not self.stripe_token diff --git a/tests/scenario_account_payment_stripe.rst b/tests/scenario_account_payment_stripe.rst index 1e5fb57cc0..4057ed5c30 100644 --- a/tests/scenario_account_payment_stripe.rst +++ b/tests/scenario_account_payment_stripe.rst @@ -157,8 +157,8 @@ Checkout the customer:: ... 'cvc': '123', ... }, ... ) - >>> stripe_customer.stripe_token = token.id - >>> stripe_customer.save() + >>> Customer.write( + ... [stripe_customer.id], {'stripe_token': token.id}, config.context) Run cron::