implemented new email templates, but not rendering

This commit is contained in:
Sam
2021-03-12 12:37:27 +00:00
parent d0609fd1fa
commit 778d65d84e
4 changed files with 378 additions and 12 deletions

View File

@@ -1217,8 +1217,13 @@ class PurchaseEmailTest(APITestCase):
self.assertEquals(2, len(mail.outbox))
def test_auth_user_can_use(self):
# required instances
company = CompanyFactory()
product = ProductFactory(company=company)
# make user the manager
self.user.company = company
self.user.role = 'COOP_MANAGER'
self.user.save()
data = {
'telephone': '123123123',

View File

@@ -273,10 +273,16 @@ def purchase_email(request):
validate_email(user_email)
except:
return Response({"error": "Value for email is not valid"}, status=status.HTTP_406_NOT_ACCEPTABLE)
# get comment
comment = data.get('comment')
# get company
company = Company.objects.filter(id=data['company']).first()
if not company:
return Response({"error": "Invalid value for company"}, status=status.HTTP_406_NOT_ACCEPTABLE)
# get managing user
managing_user = User.objects.filter(company=company, role='COOP_MANAGER').first()
if not managing_user:
return Response({"error": "No managing user found for company"}, status=status.HTTP_406_NOT_ACCEPTABLE)
# get product
product = Product.objects.filter(id=data['product'], company=company).first()
if not product:
@@ -291,6 +297,7 @@ def purchase_email(request):
'user': request.user,
'product': product,
'telephone': data['telephone'],
'comment': comment,
})
subject = "[latienda.coop] Solicitud de compra"
email = EmailMessage(subject, company_message, to=[company.email])
@@ -301,6 +308,7 @@ def purchase_email(request):
'company': company,
'product': product,
'company_message': company_message,
'manager': managing_user,
})
subject = 'Confirmación de petición de compra'
email = EmailMessage(subject, user_message, to=[user_email])