|
|
|
|
@ -99,7 +99,7 @@ class CartCheckoutBuyingForm(forms.Form): |
|
|
|
|
|
|
|
|
|
def get_initial_for_field(self, field, field_name): |
|
|
|
|
if field_name == 'offer': |
|
|
|
|
field = Offer.active.get(product_id=self.initia[field_name]) |
|
|
|
|
field.initial = Offer.active.get(product_id=self.initia[field_name]) |
|
|
|
|
elif field_name == 'order': |
|
|
|
|
field = Order.objects.get(order_code=self.initial[field_name]) |
|
|
|
|
elif field_name == 'amount' or field_name == 'bonus_points': |
|
|
|
|
@ -109,11 +109,11 @@ class CartCheckoutBuyingForm(forms.Form): |
|
|
|
|
def save(self, user): |
|
|
|
|
buying = Buying() |
|
|
|
|
buying.user = user |
|
|
|
|
buying.offer = self.offer |
|
|
|
|
buying.order = self.order |
|
|
|
|
buying.bonus_points = self.bonus_points |
|
|
|
|
buying.amount = self.amount |
|
|
|
|
buying.total_price = self.offer.get_price_with_discount * self.amount |
|
|
|
|
buying.offer = self.data['offer'] |
|
|
|
|
buying.order = self.data['order'] |
|
|
|
|
buying.bonus_points = self.data['bonus_points'] |
|
|
|
|
buying.amount = self.data['amount'] |
|
|
|
|
buying.total_price = self.data['offer'].get_price_with_discount() * self.data['amount'] |
|
|
|
|
buying.save() |
|
|
|
|
return buying |
|
|
|
|
|
|
|
|
|
@ -132,7 +132,7 @@ class CartCheckoutForm(RequestNotifiable, forms.ModelForm): |
|
|
|
|
Field('customer_name', css_class="order__input", template=self.field_template), |
|
|
|
|
Field('customer_email', css_class="order__input", template=self.field_template), |
|
|
|
|
Field('customer_user', css_class="order__input", template=self.field_template), |
|
|
|
|
Field('phone', css_class="order__input", template=self.field_template), |
|
|
|
|
Field('phone', css_class="order__input", placeholder="(+7/8)9999999999", template=self.field_template), |
|
|
|
|
Field('customer_address', css_class="order__input", template=self.field_template), |
|
|
|
|
Field('city', css_class="order__input", template=self.field_template), |
|
|
|
|
Field('comment', css_class="order__input", template=self.field_template), |
|
|
|
|
@ -158,7 +158,11 @@ class CartCheckoutForm(RequestNotifiable, forms.ModelForm): |
|
|
|
|
return super().save(commit) |
|
|
|
|
|
|
|
|
|
def send_order_invoice(self, request): |
|
|
|
|
return send_user_order_notification.delay(self.instance.id, request) |
|
|
|
|
context = { |
|
|
|
|
'order_id': self.instance.id, |
|
|
|
|
'site_url': request.build_absolute_uri(), |
|
|
|
|
} |
|
|
|
|
return send_user_order_notification.delay(context=context) |
|
|
|
|
|
|
|
|
|
def send_order_request(self, request): |
|
|
|
|
context = { |
|
|
|
|
@ -166,12 +170,12 @@ class CartCheckoutForm(RequestNotifiable, forms.ModelForm): |
|
|
|
|
'recipients': (settings.DEFAULT_FROM_EMAIL,), |
|
|
|
|
'email': { |
|
|
|
|
'subject': _('У вас новый заказ'), |
|
|
|
|
'order': self.instance, |
|
|
|
|
'order_id': self.instance.id, |
|
|
|
|
}, |
|
|
|
|
'send_at_date': self.instance.create_at, |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
return send_admin_order_notification.delay(context) |
|
|
|
|
return send_admin_order_notification.delay(context=context) |
|
|
|
|
|
|
|
|
|
class Meta: |
|
|
|
|
model = Order |
|
|
|
|
|