diff --git a/core/models.py b/core/models.py index 30a6ff03..f21b11f0 100644 --- a/core/models.py +++ b/core/models.py @@ -550,7 +550,7 @@ class Order(ExportModelOperationsMixin("order"), NiceModel): def total_quantity(self) -> int: return sum([op.quantity for op in self.order_products.all()]) - def add_product(self, product_uuid: str | None = None, attributes: list = list, update_quantity: bool = True): + def add_product(self, product_uuid: str | None = None, attributes: list = [], update_quantity: bool = True): if self.status not in ["PENDING", "MOMENTAL"]: raise ValueError(_("you cannot add products to an order that is not a pending one")) try: @@ -569,7 +569,7 @@ class Order(ExportModelOperationsMixin("order"), NiceModel): order_product, is_created = OrderProduct.objects.get_or_create( product=product, order=self, - attributes=json.dumps(attributes), + attributes=json.dumps(attributes) if attributes else {}, defaults={"quantity": 1, "buy_price": product.price}, ) if not is_created and update_quantity: