~bernie/vatstuff/main

« back to all changes in this revision

Viewing changes to vatstuff_packages/vs_gui/purchases/supplier_invoice.py

  • Committer: bernie
  • Date: 2010-09-28 16:48:32 UTC
  • Revision ID: bernie@packardbell-20100928164832-78lh6f61pp7ilnm1
Done transactions for closing and cancelling an order, and for
receiving a supplier invoice

Show diffs side-by-side

added added

removed removed

Lines of Context:
255
255
        # set the stock/expense account into the configuration
256
256
        set_config_item("LAST_STOCK_ACCOUNT_ID", self.invoice.account.id)
257
257
 
258
 
        # Create transaction_text, transaction_list, transaction_date
259
 
        # to send to the ConfirmTransactionDialog
 
258
        # Store the transaction in a TransactionForm object
 
259
        transaction = form_objects.TransactionForm()
 
260
        # This is a supplier invoice transaction(system type 9)
 
261
        transaction.system = 9
260
262
 
261
 
        self.transaction_text = "Invoice received from %s" % self.invoice.supplier.name
262
 
        self.transaction_date = self.invoice.datestamp
 
263
        transaction.description = "Invoice received from %s" % self.invoice.supplier.name
 
264
        transaction.datestamp = self.invoice.datestamp
263
265
 
264
266
        # Note, the transaction datestamp and invoice datestamp is the same value leading
265
267
        # to duplication in the database, however this is left in - in case it is necessary
266
268
        # to create a date of issue and taxpoint date - which it is currently thought is
267
269
        # not required 
268
270
 
269
 
        # self.transaction_list is a list of lists [account, debit, credit]
270
 
        # account being an account object, debit and credit being decimal objects
271
 
 
272
 
        # Purchase account: either an asset (stock) to be bought or an expense to be paid
273
 
 
274
 
        #     The purchase account       Debit by zero    Credit by the cost plus vat of the invoice
275
 
        t1 = [get_account_by_system(7),  D("0.00"),      self.invoice.cost + self.invoice.vat ]
276
 
 
277
 
        if not t1[0]:
278
 
            vs_message(self, "A Purchases account was not found", "ERROR")
 
271
        # Credit the purchase account by the cost plus vat of the invoice
 
272
        transaction.add(get_account_by_system(7), credit = self.invoice.cost + self.invoice.vat)
 
273
 
 
274
        # Debit the Stock/Expense account by the cost
 
275
        if self.invoice.cost:
 
276
            transaction.add(self.invoice.account, debit = self.invoice.cost)
 
277
 
 
278
        # Debit the VAT Balance account by the VAT amount
 
279
        if self.invoice.vat:
 
280
            transaction.add(get_account_by_system(5), debit = self.invoice.vat)
 
281
 
 
282
        status, message = transaction.check()
 
283
        if not status:
 
284
            vs_message(self, message, "ERROR")
279
285
            return
280
286
 
281
 
        #    Stock/Expense account    Debit by the cost   Credit by zero
282
 
        t2 = [ self.invoice.account,  self.invoice.cost,  D("0.00") ]
283
 
 
284
 
        self.transaction_list = [t1, t2]
285
 
 
286
 
        if self.invoice.vat != D(0):
287
 
            # If VAT is being paid, store it in the VAT owed Account
288
 
 
289
 
            #    VAT owed account             Debit by the VAT amount  Credit by zero
290
 
            t3 = [ get_account_by_system(5),  self.invoice.vat,        D("0.00") ]
291
 
 
292
 
            if not t3[0]:
293
 
                vs_message(self, "The VAT owed account cannot be found", "ERROR")
294
 
                return
295
 
 
296
 
            self.transaction_list.append(t3)
297
 
 
298
287
        wx.Yield()
299
288
        # Confirm the transaction (function and dialog in gui_functions)
300
 
        status, self.transaction_text = confirm_transaction(self,
301
 
                                                            self.transaction_text,
302
 
                                                            self.transaction_list,
303
 
                                                            self.transaction_date)
 
289
        status, new_description = confirm_transaction(self, transaction)
 
290
 
304
291
        if not status:
305
292
            vs_message(self, "The invoice not been saved", "CANCELLED")
306
293
            return
307
294
 
 
295
        transaction.description = new_description
 
296
 
308
297
        # Must now implement the transaction and save the supplier invoice
309
298
        busy_cursor_on()
310
299
        wx.Yield()
311
 
        save_supplierinvoice.save(self.invoice,
312
 
                                    self.transaction_date,
313
 
                                    self.transaction_text,
314
 
                                    self.transaction_list)
 
300
        save_supplierinvoice.save(self.invoice, transaction)
315
301
 
316
302
        big_refresh()
317
303
        vs_message(self, "Supplier invoice saved", "DONE")