Commit 5a3fbcd9 authored by Patrick's avatar Patrick

Add is_group field to customer to simplify the logic

parent a5ec1709
...@@ -142,6 +142,7 @@ class CustomerResource(resources.ModelResource): ...@@ -142,6 +142,7 @@ class CustomerResource(resources.ModelResource):
date_balance = fields.Field(attribute='get_admin_date_balance', widget=DateWidgetExcel(), readonly=True) date_balance = fields.Field(attribute='get_admin_date_balance', widget=DateWidgetExcel(), readonly=True)
balance = fields.Field(attribute='get_admin_balance', widget=TwoMoneysWidget(), readonly=True) balance = fields.Field(attribute='get_admin_balance', widget=TwoMoneysWidget(), readonly=True)
may_order = fields.Field(attribute='may_order', default=False, widget=DecimalBooleanWidget(), readonly=False) may_order = fields.Field(attribute='may_order', default=False, widget=DecimalBooleanWidget(), readonly=False)
is_group = fields.Field(attribute='is_group', default=False, widget=DecimalBooleanWidget(), readonly=False)
represent_this_buyinggroup = fields.Field(attribute='represent_this_buyinggroup', widget=DecimalBooleanWidget(), represent_this_buyinggroup = fields.Field(attribute='represent_this_buyinggroup', widget=DecimalBooleanWidget(),
readonly=True) readonly=True)
is_active = fields.Field(attribute='is_active', widget=DecimalBooleanWidget(), readonly=True) is_active = fields.Field(attribute='is_active', widget=DecimalBooleanWidget(), readonly=True)
...@@ -202,7 +203,8 @@ class CustomerResource(resources.ModelResource): ...@@ -202,7 +203,8 @@ class CustomerResource(resources.ModelResource):
'bank_account1', 'bank_account2', 'bank_account1', 'bank_account2',
'date_balance', 'balance', 'price_list_multiplier', 'date_balance', 'balance', 'price_list_multiplier',
'membership_fee_valid_until', 'last_membership_fee', 'last_membership_fee_date', 'membership_fee_valid_until', 'last_membership_fee', 'last_membership_fee_date',
'participation', 'purchase', 'represent_this_buyinggroup', 'is_active', 'delivery_point', 'valid_email' 'participation', 'purchase', 'represent_this_buyinggroup', 'is_group', 'is_active', 'delivery_point',
'valid_email'
) )
export_order = fields export_order = fields
import_id_fields = ('id',) import_id_fields = ('id',)
...@@ -239,7 +241,7 @@ class CustomerWithUserDataAdmin(ImportExportMixin, admin.ModelAdmin): ...@@ -239,7 +241,7 @@ class CustomerWithUserDataAdmin(ImportExportMixin, admin.ModelAdmin):
search_fields = ('short_basket_name', 'long_basket_name', 'user__email', 'email2') search_fields = ('short_basket_name', 'long_basket_name', 'user__email', 'email2')
list_per_page = 16 list_per_page = 16
list_max_show_all = 16 list_max_show_all = 16
list_filter = ('is_active', 'may_order', 'valid_email') list_filter = ('is_active', 'may_order', 'is_group', 'valid_email')
def has_delete_permission(self, request, customer=None): def has_delete_permission(self, request, customer=None):
if request.user.groups.filter( if request.user.groups.filter(
...@@ -320,7 +322,7 @@ class CustomerWithUserDataAdmin(ImportExportMixin, admin.ModelAdmin): ...@@ -320,7 +322,7 @@ class CustomerWithUserDataAdmin(ImportExportMixin, admin.ModelAdmin):
else: else:
fields_basic += [ fields_basic += [
('get_admin_balance', 'price_list_multiplier', 'get_admin_date_balance'), ('get_admin_balance', 'price_list_multiplier', 'get_admin_date_balance'),
('may_order', 'is_active'), ('may_order', 'is_group', 'is_active'),
] ]
else: else:
fields_basic += [ fields_basic += [
......
...@@ -103,10 +103,7 @@ class LUTDeliveryPointDataForm(TranslatableModelForm): ...@@ -103,10 +103,7 @@ class LUTDeliveryPointDataForm(TranslatableModelForm):
required=False required=False
) )
customer_responsible = forms.ModelChoiceField( customer_responsible = forms.ModelChoiceField(
Customer.objects.filter( Customer.objects.filter(is_group=True, is_active=True),
may_order=False, is_active=True, delivery_point__isnull=True,
represent_this_buyinggroup=False
),
label=_("customer_responsible"), label=_("customer_responsible"),
help_text=_("Invoices are sent to this consumer who is responsible for collecting the payments."), help_text=_("Invoices are sent to this consumer who is responsible for collecting the payments."),
required=False) required=False)
......
This diff is collapsed.
...@@ -108,6 +108,7 @@ class Customer(models.Model): ...@@ -108,6 +108,7 @@ class Customer(models.Model):
verbose_name=_("delivery point"), verbose_name=_("delivery point"),
blank=True, null=True, default=None) blank=True, null=True, default=None)
is_active = models.BooleanField(_("is_active"), default=True) is_active = models.BooleanField(_("is_active"), default=True)
is_group = models.BooleanField(_("is_group"), default=False)
may_order = models.BooleanField(_("may_order"), default=True) may_order = models.BooleanField(_("may_order"), default=True)
valid_email = models.NullBooleanField(_("valid_email"), default=None) valid_email = models.NullBooleanField(_("valid_email"), default=None)
preparation_order = models.IntegerField(null=True, blank=True, default=0) preparation_order = models.IntegerField(null=True, blank=True, default=0)
...@@ -279,6 +280,7 @@ def customer_pre_save(sender, **kwargs): ...@@ -279,6 +280,7 @@ def customer_pre_save(sender, **kwargs):
if customer.represent_this_buyinggroup: if customer.represent_this_buyinggroup:
# The buying group may not be de activated # The buying group may not be de activated
customer.is_active = True customer.is_active = True
customer.is_group = False
if customer.email2 is not None: if customer.email2 is not None:
customer.email2 = customer.email2.lower() customer.email2 = customer.email2.lower()
if customer.vat_id is not None and len(customer.vat_id.strip()) == 0: if customer.vat_id is not None and len(customer.vat_id.strip()) == 0:
...@@ -307,6 +309,9 @@ def customer_pre_save(sender, **kwargs): ...@@ -307,6 +309,9 @@ def customer_pre_save(sender, **kwargs):
customer.bank_account2 = None customer.bank_account2 = None
if not customer.is_active: if not customer.is_active:
customer.may_order = False customer.may_order = False
if customer.is_group:
customer.may_order = False
customer.delivery_point = None
if customer.price_list_multiplier <= DECIMAL_ZERO: if customer.price_list_multiplier <= DECIMAL_ZERO:
customer.price_list_multiplier = DECIMAL_ONE customer.price_list_multiplier = DECIMAL_ONE
if customer.delivery_point is not None and customer.delivery_point.customer_responsible is not None: if customer.delivery_point is not None and customer.delivery_point.customer_responsible is not None:
......
...@@ -209,14 +209,21 @@ class Permanence(TranslatableModel): ...@@ -209,14 +209,21 @@ class Permanence(TranslatableModel):
link = [] link = []
for ci in invoice.CustomerInvoice.objects.filter(permanence_id=self.id).select_related( for ci in invoice.CustomerInvoice.objects.filter(permanence_id=self.id).select_related(
"customer").order_by('customer'): "customer").order_by('customer'):
ci_customer = ci.customer
if ci.is_order_confirm_send: if ci.is_order_confirm_send:
label = '%s (%s) %s' % ( label = '%s%s (%s) %s%s' % (
"<b><i>" if ci_customer.is_group else EMPTY_STRING,
ci.customer.short_basket_name, ci.get_total_price_with_tax(customer_who_pays=True), ci.customer.short_basket_name, ci.get_total_price_with_tax(customer_who_pays=True),
ci.get_is_order_confirm_send_display()) ci.get_is_order_confirm_send_display(),
"</i></b>" if ci_customer.is_group else EMPTY_STRING,
)
else: else:
label = '%s (%s) %s' % ( label = '%s%s (%s) %s%s' % (
"<b><i>" if ci_customer.is_group else EMPTY_STRING,
ci.customer.short_basket_name, ci.total_price_with_tax, ci.customer.short_basket_name, ci.total_price_with_tax,
ci.get_is_order_confirm_send_display()) ci.get_is_order_confirm_send_display(),
"</i></b>" if ci_customer.is_group else EMPTY_STRING,
)
# Important : no target="_blank" # Important : no target="_blank"
link.append( link.append(
'<a href="%s?permanence=%d&customer=%d">%s</a>' '<a href="%s?permanence=%d&customer=%d">%s</a>'
...@@ -226,10 +233,13 @@ class Permanence(TranslatableModel): ...@@ -226,10 +233,13 @@ class Permanence(TranslatableModel):
link = [] link = []
for ci in invoice.CustomerInvoice.objects.filter(permanence_id=self.id).select_related( for ci in invoice.CustomerInvoice.objects.filter(permanence_id=self.id).select_related(
"customer").order_by('customer'): "customer").order_by('customer'):
label = "%s (%s) %s" % ( ci_customer = ci.customer
ci.customer.short_basket_name, label = "%s%s (%s) %s%s" % (
"<b><i>" if ci_customer.is_group else EMPTY_STRING,
ci_customer.short_basket_name,
ci.get_total_price_with_tax(customer_who_pays=True), ci.get_total_price_with_tax(customer_who_pays=True),
ci.get_is_order_confirm_send_display() ci.get_is_order_confirm_send_display(),
"</i></b>" if ci_customer.is_group else EMPTY_STRING,
) )
# Important : target="_blank" because the invoices must be displayed without the cms_toolbar # Important : target="_blank" because the invoices must be displayed without the cms_toolbar
# Such that they can be accessed by the customer and by the staff # Such that they can be accessed by the customer and by the staff
......
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