Commit b6d8d519 authored by Patrick's avatar Patrick

Add subscribe_to_email field at customer level.

parent 2e7c86eb
......@@ -338,7 +338,7 @@ class CustomerWithUserDataAdmin(ImportExportMixin, admin.ModelAdmin):
else:
fields_basic += [
('get_admin_balance', 'price_list_multiplier', 'get_admin_date_balance'),
('may_order', 'is_group', 'is_active'),
('may_order', 'is_group', 'is_active', 'subscribe_to_email'),
]
else:
fields_basic += [
......
This diff is collapsed.
......@@ -107,6 +107,7 @@ class Customer(models.Model):
is_group = models.BooleanField(_("is_group"), default=False)
may_order = models.BooleanField(_("may_order"), default=True)
valid_email = models.NullBooleanField(_("valid_email"), default=None)
subscribe_to_email = models.BooleanField(_("subscribe to email"), default=True)
preparation_order = models.IntegerField(null=True, blank=True, default=0)
def get_admin_date_balance(self):
......
......@@ -127,9 +127,12 @@ def send_email_with_error_log(email, from_name=None, track_customer_on_error=Fal
customer = models.Customer.objects.filter(user__email=email_to).order_by('?').first()
if customer is None:
customer = models.Customer.objects.filter(email2=email_to).order_by('?').first()
if customer is None or customer.valid_email is False:
if customer is None or customer.valid_email is False or customer.subscribe_to_email is False:
send_mail = False
print("################################## send_email customer.valid_email == False")
if send_email:
# Append "unsubscribe" at the end of the email.
pass
else:
customer = None
if send_mail:
......
......@@ -29,6 +29,9 @@ class CustomerForm(RepanierForm):
accept_mails_from_members = forms.BooleanField(
label=EMPTY_STRING, required=False
)
subscribe_to_email = forms.BooleanField(
label=EMPTY_STRING, required=False
)
phone1 = forms.CharField(label=_('Your main phone'), max_length=25)
phone2 = forms.CharField(label=_('Your secondary phone'), max_length=25, required=False)
......@@ -61,6 +64,8 @@ class CustomerForm(RepanierForm):
label=_('My emails are visible to all members'))
self.fields["accept_phone_call_from_members"].widget = CheckboxWidget(
label=_('My phones numbers are visible to all members'))
self.fields["subscribe_to_email"].widget = CheckboxWidget(
label=_('I subscribe to emails send by repanier'))
class CustomerValidationForm(NgFormValidationMixin, CustomerForm):
......@@ -92,6 +97,7 @@ def my_profile_view(request):
customer.accept_phone_call_from_members = form.cleaned_data.get('accept_phone_call_from_members')
customer.email2 = form.cleaned_data.get('email2').lower()
customer.accept_mails_from_members = form.cleaned_data.get('accept_mails_from_members')
customer.subscribe_to_email = form.cleaned_data.get('subscribe_to_email')
customer.city = form.cleaned_data.get('city')
customer.address = form.cleaned_data.get('address')
customer.picture = form.cleaned_data.get('picture')
......@@ -130,6 +136,8 @@ def my_profile_view(request):
field.initial = customer.email2
field = form.fields["accept_mails_from_members"]
field.initial = customer.accept_mails_from_members
field = form.fields["subscribe_to_email"]
field.initial = customer.subscribe_to_email
field = form.fields["city"]
field.initial = customer.city
field = form.fields["address"]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment