Developing custom LedgerSMB extension experience

Submitted by Chris Travers on

By Erik Huelsmann

In summary: adding to or changing LedgerSMB can be extremely easy

For one of my businesses, I needed to create an application to store some data on the services and products we provide. Basically, there would be one central table with some references to a few other tables, mostly to provide (short) selection lists. Also, there's one bigger complexity, because we wanted to link to our customer data.

The customer data is all stored in LSMB, so, developing this database inside LSMB's database seemed like a logical choice.

Since my colleague and I were completely unfamiliar with the web development framework for LSMB, we first had a start with the tools we did know. (Internally developed stuff, nothing particularly fancy.) However, due to other priorities, things didn't quite roll forward as we wanted; it was simply too much work to get it done.

Last week we scrapped our own development. As a replacement I started looking at the tools that LSMB provides to get the same job done. Again, without prior knowledge how this should be done, I simply studied the budgetting module. I figured that if budgetting was an extension, we might consider our own administration as an extension and that it should probably work (roughly) the same way.

And it did: in 1,5 day I had our administration up and running, featuring a data entry screen and a search screen. The current version of the data entry screen searches and links to a customer only if it finds an exact match. [Chris and I are working on functionality every module can use to look up cross table references like these, so it'll be replaced by something better soon.]

The steps I had to take were really simple:

* Develop 2 main stored procedures:
- [mymodule]__search()
- [mymodule]__save()
and 1 stored procedure for each drop down in the data-entry screen:
- [mymodule]__list_[characteristic1]()
- [mymodule]__list_[characteristic2]()
- ... etc...

* Create a class in LedgerSMB/DBObject/[objectname].pm
which contains functions callable from perl and maps those
to calls to the stored procedures in the database as simple as
containing:

sub search {
my ($self) = @_;
my $results = $self->execmethod({funcname=>[mymodule]__search'});
$self->merge($results);

return $results;
}

* Create two Template Toolkit template file for my module:
- ./UI/services/entry.html
- ./UI/services/search_criteria.html

* Create an LedgerSMB 'module' [mymodule].pl, with three entry points:
- edit
- search
- update

* Create a top level handler file by copying ./file.pl to ./[mymodule].pl

* Add menu items

Basically, the out of the 1,5 days I've spent, most time was spent learning what I had to do. The actual time spent coding was negligeable.

In summary: adding to or changing LedgerSMB can be extremely easy. It was a refreshing surprise to me how easy. We'll definitely develop the rest of our application using LedgerSMB's own framework and when it's done, we might be able to donate it to the project.

Anyway, I hope the above inspires others to try it out themselves. If you have any questions, both Chris and me will be glad to help you out!

Source: Developers mailing list: http://permalink.gmane.org/gmane.comp.finance.ledger.smb.devel/3505