Commit 8c9496d7 authored by Patrick's avatar Patrick

Remove customer.save(update_fields

parent c0a2aaa3
......@@ -166,7 +166,11 @@ def generate_invoice(permanence, payment_date):
customer.membership_fee_valid_until,
REPANIER_SETTINGS_MEMBERSHIP_FEE_DURATION
)
customer.save(update_fields=['membership_fee_valid_until', ])
# customer.save(update_fields=['membership_fee_valid_until', ])
# use vvvv because ^^^^^ will call "pre_save" function which reset valid_email to None
models.Customer.objects.filter(id=customer.id).order_by('?').update(
membership_fee_valid_until=customer.membership_fee_valid_until
)
permanence.recalculate_profit()
permanence.save()
......@@ -534,10 +538,15 @@ def cancel_invoice(permanence):
for customer_invoice in CustomerInvoice.objects.filter(
permanence_id=permanence.id).order_by():
customer = customer_invoice.customer
customer.balance = customer_invoice.previous_balance
customer.date_balance = customer_invoice.date_previous_balance
customer.save(update_fields=['balance', 'date_balance'])
# customer = customer_invoice.customer
# customer.balance = customer_invoice.previous_balance
# customer.date_balance = customer_invoice.date_previous_balance
# customer.save(update_fields=['balance', 'date_balance'])
# use vvvv because ^^^^^ will call "pre_save" function which reset valid_email to None
models.Customer.objects.filter(id=customer_invoice.customer_id).order_by('?').update(
balance=customer_invoice.previous_balance,
date_balance=customer_invoice.date_previous_balance
)
BankAccount.objects.all().filter(
customer_invoice_id=customer_invoice.id
).update(
......
......@@ -130,15 +130,10 @@ def send_email_with_error_log(email, from_name=None, track_customer_on_error=Fal
if track_customer_on_error:
# select the customer based on user__email or customer__email2
email_to = email.to[0]
customer = models.Customer.objects.filter(user__email=email_to).order_by('?').first()
customer = models.Customer.objects.filter(user__email=email_to, subscribe_to_email=True).exclude(valid_email=False).only('id').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 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
customer = models.Customer.objects.filter(email2=email_to, subscribe_to_email=True).exclude(valid_email=False).only('id').order_by('?').first()
send_mail = customer is not None
else:
customer = None
if send_mail:
......@@ -185,8 +180,10 @@ def send_email_with_error_log(email, from_name=None, track_customer_on_error=Fal
connection.close()
print("##################################")
if customer is not None:
customer.valid_email = valid_email
customer.save(update_fields=['valid_email'])
# customer.valid_email = valid_email
# customer.save(update_fields=['valid_email'])
# use vvvv because ^^^^^ will call "pre_save" function which reset valid_email to None
models.Customer.objects.filter(id=customer.id).order_by('?').update(valid_email=valid_email)
def send_email_to_who(is_email_send, board=False):
......
......@@ -94,7 +94,11 @@ def export_abstract(permanence, deliveries_id=None, group=False, wb=None):
).order_by('?').first()
if invoice is not None and invoice.total_price_with_tax.amount != DECIMAL_ZERO:
customer.preparation_order = preparation_order
customer.save(update_fields=['preparation_order'])
# customer.save(update_fields=['preparation_order'])
# use vvvv because ^^^^^ will call "pre_save" function which reset valid_email to None
Customer.objects.filter(id=customer.id).order_by('?').update(
preparation_order=preparation_order
)
preparation_order += 1
if REPANIER_SETTINGS_CUSTOMERS_MUST_CONFIRM_ORDERS and not invoice.is_order_confirm_send:
confirmed = _(" /!\ Unconfirmed")
......@@ -144,7 +148,11 @@ def export_abstract(permanence, deliveries_id=None, group=False, wb=None):
).order_by('?').first()
if invoice is not None and invoice.total_price_with_tax.amount != DECIMAL_ZERO:
customer.preparation_order = preparation_order
customer.save(update_fields=['preparation_order'])
# customer.save(update_fields=['preparation_order'])
# use vvvv because ^^^^^ will call "pre_save" function which reset valid_email to None
Customer.objects.filter(id=customer.id).order_by('?').update(
preparation_order=preparation_order
)
preparation_order += 1
if REPANIER_SETTINGS_CUSTOMERS_MUST_CONFIRM_ORDERS and not invoice.is_order_confirm_send:
confirmed = _(" /!\ Unconfirmed")
......
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