255
255
# set the stock/expense account into the configuration
256
256
set_config_item("LAST_STOCK_ACCOUNT_ID", self.invoice.account.id)
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
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
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
269
# self.transaction_list is a list of lists [account, debit, credit]
270
# account being an account object, debit and credit being decimal objects
272
# Purchase account: either an asset (stock) to be bought or an expense to be paid
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 ]
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)
274
# Debit the Stock/Expense account by the cost
275
if self.invoice.cost:
276
transaction.add(self.invoice.account, debit = self.invoice.cost)
278
# Debit the VAT Balance account by the VAT amount
280
transaction.add(get_account_by_system(5), debit = self.invoice.vat)
282
status, message = transaction.check()
284
vs_message(self, message, "ERROR")
281
# Stock/Expense account Debit by the cost Credit by zero
282
t2 = [ self.invoice.account, self.invoice.cost, D("0.00") ]
284
self.transaction_list = [t1, t2]
286
if self.invoice.vat != D(0):
287
# If VAT is being paid, store it in the VAT owed Account
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") ]
293
vs_message(self, "The VAT owed account cannot be found", "ERROR")
296
self.transaction_list.append(t3)
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)
305
292
vs_message(self, "The invoice not been saved", "CANCELLED")
295
transaction.description = new_description
308
297
# Must now implement the transaction and save the supplier invoice
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)
317
303
vs_message(self, "Supplier invoice saved", "DONE")