Sunday, September 10, 2006

Rails and the initialize() method

I spent a bit of time this weekend on a pet rails project. I came across a strange error when trying to create new records through the application. Editing was working just fine, but creating a new record just seemed to hang.

Breakpoints came to my rescue. In Ruby, they're really handy. You can put a 'breakpoint' call anywhere in your code, and if you have a breakpointer process running (start this with the command 'ruby script/breakpointer'), you jump straight into an interactive ruby console debug session when the breakpoint is hit.

Using the development log and a few breakpoints, I found the that the error was:
ArgumentError: wrong number of arguments (1 for 0)
And that it was caused by a line similar to this:
@order = order.new(params[:order])
Ie, the controller was creating a new order from the post parameters.

Then all became clear - some time earlier, I'd overridden the initialize() method in the order to default some dates. My code was similar to this:
def initialize
super()

if (@new_record)
self.validFrom = Date.today
self.validTo = 1.year.from_now.to_date
end
end

Great for creating new objects in my tests and console sessions where I always just created the object and then set properties. However, the controller was relying on passing in the post parameters in the constructor.

The solution is to accept any number of params and pass these to the base class:
def initialize(*params)
super(*params)

if (@new_record)
self.validFrom = Date.today
self.validTo = 1.year.from_now.to_date
end
end

That way, the order can accept the post parameters in its constructor.

I'm very pleased to say that I can now create new records again!

Wednesday, September 06, 2006

How to do Tax Deductions for an Investment Property in NSW, Australia

Last year I bought a house. Recently, I've been doing my tax. It is much more complex this year with the property, but there are a lot more deductions. Here's some tips:

Renting a out part of your property
If you rent some of your property, you are eligible for tax deductions for a proportion of your expenses. This proportion is based on the floor area that is rented, compared with the floor area which is not rented. Make sure you include common areas in your calculation.

Keep receipts and record all expenses
They then need to be classified into areas such as:
  • Interest on loan
  • Advertising
  • Insurance
  • Rates
  • Repairs
  • Postage
  • Cleaning
  • Garden
  • Borrowing expenses
  • Legal Expenses
  • Depreciation
  • Capital Works

Most of these are straight forward, and immediate write offs in the year they are incurred.
I'll go into more detail on the complex ones below.

Borrowing Expenses
Generally, you will need to spread these over 5 years, or the length of your loan, whichever is shorter. In most cases, this will mean you'll tax deduct 1/5 of them each year for the first 5 years of your loan. They include things like government stamp duty on the loan and bank charges.

Legal Costs
Unfortunately, these do not include the cost of legal fees in acquiring your property. They are for when you need to fight with tenants in court and similar. Hopefully you won't have any of these.

Depreciation and Capital Works
This is the most complex area. First, download the Rental Properties Guide 06 (NAT1729-06) from the ATO. This document is invaluable. I'd recommend you at least skim read it.

Capital Works
Okay, now, if your house has been built or had any significant renovations since 1979, you may well have capital works deductions. The conditions on these vary. Have at look at the guide mentioned above, page 23 of the PDF. In most cases, you will be able to claim construction costs at 2.5% for 40 years. If there was a couple of hundred thousand dollars of construction costs, 2.5% could be quite a bit of money every year. If you know the cost of the construction, this is easy to calculate. If not, you will need to get this estimated - you can't do this yourself. I used Depreciator. They employ quantity surveyors and meet ATO requirements. I was quite happy with them - see my post on the Somersoft investment forum for more details. They also estimate costs of assets such as hot water systems, stoves, blinds etc.

Deductions
You need to classify all your assets according to their cost and depreciate accordingly:
  • $1-300: write off straight away in the current tax year
  • $301-1000: put in low value pool (deduct at 18.5% for the first year when adding to the pool, 37% for assets already in the pool)
  • $1001 or more: depreciate with straight line or curved line methods over effective life set out by ATO. You can find these in the rental guide from the ATO mentioned above.
What is a asset (can be depreciated) and what is a capital work
There is a reasonably arbitrary seeming classification of items between capital works and deductions. A hot water system, for example, is a depreciable asset but a kitchen cupboard is a capital work. Check all your items with the rental guide mentioned above. If an item is an asset, you can estimate its market value, and you can depreciate it over the effective life in the guide. If it is a capital work, then you cannot depreciate it. It is part of construction costs - see above section on capital works for more details on claiming these.

Disclaimer
I'm not a tax professional. This post is my personal opinion and interpretation. No responsibility taken for an errors or omissions. Use at your own risk.

Sunday, September 03, 2006

Learn English using a Blog and Programming Tools!

My fiancee, Soosun, is brushing up on her English skills before going to uni next year. As part of the plan to improve her writing, she's started a blog. Friends and family can write comments on her posts to help improve her written English.

She just wrote a nice article on making kimchi, and I posted a comment containing a copy of her article with English improvements. But how can she tell what I've suggested? The solution we decided to use is kdiff3, a tool I use at work for comparing and merging source code. You can download it here. If you turn word wrap on, it is great for comparing English - shows up the differences beautifully.

From "A Wild Sheep Chase" by Haruki Murakami

"Nor do you know where you stand. Now listen, I thought it over last night. And it struck me. What have I got to feel threatened about? Next to nothing. I broke up with my wife, I plan to quit my job today, my apartment is rented, and I have no furnishings worth worrying about. By way of holdings, I've got maybe two million yen in savings, a used car, and a cat who's getting on in years. My clothes are all out of fashion, and my records are ancient. I've made no name for myself, have no social credibility, no sex appeal, no talent. I'm not so young anymore, and I'm always saying dumb things that I later regret. In a word, to borrow your turn of phrase, I am an utterly mediocre person. What have I got to lose? If you can think of anything, clue me in, why don't you?"

Great passage, ya?

Saturday, September 02, 2006