133
131
button_sizer.Add(new_customer_text, 0, wx.LEFT | wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 20)
135
133
# Edit a customer
136
self.all_customers = Customer.get_all()
137
customer_list = [ customer.name for customer in self.all_customers ]
140
self.edit_customer_choice = wx.Choice(self, -1, size=button_size, choices=customer_list)
141
# set selection to last item on list - looks best under gnome
142
self.edit_customer_choice.SetSelection(len(customer_list)-1)
144
self.edit_customer_choice = wx.Choice(self, -1, size=button_size, choices=[" "])
145
self.edit_customer_choice.SetSelection(0)
146
self.edit_customer_choice.SetToolTipString("Choose to edit a customer details")
148
button_sizer.Add(self.edit_customer_choice, 0, wx.ALIGN_RIGHT)
150
# Edit, contacts and banking buttons for this customer
151
eandc_sizer = wx.BoxSizer(wx.HORIZONTAL)
153
self.edit_customer_button = wx.Button(self, label="Edit", size=wx.DefaultSize)
154
self.edit_customer_button.SetToolTipString("Press to edit the chosen customer")
155
eandc_sizer.Add(self.edit_customer_button, 0, wx.ALIGN_LEFT)
157
self.contacts_button = wx.Button(self, label="Contacts", size=wx.DefaultSize)
158
self.contacts_button.SetToolTipString("Edit and list contacts for the chosen customer")
159
eandc_sizer.Add(self.contacts_button, 0, wx.LEFT | wx.ALIGN_LEFT, 20)
161
self.bank_button = wx.Button(self, label="Bank", size=wx.DefaultSize)
162
self.bank_button.SetToolTipString("Edit and show bank details for the chosen customer")
163
eandc_sizer.Add(self.bank_button, 0, wx.LEFT | wx.ALIGN_LEFT, 20)
165
button_sizer.Add(eandc_sizer, 0, wx.LEFT | wx.ALIGN_LEFT, 20)
134
self.edit_customer_button = wx.Button(self, label="Edit customer", size=button_size)
135
self.edit_customer_button.SetToolTipString("Press to edit a customer details")
136
button_sizer.Add(self.edit_customer_button, 0, wx.ALIGN_RIGHT)
137
edit_customer_text=wx.StaticText(self, -1, "Press to edit a customer")
138
button_sizer.Add(edit_customer_text, 0, wx.LEFT | wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 20)
167
140
# sort out which buttons are enabled or not
170
143
sizer.Add(button_sizer, 0, wx.TOP | wx.ALIGN_CENTER, 20)
173
Choose a customer and press Edit to change or add further invoice or delivery
174
addresses. Press Contacts or Bank to optionally store further customer details."""
176
self.bottom_text=wx.StaticText(self, -1, help2_text)
177
sizer.Add(self.bottom_text, 0, wx.ALL | wx.ALIGN_CENTER, 20)
179
145
# Set the size to the panel
180
146
self.SetSizer(sizer)
189
155
self.Bind(wx.EVT_BUTTON, self.item_button_pressed, self.item_button)
190
156
self.Bind(wx.EVT_BUTTON, self.new_customer_button_pressed, self.new_customer_button)
191
157
self.Bind(wx.EVT_BUTTON, self.edit_customer_button_pressed, self.edit_customer_button)
192
self.Bind(wx.EVT_BUTTON, self.contacts_button_pressed, self.contacts_button)
193
self.Bind(wx.EVT_BUTTON, self.bank_button_pressed, self.bank_button)
196
def get_customer(self):
197
"returns the customer currently shown"
198
if not self.all_customers: return None
199
customer_selected_list_item = self.edit_customer_choice.GetCurrentSelection()
200
assert customer_selected_list_item != -1
201
return self.all_customers[customer_selected_list_item]
204
160
# ----------------- Handler functions
253
209
def edit_customer_button_pressed(self, event):
254
"Create and show the EditOrganizationDialog to edit an existing customer"
255
customer = self.get_customer()
256
if not customer: return
257
organization.edit_organization_dialog(self, customer)
261
def contacts_button_pressed(self, event):
262
"View and edit the contacts for this customer"
263
customer = self.get_customer()
264
if not customer: return
265
view_contacts.view_contacts_dialog(self, customer)
269
def bank_button_pressed(self, event):
270
"Create and show the BankDetailsDialog to edit bank info for an existing customer"
271
customer = self.get_customer()
272
if not customer: return
273
view_bank.bank_details_dialog(self, customer)
276
def refresh_list(self, select_customer=None):
277
"Refresh list and set selection to select_customer"
278
all_customers = Customer.get_all()
279
if not all_customers:
280
# empty list, no customer has been created yet
281
self.edit_customer_choice.Enable(False)
282
self.edit_customer_button.Enable(False)
283
self.contacts_button.Enable(False)
284
self.bank_button.Enable(False)
285
# refresh customer selection
286
self.edit_customer_choice.Clear()
287
self.edit_customer_choice.AppendItems(" ")
288
self.edit_customer_choice.SetSelection(0)
289
self.all_customers = []
292
if select_customer is None:
293
# Get the current customer shown
294
select_customer = self.get_customer()
296
# A new customer may have been added
297
self.edit_customer_choice.Clear()
298
self.all_customers = all_customers
301
customer_list = [customer.name for customer in self.all_customers]
302
self.edit_customer_choice.AppendItems(customer_list)
304
for index, customer in enumerate(self.all_customers):
305
if select_customer == customer:
306
self.edit_customer_choice.SetSelection(index)
310
self.edit_customer_choice.SetSelection(len(customer_list)-1)
313
self.edit_customer_choice.Enable(True)
314
self.edit_customer_button.Enable(True)
315
self.contacts_button.Enable(True)
316
self.bank_button.Enable(True)
210
"Create and show the dialog to edit an existing customer"
211
organization.choose_customer_dialog(self)
319
214
def refresh(self):
322
217
self.view_invoices_button.Enable(False)
323
218
self.credit_note_button.Enable(False)
324
219
self.view_credit_notes_button.Enable(False)
325
# refresh customer list and customer buttons
220
self.edit_customer_button.Enable(False)
222
self.all_customers = Customer.get_all()
327
223
if self.all_customers:
224
self.edit_customer_button.Enable(True)
328
225
# Check registered address is complete
329
226
company = Company()
330
227
# Get the current VAT Scheme