feat: websockets
This commit is contained in:
@@ -350,11 +350,32 @@ class ProductVariantCreateView(ProductVariantAttributesContextMixin, BackofficeC
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
product = self.get_product()
|
||||
context.setdefault('price_form', ProductInitialPriceForm())
|
||||
context.update(
|
||||
{'title': f'Añadir variante a {product.name}', 'cancel_url': reverse_lazy('backoffice:product_detail', args=[product.pk])}
|
||||
)
|
||||
return context
|
||||
|
||||
def form_valid(self, form):
|
||||
# El precio es opcional y se crea en el mismo envío que la variante,
|
||||
# igual que en ProductCreateView (ver ProductInitialPriceForm).
|
||||
price_form = ProductInitialPriceForm(self.request.POST)
|
||||
|
||||
if not price_form.is_valid():
|
||||
return self.render_to_response(self.get_context_data(form=form, price_form=price_form))
|
||||
|
||||
response = super().form_valid(form)
|
||||
|
||||
if price_form.cleaned_data.get('price') is not None:
|
||||
ProductPrice.objects.create(
|
||||
variant=self.object,
|
||||
price=price_form.get_price_without_tax(),
|
||||
tax=price_form.cleaned_data['tax'],
|
||||
current=True,
|
||||
)
|
||||
|
||||
return response
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse_lazy('backoffice:product_detail', args=[self.object.product_id])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user