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

View file

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