Improve contact name handling for new custorder

This commit is contained in:
Lance Edgar 2021-10-07 12:33:52 -04:00
parent c611eb3787
commit 5e339bb7ea
3 changed files with 45 additions and 19 deletions

View file

@ -342,8 +342,13 @@
<div v-if="!contactIsKnown" <div v-if="!contactIsKnown"
style="padding-left: 10rem; display: flex;"> style="padding-left: 10rem; display: flex;">
<div> <div>
<b-field label="Customer Name"> <b-field grouped>
<span>{{ newCustomerName }}</span> <b-field label="First Name">
<span>{{ newCustomerFirstName }}</span>
</b-field>
<b-field label="Last Name">
<span>{{ newCustomerLastName }}</span>
</b-field>
</b-field> </b-field>
<b-field grouped> <b-field grouped>
<b-field label="Phone Number"> <b-field label="Phone Number">
@ -381,11 +386,17 @@
</header> </header>
<section class="modal-card-body"> <section class="modal-card-body">
<b-field label="Customer Name"> <b-field grouped>
<b-input v-model="editNewCustomerName" <b-field label="First Name">
<b-input v-model="editNewCustomerFirstName"
ref="editNewCustomerInput"> ref="editNewCustomerInput">
</b-input> </b-input>
</b-field> </b-field>
<b-field label="Last Name">
<b-input v-model="editNewCustomerLastName">
</b-input>
</b-field>
</b-field>
<b-field grouped> <b-field grouped>
<b-field label="Phone Number"> <b-field label="Phone Number">
<b-input v-model="editNewCustomerPhone"></b-input> <b-input v-model="editNewCustomerPhone"></b-input>
@ -674,13 +685,15 @@
% endif % endif
newCustomerName: ${json.dumps(new_customer_name)|n}, newCustomerFirstName: ${json.dumps(new_customer_first_name)|n},
newCustomerLastName: ${json.dumps(new_customer_last_name)|n},
newCustomerPhone: ${json.dumps(new_customer_phone)|n}, newCustomerPhone: ${json.dumps(new_customer_phone)|n},
newCustomerEmail: ${json.dumps(new_customer_email)|n}, newCustomerEmail: ${json.dumps(new_customer_email)|n},
contactNotes: ${json.dumps(contact_notes)|n}, contactNotes: ${json.dumps(contact_notes)|n},
editNewCustomerShowDialog: false, editNewCustomerShowDialog: false,
editNewCustomerName: null, editNewCustomerFirstName: null,
editNewCustomerLastName: null,
editNewCustomerPhone: null, editNewCustomerPhone: null,
editNewCustomerEmail: null, editNewCustomerEmail: null,
editNewCustomerSaving: false, editNewCustomerSaving: false,
@ -718,8 +731,8 @@
} }
} }
} else { } else {
if (this.newCustomerName) { if (this.contactDisplay) {
text = "Customer: " + this.newCustomerName text = "Customer: " + this.contactDisplay
} }
} }
@ -772,7 +785,7 @@
} }
phoneNumber = this.orderPhoneNumber phoneNumber = this.orderPhoneNumber
} else { // customer is not known } else { // customer is not known
if (!this.newCustomerName) { if (!this.contactDisplay) {
return { return {
type: 'is-danger', type: 'is-danger',
text: "Please identify the customer.", text: "Please identify the customer.",
@ -850,7 +863,7 @@
if (this.editNewCustomerSaving) { if (this.editNewCustomerSaving) {
return true return true
} }
if (!this.editNewCustomerName) { if (!(this.editNewCustomerFirstName && this.editNewCustomerLastName)) {
return true return true
} }
if (!(this.editNewCustomerPhone || this.editNewCustomerEmail)) { if (!(this.editNewCustomerPhone || this.editNewCustomerEmail)) {
@ -1147,7 +1160,8 @@
% endif % endif
editNewCustomerInit() { editNewCustomerInit() {
this.editNewCustomerName = this.newCustomerName this.editNewCustomerFirstName = this.newCustomerFirstName
this.editNewCustomerLastName = this.newCustomerLastName
this.editNewCustomerPhone = this.newCustomerPhone this.editNewCustomerPhone = this.newCustomerPhone
this.editNewCustomerEmail = this.newCustomerEmail this.editNewCustomerEmail = this.newCustomerEmail
this.editNewCustomerShowDialog = true this.editNewCustomerShowDialog = true
@ -1161,14 +1175,17 @@
let params = { let params = {
action: 'update_pending_customer', action: 'update_pending_customer',
display_name: this.editNewCustomerName, first_name: this.editNewCustomerFirstName,
last_name: this.editNewCustomerLastName,
phone_number: this.editNewCustomerPhone, phone_number: this.editNewCustomerPhone,
email_address: this.editNewCustomerEmail, email_address: this.editNewCustomerEmail,
} }
this.submitBatchData(params, response => { this.submitBatchData(params, response => {
if (response.data.success) { if (response.data.success) {
this.newCustomerName = response.data.new_customer_name this.contactDisplay = response.data.new_customer_name
this.newCustomerFirstName = response.data.new_customer_first_name
this.newCustomerLastName = response.data.new_customer_last_name
this.newCustomerPhone = response.data.phone_number this.newCustomerPhone = response.data.phone_number
this.orderPhoneNumber = response.data.phone_number this.orderPhoneNumber = response.data.phone_number
this.newCustomerEmail = response.data.email_address this.newCustomerEmail = response.data.email_address

View file

@ -48,7 +48,7 @@ class CustomerOrderBatchView(BatchMasterView):
grid_columns = [ grid_columns = [
'id', 'id',
'customer', 'contact_name',
'rowcount', 'rowcount',
'total_price', 'total_price',
'created', 'created',
@ -98,7 +98,7 @@ class CustomerOrderBatchView(BatchMasterView):
g.set_type('total_price', 'currency') g.set_type('total_price', 'currency')
g.set_link('customer') g.set_link('contact_name')
g.set_link('created') g.set_link('created')
g.set_link('created_by') g.set_link('created_by')

View file

@ -405,7 +405,7 @@ class CustomerOrderView(MasterView):
'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,
'contact_display': self.handler.get_contact_display(batch), 'contact_display': batch.contact_name,
'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_emails': self.handler.get_contact_emails(batch),
@ -414,6 +414,8 @@ class CustomerOrderView(MasterView):
'add_email_address': bool(batch.get_param('add_email_address')), 'add_email_address': bool(batch.get_param('add_email_address')),
'contact_profile_url': None, 'contact_profile_url': None,
'new_customer_name': None, 'new_customer_name': None,
'new_customer_first_name': None,
'new_customer_last_name': None,
'new_customer_phone': None, 'new_customer_phone': None,
'new_customer_email': None, 'new_customer_email': None,
} }
@ -421,6 +423,8 @@ class CustomerOrderView(MasterView):
pending = batch.pending_customer pending = batch.pending_customer
if pending: if pending:
context.update({ context.update({
'new_customer_first_name': pending.first_name,
'new_customer_last_name': pending.last_name,
'new_customer_name': pending.display_name, 'new_customer_name': pending.display_name,
'new_customer_phone': pending.phone_number, 'new_customer_phone': pending.phone_number,
'new_customer_email': pending.email_address, 'new_customer_email': pending.email_address,
@ -486,6 +490,7 @@ class CustomerOrderView(MasterView):
def update_pending_customer(self, batch, data): def update_pending_customer(self, batch, data):
model = self.model model = self.model
app = self.get_rattail_app() app = self.get_rattail_app()
people = app.get_people_handler()
# clear out any contact it may have # clear out any contact it may have
self.handler.unassign_contact(batch) self.handler.unassign_contact(batch)
@ -499,11 +504,15 @@ class CustomerOrderView(MasterView):
batch.pending_customer = pending batch.pending_customer = pending
# update pending customer info # update pending customer info
pending.display_name = data['display_name'] pending.first_name = data['first_name']
pending.last_name = data['last_name']
pending.display_name = people.normalize_full_name(pending.first_name,
pending.last_name)
pending.phone_number = app.format_phone_number(data['phone_number']) pending.phone_number = app.format_phone_number(data['phone_number'])
pending.email_address = data['email_address'] pending.email_address = data['email_address']
# also update the batch w/ contact info # also update the batch w/ contact info
batch.contact_name = pending.display_name
batch.phone_number = pending.phone_number batch.phone_number = pending.phone_number
batch.email_address = pending.email_address batch.email_address = pending.email_address