created json field Company.credentials, added import_products action to CompanyViewSet
This commit is contained in:
@@ -1,12 +1,15 @@
|
|||||||
# from django.db import models
|
# from django.db import models
|
||||||
from django.contrib.gis.db import models
|
from django.contrib.gis.db import models
|
||||||
|
from django.contrib.postgres.fields import JSONField
|
||||||
|
from django.contrib.auth import get_user_model
|
||||||
from tagulous.models import TagField
|
from tagulous.models import TagField
|
||||||
# from core.models import TreeTag
|
|
||||||
|
|
||||||
|
|
||||||
|
from history.models import HistorySync
|
||||||
# Create your models here.
|
# Create your models here.
|
||||||
|
|
||||||
|
# User = get_user_model()
|
||||||
|
|
||||||
|
|
||||||
class Company(models.Model):
|
class Company(models.Model):
|
||||||
|
|
||||||
WOO_COMMERCE = 'WOO_COMMERCE'
|
WOO_COMMERCE = 'WOO_COMMERCE'
|
||||||
@@ -42,14 +45,13 @@ class Company(models.Model):
|
|||||||
sync = models.BooleanField('Sincronizar tienda', default=False, null=True, blank=True)
|
sync = models.BooleanField('Sincronizar tienda', default=False, null=True, blank=True)
|
||||||
is_validated = models.BooleanField('Validado', default=False, null=True, blank=True)
|
is_validated = models.BooleanField('Validado', default=False, null=True, blank=True)
|
||||||
is_active = models.BooleanField('Activado', default=False, null=True, blank=True)
|
is_active = models.BooleanField('Activado', default=False, null=True, blank=True)
|
||||||
|
credentials = JSONField(null=True)
|
||||||
|
|
||||||
# internal
|
# internal
|
||||||
created = models.DateTimeField('date of creation', auto_now_add=True)
|
created = models.DateTimeField('date of creation', auto_now_add=True)
|
||||||
updated = models.DateTimeField('date last update', auto_now=True)
|
updated = models.DateTimeField('date last update', auto_now=True)
|
||||||
creator = models.ForeignKey('core.CustomUser', on_delete=models.DO_NOTHING, null=True, related_name='creator')
|
creator = models.ForeignKey('core.CustomUser', on_delete=models.DO_NOTHING, null=True, related_name='creator')
|
||||||
|
# history = models.ForeignKey(HistorySync, null=True, on_delete=models.DO_NOTHING, related_name='company')
|
||||||
# def __str__(self):
|
|
||||||
# return self.company_name
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = "Compañía"
|
verbose_name = "Compañía"
|
||||||
|
|||||||
@@ -35,8 +35,7 @@ class CompanyViewSet(viewsets.ModelViewSet):
|
|||||||
Send email to company.creator
|
Send email to company.creator
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
queryset = self.get_custom_queryset(request)
|
instance = self.queryset.filter(pk=kwargs['pk']).first()
|
||||||
instance = queryset.filter(pk=kwargs['pk']).first()
|
|
||||||
if instance:
|
if instance:
|
||||||
# IP stuff
|
# IP stuff
|
||||||
client_ip, is_routable = get_client_ip(request)
|
client_ip, is_routable = get_client_ip(request)
|
||||||
@@ -121,6 +120,20 @@ class CompanyViewSet(viewsets.ModelViewSet):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
return Response({"errors":{"details": str(e),}}, status=500)
|
return Response({"errors":{"details": str(e),}}, status=500)
|
||||||
|
|
||||||
|
@action(detail=True, methods=['POST', ])
|
||||||
|
def import_products(self, request, **kwargs):
|
||||||
|
instance = self.queryset.filter(pk=kwargs['pk']).first()
|
||||||
|
# check if it's a shop
|
||||||
|
if instance.shop is not True:
|
||||||
|
return Response('This company is not s shop')
|
||||||
|
# check what platform
|
||||||
|
platform = instance.platform
|
||||||
|
# check required credentials
|
||||||
|
|
||||||
|
# execute import
|
||||||
|
|
||||||
|
return Response()
|
||||||
|
|
||||||
|
|
||||||
@api_view(['GET',])
|
@api_view(['GET',])
|
||||||
@permission_classes([IsAuthenticated,])
|
@permission_classes([IsAuthenticated,])
|
||||||
|
|||||||
Reference in New Issue
Block a user