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"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<module version="4">
|
<module version="4">
|
||||||
<component name="PyDocumentationSettings">
|
<component name="PyDocumentationSettings">
|
||||||
<option name="format" value="GOOGLE" />
|
<option name="format" value="PLAIN" />
|
||||||
<option name="myDocStringFormat" value="Google" />
|
<option name="myDocStringFormat" value="Plain" />
|
||||||
</component>
|
</component>
|
||||||
<component name="TemplatesService">
|
<component name="TemplatesService">
|
||||||
<option name="TEMPLATE_CONFIGURATION" value="Django" />
|
<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
|
raise Http404(_("promocode does not exist")) from dne
|
||||||
return promocode.use(self)
|
return promocode.use(self)
|
||||||
|
|
||||||
def apply_addresses(
|
def apply_addresses(self, billing_address_uuid: str | None = None, shipping_address_uuid: str | None = None):
|
||||||
self, billing_address_uuid: str | None = None, shipping_address_uuid: str | None = None
|
|
||||||
):
|
|
||||||
try:
|
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:
|
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"))
|
raise ValueError(_("you can only buy physical products with shipping address specified"))
|
||||||
|
|
||||||
|
|
@ -1586,6 +1587,7 @@ class Order(ExportModelOperationsMixin("order"), NiceModel): # type: ignore [mi
|
||||||
if (not force_balance and not force_payment) or (force_balance and force_payment):
|
if (not force_balance and not force_payment) or (force_balance and force_payment):
|
||||||
raise ValueError(_("invalid force value"))
|
raise ValueError(_("invalid force value"))
|
||||||
|
|
||||||
|
if any([billing_address, shipping_address]):
|
||||||
order.apply_addresses(billing_address, shipping_address)
|
order.apply_addresses(billing_address, shipping_address)
|
||||||
|
|
||||||
if order.total_quantity < 1:
|
if order.total_quantity < 1:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue