~bernie/vatstuff/main

« back to all changes in this revision

Viewing changes to vatstuff_packages/vs_gui/sales/sales_tab.py

  • Committer: bernie
  • Date: 2010-10-05 20:40:15 UTC
  • Revision ID: bernie@packardbell-20101005204015-0ptiur1ls32cf6xj
added customer and supplier pickers

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
from vatstuff_packages.vs_gui.sales import view_invoices
45
45
from vatstuff_packages.vs_gui.sales import view_creditnotes
46
46
 
47
 
from vatstuff_packages.vs_gui import view_contacts
48
 
from vatstuff_packages.vs_gui import view_bank
49
47
from vatstuff_packages.vs_gui import organization
50
48
from vatstuff_packages.vs_gui import add_item
51
49
 
133
131
        button_sizer.Add(new_customer_text, 0, wx.LEFT | wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 20)
134
132
 
135
133
        # Edit a customer
136
 
        self.all_customers = Customer.get_all()
137
 
        customer_list = [ customer.name for customer in self.all_customers ]
138
 
 
139
 
        if customer_list:
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)
143
 
        else:
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") 
147
 
 
148
 
        button_sizer.Add(self.edit_customer_choice, 0, wx.ALIGN_RIGHT)
149
 
 
150
 
        # Edit, contacts and banking buttons for this customer
151
 
        eandc_sizer = wx.BoxSizer(wx.HORIZONTAL)
152
 
 
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)
156
 
 
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)
160
 
 
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)
164
 
 
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)
166
139
 
167
140
        # sort out which buttons are enabled or not
168
141
        self.refresh()
169
142
 
170
143
        sizer.Add(button_sizer, 0, wx.TOP | wx.ALIGN_CENTER, 20)
171
 
 
172
 
        help2_text="""\
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."""
175
 
        
176
 
        self.bottom_text=wx.StaticText(self, -1, help2_text)
177
 
        sizer.Add(self.bottom_text, 0, wx.ALL | wx.ALIGN_CENTER, 20)
178
144
        
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)
194
 
 
195
 
 
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]
202
158
 
203
159
 
204
160
    # ----------------- Handler functions
206
162
    @button_wrap
207
163
    def inv_button_pressed(self, event):
208
164
        "Invoice button pressed, create and show the invoice dialog"
209
 
        customer = self.get_customer()
 
165
        customer = get_last_customer()
210
166
        if not customer: return
211
167
        make_invoice.invoice_dialog(self, customer)
212
168
 
226
182
    @button_wrap
227
183
    def credit_note_button_pressed(self, event):
228
184
        "Create a credit note button pressed, show the SendCreditNoteDialog"
229
 
        customer = self.get_customer()
 
185
        customer = get_last_customer()
230
186
        if not customer: return
231
187
        send_creditnote_dialog(self, customer)
232
188
 
251
207
 
252
208
    @button_wrap
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)
258
 
 
259
 
 
260
 
    @button_wrap
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)
266
 
 
267
 
 
268
 
    @button_wrap
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)
274
 
 
275
 
 
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 = []
290
 
            return
291
 
 
292
 
        if select_customer is None:
293
 
            # Get the current customer shown
294
 
            select_customer = self.get_customer()
295
 
 
296
 
        # A new customer may have been added
297
 
        self.edit_customer_choice.Clear()
298
 
        self.all_customers = all_customers
299
 
 
300
 
        # Set up new list
301
 
        customer_list = [customer.name for customer in self.all_customers]
302
 
        self.edit_customer_choice.AppendItems(customer_list)
303
 
 
304
 
        for index, customer in enumerate(self.all_customers):
305
 
            if select_customer == customer:
306
 
                self.edit_customer_choice.SetSelection(index)
307
 
                break
308
 
        else:
309
 
            # Choose last
310
 
            self.edit_customer_choice.SetSelection(len(customer_list)-1)
311
 
 
312
 
        # enable buttons
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)
317
212
 
318
213
 
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
326
 
        self.refresh_list()
 
220
        self.edit_customer_button.Enable(False)
 
221
        # refresh buttons
 
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