diff --git a/eboutic/models.py b/eboutic/models.py index cf6e15ab..afa3b035 100644 --- a/eboutic/models.py +++ b/eboutic/models.py @@ -219,16 +219,14 @@ class Invoice(models.Model): if self.validated: raise DataError(_("Invoice already validated")) customer, _created = Customer.get_or_create(user=self.user) - kwargs = { - "counter": get_eboutic(), - "customer": customer, - "date": self.date, - "payment_method": Selling.PaymentMethod.CARD, - } + kwargs = {"counter": get_eboutic(), "customer": customer, "date": self.date} for i in self.items.select_related("product"): if i.product.product_type_id == settings.SITH_COUNTER_PRODUCTTYPE_REFILLING: Refilling.objects.create( - **kwargs, operator=self.user, amount=i.unit_price * i.quantity + **kwargs, + operator=self.user, + amount=i.unit_price * i.quantity, + payment_method=Refilling.PaymentMethod.CARD, ) else: Selling.objects.create( @@ -239,6 +237,7 @@ class Invoice(models.Model): seller=self.user, unit_price=i.unit_price, quantity=i.quantity, + payment_method=Selling.PaymentMethod.CARD, ) self.validated = True self.save() diff --git a/eboutic/tests/test_payment.py b/eboutic/tests/test_payment.py index 5c4b1da1..b59c05bb 100644 --- a/eboutic/tests/test_payment.py +++ b/eboutic/tests/test_payment.py @@ -17,7 +17,7 @@ from pytest_django.asserts import assertRedirects from core.baker_recipes import old_subscriber_user, subscriber_user from counter.baker_recipes import price_recipe, product_recipe -from counter.models import Product, ProductType, Selling +from counter.models import Product, ProductType, Refilling, Selling from counter.tests.test_counter import force_refill_user from eboutic.models import Basket, BasketItem @@ -236,6 +236,10 @@ class TestPaymentCard(TestPaymentBase): self.customer.customer.refresh_from_db() assert self.customer.customer.amount == price.amount * 2 + refill = self.customer.customer.refillings.last() + assert refill is not None + assert refill.amount == price.amount * 2 + assert refill.payment_method == Refilling.PaymentMethod.CARD def test_multiple_responses(self): bank_response = self.generate_bank_valid_answer(self.basket)