diff --git a/docs/releases/1.1.2.rst b/docs/releases/1.1.2.rst new file mode 100644 index 0000000..de60e8f --- /dev/null +++ b/docs/releases/1.1.2.rst @@ -0,0 +1,15 @@ +##### +1.1.2 +##### + +*2022-03-22* + +Changed +------- + +- Creating an Order using ``create_from_basket`` no longer saves the order twice. + +Fixed +----- + +- Fixed wrong sender model being sent for status changed signal. diff --git a/docs/releases/index.rst b/docs/releases/index.rst index 616a7a4..b8711d9 100644 --- a/docs/releases/index.rst +++ b/docs/releases/index.rst @@ -18,6 +18,7 @@ Release notes and upgrade information. This project adheres to :caption: v1.1 :maxdepth: 1 + 1.1.2 1.1.1 1.1.0 diff --git a/salesman/orders/models.py b/salesman/orders/models.py index 0e35ec6..720f924 100644 --- a/salesman/orders/models.py +++ b/salesman/orders/models.py @@ -14,7 +14,7 @@ from django.utils.text import Truncator from django.utils.translation import gettext_lazy as _ -from salesman.basket.models import Basket, BasketItem +from salesman.basket.models import BaseBasket, BaseBasketItem from salesman.conf import app_settings from salesman.core.typing import Product from salesman.core.utils import get_salesman_model @@ -47,13 +47,12 @@ def create_from_request(self, request: HttpRequest, **kwargs) -> BaseOrder: Returns: Order: Order instance """ - generate_ref = app_settings.SALESMAN_ORDER_REFERENCE_GENERATOR - kwargs['ref'] = generate_ref(request) + kwargs['ref'] = app_settings.SALESMAN_ORDER_REFERENCE_GENERATOR(request) return super().create(**kwargs) def create_from_basket( self, - basket: Basket, + basket: BaseBasket, request: HttpRequest, **kwargs, ) -> BaseOrder: @@ -63,7 +62,8 @@ def create_from_basket( Returns: Order: Order instance """ - order = self.create_from_request(request, **kwargs) + kwargs['ref'] = app_settings.SALESMAN_ORDER_REFERENCE_GENERATOR(request) + order = self.model(**kwargs) order.populate_from_basket(basket, request) return order @@ -154,7 +154,7 @@ def save(self, *args, **kwargs): # Send signal if status changed. if new_status != old_status: status_changed.send( - get_salesman_model('Basket'), + get_salesman_model('Order'), order=self, new_status=new_status, old_status=old_status, @@ -188,7 +188,7 @@ def pay( @transaction.atomic def populate_from_basket( self, - basket: Basket, + basket: BaseBasket, request: HttpRequest, **kwargs, ) -> None: @@ -369,7 +369,11 @@ def save(self, *args, **kwargs): kwargs['update_fields'].append('_extra') super().save(*args, **kwargs) - def populate_from_basket_item(self, item: BasketItem, request: HttpRequest) -> None: + def populate_from_basket_item( + self, + item: BaseBasketItem, + request: HttpRequest, + ) -> None: """ Populate order with items from basket.