Add "restrict contact info" feature for new custorder batch

also add support for choosing from existing emails
This commit is contained in:
Lance Edgar 2021-10-06 12:32:13 -04:00
parent 9b6113a4c8
commit 0237d8c31a
2 changed files with 102 additions and 47 deletions

View file

@ -155,7 +155,8 @@
<div class="level-item">
{{ orderPhoneNumber }}
</div>
<div class="level-item">
<div class="level-item"
v-if="contactPhones.length &gt; 1">
<b-button type="is-primary"
@click="editPhoneNumberInit()"
icon-pack="fas"
@ -185,6 +186,7 @@
</b-radio>
</b-field>
% if not restrict_contact_info:
<b-field>
<b-radio v-model="existingPhoneUUID"
:native-value="null">
@ -201,6 +203,7 @@
add this phone number to customer record
</b-checkbox>
</b-field>
% endif
</section>
@ -236,7 +239,8 @@
(no valid email on file)
</span>
</div>
<div class="level-item">
<div class="level-item"
v-if="contactEmails.length &gt; 1">
<b-button type="is-primary"
@click="editEmailAddressInit()"
icon-pack="fas"
@ -252,12 +256,38 @@
</header>
<section class="modal-card-body">
<b-field label="Email Address"
:type="editEmailAddressValue ? null : 'is-danger'">
<b-input v-model="editEmailAddressValue"
ref="editEmailAddressInput">
</b-input>
<b-field v-for="email in contactEmails"
:key="email.uuid">
<b-radio v-model="existingEmailUUID"
:native-value="email.uuid">
{{ email.type }} {{ email.address }}
<span v-if="email.preferred"
class="is-italic">
(preferred)
</span>
</b-radio>
</b-field>
% if not restrict_contact_info:
<b-field>
<b-radio v-model="existingEmailUUID"
:native-value="null">
other
</b-radio>
</b-field>
<b-field v-if="!existingEmailUUID"
grouped>
<b-input v-model="otherEmailAddress">
</b-input>
<b-checkbox v-model="addOtherEmailAddress"
disabled>
add this email address to customer record
</b-checkbox>
</b-field>
% endif
</section>
<footer class="modal-card-foot">
@ -545,7 +575,7 @@
% else:
contactUUID: ${json.dumps(batch.person_uuid)|n},
% endif
contactDisplay: ${json.dumps(six.text_type(batch.customer or ''))|n},
contactDisplay: ${json.dumps(contact_display)|n},
customerEntry: null,
contactProfileURL: ${json.dumps(contact_profile_url)|n},
@ -557,15 +587,18 @@
editPhoneNumberShowDialog: false,
editPhoneNumberSaving: false,
orderEmailAddress: ${json.dumps(batch.email_address)|n},
contactEmails: ${json.dumps(contact_emails)|n},
existingEmailUUID: null,
otherEmailAddress: null,
addOtherEmailAddress: false,
editEmailAddressShowDialog: false,
editEmailAddressSaving: false,
customerName: null,
phoneNumber: null,
orderEmailAddress: ${json.dumps(batch.email_address)|n},
contactNotes: ${json.dumps(contact_notes)|n},
editEmailAddressShowDialog: false,
editEmailAddressValue: null,
editEmailAddressSaving: false,
items: ${json.dumps(order_items)|n},
editingItem: null,
showingItemDialog: false,
@ -710,7 +743,7 @@
if (this.editEmailAddressSaving) {
return true
}
if (!this.editEmailAddressValue) {
if (!this.existingEmailUUID && !this.otherEmailAddress) {
return true
}
return false
@ -870,6 +903,7 @@
that.orderEmailAddress = response.data.email_address
that.contactProfileURL = response.data.contact_profile_url
that.contactPhones = response.data.contact_phones
that.contactEmails = response.data.contact_emails
that.contactNotes = response.data.contact_notes
})
},
@ -931,11 +965,18 @@
},
editEmailAddressInit() {
this.editEmailAddressValue = this.orderEmailAddress
this.existingEmailUUID = null
let normalOrderEmail = (this.orderEmailAddress || '').toLowerCase()
for (let email of this.contactEmails) {
let normal = email.address.toLowerCase()
if (normal == normalOrderEmail) {
this.existingEmailUUID = email.uuid
break
}
}
this.otherEmailAddress = this.existingEmailUUID ? null : this.orderEmailAddress
this.editEmailAddressShowDialog = true
this.$nextTick(() => {
this.$refs.editEmailAddressInput.focus()
})
},
editEmailAddressSave() {
@ -943,7 +984,21 @@
let params = {
action: 'update_email_address',
email_address: this.editEmailAddressValue,
email_address: null,
}
if (this.existingEmailUUID) {
for (let email of this.contactEmails) {
if (email.uuid == this.existingEmailUUID) {
params.email_address = email.address
break
}
}
}
if (!params.email_address) {
params.email_address = this.otherEmailAddress
// params.add_email_address = this.addOtherEmailAddress
}
this.submitBatchData(params, response => {
@ -959,7 +1014,6 @@
}
this.editEmailAddressSaving = false
})
},
showAddItemDialog() {

View file

@ -255,7 +255,10 @@ class CustomerOrderView(MasterView):
context = {'batch': batch,
'normalized_batch': self.normalize_batch(batch),
'new_order_requires_customer': self.handler.new_order_requires_customer(),
'restrict_contact_info': self.handler.should_restrict_contact_info(),
'contact_display': self.handler.get_contact_display(batch),
'contact_phones': self.handler.get_contact_phones(batch),
'contact_emails': self.handler.get_contact_emails(batch),
'contact_profile_url': None,
'contact_notes': self.handler.get_contact_notes(batch),
'order_items': items,
@ -387,13 +390,19 @@ class CustomerOrderView(MasterView):
except ValueError as error:
return {'error': six.text_type(error)}
self.Session.flush()
context = self.get_context_contact(batch)
context['success'] = True
return context
def get_context_contact(self, batch):
context = {
'success': True,
'customer_uuid': batch.customer_uuid,
'person_uuid': batch.person_uuid,
'phone_number': batch.phone_number,
'email_address': batch.email_address,
'contact_phones': self.handler.get_contact_phones(batch),
'contact_emails': self.handler.get_contact_emails(batch),
'contact_notes': self.handler.get_contact_notes(batch),
}
@ -407,17 +416,9 @@ class CustomerOrderView(MasterView):
def unassign_contact(self, batch, data):
self.handler.unassign_contact(batch)
context = {
'success': True,
'customer_uuid': batch.customer_uuid,
'person_uuid': batch.person_uuid,
'phone_number': batch.phone_number,
'email_address': batch.email_address,
'contact_profile_url': None,
'contact_notes': self.handler.get_contact_notes(batch),
}
self.Session.flush()
context = self.get_context_contact(batch)
context['success'] = True
return context
def update_phone_number(self, batch, data):