Features: 1) Add default Address.objects.none() placeholders in apply_addresses method; 2) Validate address application only when billing or shipping address exists;
Fixes: 1) Correct logic for optional address validation to avoid runtime errors; Extra: 1) Change documentation settings format from "Google" to "Plain".
This commit is contained in:
parent
eb213c7f3f
commit
eb7cc9847a
2 changed files with 8 additions and 6 deletions
|
|
@ -1,8 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module version="4">
|
||||
<component name="PyDocumentationSettings">
|
||||
<option name="format" value="GOOGLE" />
|
||||
<option name="myDocStringFormat" value="Google" />
|
||||
<option name="format" value="PLAIN" />
|
||||
<option name="myDocStringFormat" value="Plain" />
|
||||
</component>
|
||||
<component name="TemplatesService">
|
||||
<option name="TEMPLATE_CONFIGURATION" value="Django" />
|
||||
|
|
|
|||
|
|
@ -1536,10 +1536,11 @@ class Order(ExportModelOperationsMixin("order"), NiceModel): # type: ignore [mi
|
|||
raise Http404(_("promocode does not exist")) from dne
|
||||
return promocode.use(self)
|
||||
|
||||
def apply_addresses(
|
||||
self, billing_address_uuid: str | None = None, shipping_address_uuid: str | None = None
|
||||
):
|
||||
def apply_addresses(self, billing_address_uuid: str | None = None, shipping_address_uuid: str | None = None):
|
||||
try:
|
||||
billing_address = Address.objects.none()
|
||||
shipping_address = Address.objects.none()
|
||||
|
||||
if not any([shipping_address_uuid, billing_address_uuid]) and not self.is_whole_digital:
|
||||
raise ValueError(_("you can only buy physical products with shipping address specified"))
|
||||
|
||||
|
|
@ -1586,7 +1587,8 @@ class Order(ExportModelOperationsMixin("order"), NiceModel): # type: ignore [mi
|
|||
if (not force_balance and not force_payment) or (force_balance and force_payment):
|
||||
raise ValueError(_("invalid force value"))
|
||||
|
||||
order.apply_addresses(billing_address, shipping_address)
|
||||
if any([billing_address, shipping_address]):
|
||||
order.apply_addresses(billing_address, shipping_address)
|
||||
|
||||
if order.total_quantity < 1:
|
||||
raise ValueError(_("you cannot purchase an empty order!"))
|
||||
|
|
|
|||
Loading…
Reference in a new issue