~bernie/vatstuff/main

« back to all changes in this revision

Viewing changes to vatstuff_packages/vs_gui/accounts/new_account.py

  • Committer: Bernard Czenkusz
  • Date: 2010-09-27 12:31:40 UTC
  • Revision ID: bernie@bernie-desktop-20100927123140-fu5oyqobrcd64d9t
Further refactoring on transactions
creditnotes transactions now done

Show diffs side-by-side

added added

removed removed

Lines of Context:
74
74
        # Create the sizer
75
75
        sizer=wx.BoxSizer(wx.VERTICAL)
76
76
 
77
 
        # Store the opening transaction in a TransactionForm object
78
 
        self.transaction = form_objects.TransactionForm()
79
 
 
80
77
        # Create the input labels and fields in a grid sizer
81
78
        fields_sizer=wx.FlexGridSizer(rows=5, cols=2, hgap=20, vgap=20)
82
79
 
262
259
    def set_opening_balance(self, balance, datestamp):
263
260
        """Creates a transaction to set the opening balance"""
264
261
 
265
 
        self.transaction.description = "%s opening balance" % self.account.fullname
266
 
        self.transaction.datestamp = datestamp
 
262
        # Store the opening transaction in a TransactionForm object
 
263
        transaction = form_objects.TransactionForm()
 
264
 
 
265
        transaction.description = "%s opening balance" % self.account.fullname
 
266
        transaction.datestamp = datestamp
267
267
        # This is an opening balance transaction (system type 1)
268
 
        self.transaction.system = 1
 
268
        transaction.system = 1
269
269
 
270
270
        # Get the system opening balances account - this being the account with system = 2
271
271
        op_account = get_account_by_system(2)
272
272
 
273
 
        # Ensure the transaction.trans_list is empty
274
 
        self.transaction.clear()
275
 
 
276
273
        # If balance is greater than zero, then debit the account by the
277
274
        # balance, otherwise credit it
278
275
        if balance > D(0):
279
 
            self.transaction.add(self.account, debit=balance)
280
 
            self.transaction.add(op_account, credit=balance)
 
276
            transaction.add(self.account, debit=balance)
 
277
            transaction.add(op_account, credit=balance)
281
278
        else:
282
279
            balance = abs(balance)
283
 
            self.transaction.add(self.account, credit=balance)
284
 
            self.transaction.add(op_account, debit=balance)
 
280
            transaction.add(self.account, credit=balance)
 
281
            transaction.add(op_account, debit=balance)
285
282
 
286
 
        status, message = self.transaction.check()
 
283
        status, message = transaction.check()
287
284
        if not status:
288
285
            return False, message
289
286
 
290
287
        # In this case do not confirm the transaction - as doing so does not add any value
291
288
 
292
289
        # Must now implement the opening balance transaction
293
 
        transaction_id = transactions.implement(None, self.transaction)
 
290
        transactions.implement(None, transaction)
294
291
 
295
292
        info_log("opening balance set")
296
293
        return True, None