Вы находитесь на странице: 1из 23

ADEMPIERE JAVA POS

(POINT OF SALES)
Integration and Testing Guide

C ONQUER IN G T H E W I L D

REDHUAN D. OON
Sponsored by Sysnova
August 2011

“I did a lousy job but I got it done”


- red1

This document is not due to some project management discipline. It is exposing one of the author’s many
weaknesses, which is to brag about what he did or where he’s been to. Thus to incite maximum emotional im-
pact, he has to make it freely accessible and distributed particularly to some of his close friends.

The tagline above is inspired right before he was about to start writing this document one morning, a longtime
friend phoned and related how people kept criticising his handling of event management jobs and he got re-
placed but later they took him back when the replacements did an even more lousier job. So a quip lighted up
in Red1’s head to offer the advice to his friend to say this quip each time it happens again.

The cover photo is a shot he took with his Nokia E71 while horse-riding in Del Monte county of Cagayan de
Oro, Mindanao. Note at the bottom right of the picture is a Nacho’s point of sales, that although it seems to
be mobile, it does not have a modern tool other than a human head to crunch the figures of sales. A good can-
didate for using an Open Source POS.

The series of photos in the first chapter are captured in Northern Mindanao. From left to right:
Chris Ian’s wife, Kelly and their daughter out horseriding together with me where they took me ziplining.
Arriving safely at the end of that zipline, which is the longest in Asia at 840 meters;
White-water rafting in the Cagayan de Oro river;
Certificate copy that is given to students at Xavier University where Red1 delivered a half day seminar on ADempiere;
Some of the students who are excited about getting him to return again to Cagayan.


ADempiere Java POS Integration & Testing Guide

TABLE OF CONTENTS

Where Do You Find Inspiration? 4


The Origin of ADempiere Java POS 6
Solving the Bugs 10
Getting Java POS 12
Using Java POS 13
Getting the Testing Suite 18
Running the Tests 20
Conclusion 23

Copyle# Redhuan D. Oon 2011 3


ADempiere Java POS Integration & Testing Guide

Where Do You Find Inspiration?

To be exact it is more of ‘where do you find relief?’ To escape from pain that is. Tackling new
things is fun only at the end of it. Before it you go through pain. In software engineering there is
much relief via Open Source work. You can be anywhere at anytime as all work happens mostly
in digital space. Thus what is stopping you to go out and have fun at the same time? Many of the
challenging tasks found in this documentation were encountered while I was travelling around to
a couple of places this past month.

Blackheath, 1st - 11th July, where while supposedly meditating at the Vipassana Centre up in
the Blue Mountains outside Sydney, with another 100 men and women who also signed up, I
took my first peek at the new code from UISpec4J I downloaded before going and thus began
another new painful learning curve. I must say the strict regime of no eye contact nor talking for
10 days, no phone nor Internet and eating only vegetarian food with no dinners in a freezing
southern winter helped leave my mind empty for one single distraction. But on the 4th evening
we lost electrical power due to a real big windy storm which knocked out the whole of Black-
heath for 2 days. So that means no more heating nor water as it needs electricity to pump up to
the high location, and my MacBook died faster in the cold. Perhaps Dhamma was punishing me
for breaking noble silence with a worldly device hidden under my cloak to resolve the small gaps
and bugs within the Java POS. I needed some new discipline and that place and condition gave
me some poetic balance. However I also found out what Buddha is actually trying to tell his fol-
lowers two thousand five hundred years ago. It is Shut Up!

Hornsby, 12th - 15th July, while housesitting a HelpExchange host, I got more comfortable as
the household tasks were quite easy. Either making sure the already very clean house stays clean
or feeding the already very fat cats (just pour more catfood into the the tumbler for both cats) or
walking a Down’s syndrome occupant to his job at the MacDonalds across town via train. I did
that only once as he works there twice a week where I was at this sweet old but very remarkable
Sydney lady’s house for only 3 days before flying back to Melbourne enroute to my Malaysian
farm home, of which I hardly got reacquainted as I have to head to Penang immediately upon
touchdown for some family gathering and then Johor for an ERP prospect meeting. In effect, I
only slept one night at my farm home before heading out this time to the Philippines.

Copyle# Redhuan D. Oon 2011 4


ADempiere Java POS Integration & Testing Guide

Cagayan de Oro, 21st - 25th July, where the 3 hours whitewater rafting and ziplining a total of
1.5km (where there is one 840 meter, Asia’s longest) and very pleasant evenings with a ear-
blowing karaoke night, help jolt more numbness out of my skull. And the very abstract new UIS-
pec4J code became clearer. This nascent code in my head is supposed to intercept GUI panel
windows such as our Java POS without launching it manually to click on the potent buttons and
icons. Now if I could just get that Open Source tool to really work, I will jump into the fast flow-
ing Northern Mindanao river, and I did fell in 3 times, thanks to the rafting skills of the guide
onboard (which involves getting us as much into the water as out of it. Its part of the fun, get it?).
It is up in the motel called New Dawn, room 207 on the last morning of some remaining focus
that I managed to make the foreign code handshake with our Java POS more firmly:

return window.getButton("Ok").triggerClick();

Makati, 25th - 29th July, while staying in the dorm on the 9th floor of Asia Pacific College, I
turned the handshake into more smiles and right small talk: window.getButton("Oak").click();
In between meetings with faculty heads and ADempiere clients and prospects, brought in by
IOSS, the local ADempiere player, my host, which has to juggle with my request for at least one
night out with the guys and gals for karaoke, got me to see so much potential happening in the
Philippines. I wrapped it up with another stellar performance on stage, pounding out the music
and promise of Open Source ERP under the Church of ADempiere to the faculty staff and stu-
dents on the 12th floor penthouse auditorium. I must believe I am that good, from all the clap-
ping and cheering. Otherwise, the pain won’t go away.

I achieved code Nirvana while settling down as one with my farm shack at the onset of the Ra-
madhan fasting month to conduct very surgical moves on the code. And it is good Zen. UISpec4J
is truly amazing in that I can now get it to touch any panel, key in any textbox, pull down any
combobox, and access any table row/column on the GUI. Or to handle any successive pop-up
windows from any action. All without seeing the POS in action. The sky is now the limit. And
now I must be kind to the other earthlings. I have to give back out what is given to me.

I end this preface with tribute here to the greatest yet humblest contributors of Open Source
software that I have come to learn from. May their karma grow many times over.

Peace!
Redhuan D. Oon,
Kuang farm, Sungai Buloh. 11th August, 2011

Copyle# Redhuan D. Oon 2011 5


ADempiere Java POS Integration & Testing Guide

The Origin of ADempiere Java POS


As with anything in Open Source projects, it is contributed ware and unequivocal tribute to
those who first brought it about and suffered or I rather suspect, enjoyed through its jour-
ney. The Java POS in ADempiere was originally a remnant from Compiere days. I remem-
bered trying to tackle it when it first appeared in one of the versions in perhaps 2004 and
emailing Jorg Janke, the owner of Compiere that time. Jorg Janke gave me a short casual an-
swer like “Someone else did this and they have not updated anything further”.

In a way that becomes the turning point. If you remember, my very first iconic tutorial in
2004 that launched my red1.org empire, I was trying to make the Sales Order window look
like a Point of Sales.

So Compiere’s Java POS remains quite inept but still a remarkable promise. It has some
semblance of a working POS with some bland touchscreen feel of buttons on the right side
of it. The basic skeletal frame of code that talks to the ERP behind is there, despatching
Sales Order lines, calling up product code and pricings but it was not pretty or sexy. A POS
has to look better like any other POS in the market.

OpenXpertya of Spain then greatly improved it giving it more pop-up dialog for Business
Partner and Product selection. The buttons also looked a bit better and there are different
colour settings in them. This version was handed to me by an OpenXpertya person, who is
also a long time red1.org/forum member, Oscar who goes by the handler Lofx, in November
2008 to put into ADempiere.

Figure 1. The OpenXpertya version

Copyle# Redhuan D. Oon 2011 6


ADempiere Java POS Integration & Testing Guide

The code then get more baptism from the community as what I put up here that include
Carlos Ruiz, Heng Sin and Joseph Brower. I wrote up a user guide here. Then a real big jump
in usability came from down under at the hands of Paul Bowden of ADAXA HQ in Mel-
bourne. The product touchpad is more larger with more crisp arrangement of fields to make
good use of the wasteful spaces in between. Paul also began using the new Swing tool of Mi-
gLayout that helps the developer’s life in maintaining look and feel easier.

Paul also made a nice pop-up keyboard plugin for fuller use of the touchscreen. There is also
a pop-up number pad that gives faster key-in of numbers in multiple figures. Paul named it
the Touchscreen POS here.

Figure 2. Paul Bow-


den’s Touchscreen
POS

Paul used intui-


tive judgement
as to making the
product-pad
switchable be-
tween Popular
products and All

Copyle# Redhuan D. Oon 2011 7


ADempiere Java POS Integration & Testing Guide

Products.

Figure 3. The pop-up keypads for easier input via touchscreen

Of course this makes the POS looks great and set for prime time. But a conflict occurs
when Trifon picked Paul’s work up and rushed this into trunk. Our PMC that time, Carlos
Ruiz objected to it and took it out again in version 361 as this POS has some bugs that were
not reviewed well enough as to its impact and thus breaks the best practice that we were
committed to that time to ensure stable and backward compatible code. The old OpenX-
pertya version is back in Carlos Ruiz’s 361, and Carlos has gone out of the project-space to-
gether with Heng Sin still keeping to their principle of stability above all else.

Copyle# Redhuan D. Oon 2011 8


ADempiere Java POS Integration & Testing Guide

Then a big break came when SYSNOVA sponsored me to see to the bug fixing and getting
it back into main release of the stabler 361. Well over a month’s attention to this has brought
about some needed fixing, proper QA and further beautification. The use of UISpec4J to-
gether with Fitnesse allows fast and agile testing to be carried out on the Java POS.

The Java POS is now more prepared for latest 361 and it is put in its own branch under the
project-space/branches as /JavaPOS. It is also compatible with the old trunk’s 360LTS.

Figure 4. Slight Java POS layout enhancement

The above enhancements done is to make it even more appealing particularly by making the
Cashier name (formerly Sales Representative which is bit too bulky looking for a small POS
interface) evident by using a larger font and in big bold red typeface. The Grand Total is made
more simpler by been just TOTAL with the final payable amount in bold larger blue type-
face. The payment button is also brought down to be more central and just below the total
figure. This gives less distance to travel for the mouse or finger as the items and payment
buttons are now as close by as can be. The New button is automatically reset whenever pay-
ment is successful. In future one may even bring the History button closer as it can be the
next most touched button particularly for restaurants where tables are not paid until some
time after the orders are made and consumed. The BPartner field can stand for table names
rather than customer names.

Copyle# Redhuan D. Oon 2011 9


ADempiere Java POS Integration & Testing Guide

Solving the Bugs


Carlos Ruiz, much to his disadvantage is always the one to cry “Must be Stable and Back-
ward Compatible!”. That is very fine because that is his job. A messy voluntary job which no
one else wants to do, or is too lazy or do not have the competency to do it. His review of our
trunk has brought about remarkable stability and quality to ADempiere. So his first com-
1 plaint of the Business Partner field been locked to Standard was my first task, and that was
easily solved as I merely reactivate that part which Paul Bowden commented out. (patch to-
gether with redbox item 4 below)

2 When operating the POS in 361, the migration scripts for the keyboard pop-up was left out,
and after tracking back Paul’s original commit,

contributions/adaxa/pos/migration/354a-trunk/postgresql/pos_postgresql.sql
contributions/adaxa/pos/migration/354a-trunk/postgresql/pos_postgresql2.sql
they got working again.

3 There is then the M_Storage field of

ERROR: column s.qtyallocated does not exist


and is easily solved with a migration script with centralised ID,

branches/JavaPOS/migration../MStorageQtyAllocated_postgresql.sql

4 When deleting an order, we hit numerous problems. The display does not refresh because it
cannot load an empty order. And the order is really deleted which is against audit purposes.
The SubOrder.java is patched to solve this. Deletion now will void the order, and remove all
lines. The processed box is also ticked so that it can be reviewed in the History table.

branches/JavaPOS/migrationPatch./red1POS.patch

5 When deleting the order, the lines are not getting deleted.

6 The Preference button does not do anything. Linked to Cashier Control window.

7 Cashier Control tries to hide previous selection without checking if they were ever visible.

PayOrderModel.payCreditCard still sets TENDERTYPE_Check. Changed to TENDER-


8
TYPE_CreditCard
(Above solved in same patch. Fixes below are not. But the JavaPOS branch has all these ap-
plied. Later chapter will describe how to take this branch and apply to any version)

Copyle# Redhuan D. Oon 2011 10


ADempiere Java POS Integration & Testing Guide

The use of POSApplication to launch the JavaPOS without going through the main menu is
reusable. It was first created during Compiere times (unless whoever the actual later author
who put it there did not change the copyright notice attributed to Jorg Janke). However I
9 removed the Splash screen so as to give faster response and also UISpec4J can’t seem to
handle the transient window for that (or I did a lousy job in making that happen).

In order for UISpec4J to work, it need to identify the names of the UI components it is
calling. Thus I modify some core code such as ALogin (for identifying the login fields) and
POSPayment (for identifying the fields in the payment fields).

10 While testing a large payment figure above i.e. 1,000.00 that has a comma separator in the
textfield, an error appears as BigDecimal cannot parse this non-numeric value. I resolved in
POSPayment with:

NumberFormat nf = NumberFormat.getInstance(Locale.getDefault()); //locale-specific


try
{
tender = new BigDecimal((nf.parse(fTenderAmt.getText())).floatValue());
pay = new BigDecimal((nf.parse(fPayAmt.getText())).floatValue());
}
catch (ParseException n)
{
n.printStackTrace();
}

However the float has two issues. It is not BigDecimal, something our top project account-
ing mind in the form of Steven Sackett of Adaxa will raise an eyebrow to. Next is that the
trailing figures after the decimal point is long and it gives an error during final processing. So
I have to introduce a truncating move:

NumberFormat formatter = new DecimalFormat("#0.00");


...
BigDecimal(formatter.format((nf.parse(fTenderAmt.getText())).floatValue()));

Of course, having written the test suite, I can simply run the Fitnesse tests onto my UIS-
pec4J code and they passed and displayed the total figures for comparison. However we
need to run more differentiated totaling with an accountant to check this further. That is
easy now that we have the Fitnesse framework to keep testing different formulas and ob-
taining the results for study.

Another minor thing, I am not sure who the POSPayment’s author is (not remarked in it)
but it is a bit too long and should be refactored into more separate objective classes.

Copyle# Redhuan D. Oon 2011 11


ADempiere Java POS Integration & Testing Guide

Getting Java POS


I have submitted to trackers in SourceForge.net on the progress of this work and it is left to
the various owners to review my work and incorporate it into main branch. I have also sub-
mitted to Carlos Ruiz for admission into 361 or iDempiere future release. If you wish to
compile yourself just checkout the branches/JavaPOS and you will find some folders:

Figure 5. POS Sourcecode

Under client/src it is:

org.comopiere.apps

org.compiere.minigrid.

org.compiere.pos

and under base/src it is:

org.compiere.model

You are to replace your own source with the


matching contents in respective folders (ex-
cept for org.compiere.pos). Do not overwrite
or remove other files in your present folder.
Just copy and paste the contents of each
folder and go to the corresponding folder in your source and paste over. So that only the
same files are overwritten and not the folder which may delete others.

But for org.compiere.pos you have to replace the whole folder as the other files in that
folder are deprecated completely and will show errors when other files are disturbed.

When that is done, just RUN_build your source and RUN_setup the binary.

For database changes just apply the migration scripts under migration and select the con-
tents of the database flavour you are using (Oracle or Postgresql).

When launching your ADempiere instance, you can go to the main menu and look for the
POS window and open it. It should show you the new POS GUI as shown in Figure 4.

Copyle# Redhuan D. Oon 2011 12


ADempiere Java POS Integration & Testing Guide

Using Java POS


We shall now use the new Java POS and go through some steps and transactions and then
the testing chapter later will repeat similar steps in order to compare the results.

First we want to try using the barcode input. If you have a scanner attached to your POS,
you can try scanning it in. If you do not have one then you can do this. Just tab to the Prod-
uct field. You will see that the cursor focus is on the Product field. Just type in the barcode
via keyboard and it will appear in the product field. We shall use the barcode for a product
called Azalea Bush and it is 1234567890.

Figure 6. Barcode entry in the Product field box and returned the product item below

Then press enter or Tab and the display will show:

Copyle# Redhuan D. Oon 2011 13


ADempiere Java POS Integration & Testing Guide

Then we click on the Product icon or just key in an S in the Product field. It will open up a
Selection box with two products having the same starting letter of S. Click on the first one
or just press Enter.

You will have selected Patio Sun Screen and the box will close and return to the main panel
as shown below.

Figure 7. Selecting product via the Product lookup pop box if there is multiple items for the same input

We leave this order and try a new order. There are two ways to make a new order when you
first open your POS. The first is by clicking on the New button. The second is like what we
do earlier is just key in any product. After making a payment the POS will also set you to a
new order mode and you do not need to click on the New button again. But in your case
here, we have not paid and so we can click on the New button to tell the POS that we are
not paying for this yet but wish to take a new Order. This is convenient for restaurant busi-

Copyle# Redhuan D. Oon 2011 14


ADempiere Java POS Integration & Testing Guide

ness where you have different table orders and they pay only at the end of their meals. You
can set different table names or numbers via the Customer field. Just create different Busi-
ness Partners from ADempiere main menu first.

Click on the New button. And this time we like to select some items and pay first by Check
and then by Credit Card but also with different Customers.

At the Customer field key in Tree and then press tab or click on the Product field. If a pop
up keyboard appears, you can use that and just press Ok at the end of it. Now we shall select
two products for this customer. Click on the Weeder and Lawn Tiller buttons and press
enter. Then click on the Payment button below the TOTAL figure. At the pop up select
Check from the Payment Type combobox.

Figure 8. Chosing the mode of payment.

Then click Ok, and the Payment will be made with all the associated DocTypes processed
such as Invoice, Shipment, Payment and Cash Journal. You may go to your Sales Order win-
dow and zoom across to these other documents to see for yourself. You can also do the ac-
counts posting and view the consequence from the Account Info window. In our instance we
set the Accounts posting to Immediate so that we can see it right away during testing.

Copyle# Redhuan D. Oon 2011 15


ADempiere Java POS Integration & Testing Guide

After the payment goes through, the POS will be ready to take your next order. You need
not click on New but just
click on another two items:
How to Plant and Elm.
You can also go to the Cus-
tomer field and type Patio,
then press Enter. Th total
amont showing is 71.02.
This time we pay via
Credit Card. You need a
valid card number and an
expiry date or it will not
allow to go through.

Again you can notice the


different accounting con-
sequence from the Account
Info.

Next we are going to do something more fanciful. We are going to click or press on every
item displayed in the product keypad. There are 16 items all together giving a big total.

Figure 9. Clicking on all 16 items on the POSKeyLayout gives a total with a comma separator for testing

Copyle# Redhuan D. Oon 2011 16


ADempiere Java POS Integration & Testing Guide

Other tasks we can do is to try deleting an order that is empty and deleting an order with
orderlines. We can use the buttons at the bottom of the POS, to see how we can delete com-
pletely the line or just decreasing (after increasing) the quantity. If you do not see the bot-
tom part (if the window is too tall) you can click on the maximize button on the top left of
the window to do so.

Figure 10. The lower bar control allow to navigate the orderlines and change the quantity ordered

Somewhere in Melbourne, I found the faces to some famous names - Paul Bowden (1st left), David (hope he
gets famous fast), Steven Sackett (in red), and Tony Snook (sitting).

Copyle# Redhuan D. Oon 2011 17


ADempiere Java POS Integration & Testing Guide

Getting the Testing Suite


The testing suite is my usual Fitnesse and is committed to branches/POSFitnesse. By check-
ing it out and placing it in your PC server, you can then classpath to it. This is needed when
you run Fitnesse from the story scripts committed to branches/FitnesseStory - under the
link, POSGuiTesting. That script suite shall refer to the binary that tests off your
ADempiere binary. that already has the POS code applied before this.

Figure 11. POSFitnesse that is used for testing the POS using Fitnesse and UISpec4J

Copyle# Redhuan D. Oon 2011 18


ADempiere Java POS Integration & Testing Guide

You can run the tests individually (except for the last test) or successively as a suite. The last
test only works in a suite as it will refer to History of 2 previous orders.

By looking at a sample test will give you an idea what and where to place your jars, testing
engine and ADempiere binaries. You should edit them to suit your local locations.

Travelling to different lands and cultures brings fresh insight not to the world, but to your own self. Here I was
volunteering to help a Maesot school on the Thai-Myanmar border build a playground (end of March 2011). A
photograph always remain a poor resemblance of what you have seen or hear and even more of what you feel.
Furthermore I kept using the cheap and limited Nokia E71 phone camera.

Copyle# Redhuan D. Oon 2011 19


ADempiere Java POS Integration & Testing Guide

Running the Tests


Returning back to the suite page, you can just press the suite link on the left panel to get the
whole series of tests firing away.

Copyle# Redhuan D. Oon 2011 20


ADempiere Java POS Integration & Testing Guide

What does the BarcodeProduct test do? It repeats exactly the exercise we did earlier

The Barcode value is passed which belongs to Azalea Bush and the SearchKey for the Prod-
uct field is set to ‘S’ and its results is clicked for the first row which is Patio Sun Screen and
the GrandTotal sales value is as above - 49.03. So this confirms what is done manually. And
you can see that this test takes about 25 seconds to execute for a first time run and in the
suite it takes about 10 seconds to run. This means efficient testing without a human tester
for the same routine and highly dependable and useful during debugging as errors will be
reported in both the exception stack and the logs from the Output Captured button at the
top right.

If you have not used Fitnesse, I can explain what the wiki styled story script above is doing.
BarCode column defines the Setter method and the GrandTotal column is a Getter method
which you know due to the ? sign at the end of it.

In the code under POSFitnesse, you look for this by going the to the java class called Barco-
deProduct as shown above as the table title. There you will find the setBarCode and Barcode-
Product methods as shown below. You can examine the other setters too such as SearchKey.

Copyle# Redhuan D. Oon 2011 21


ADempiere Java POS Integration & Testing Guide

public class BarcodeProduct extends ModelLogin {


private boolean cnt = true;
protected String barcode;
protected String search;
protected static String grandtotal = "";
//
public void setBarCode(String code){
barcode = code;
}
public void setSearchKey(String s){
search = s;
}
public String GrandTotal(){
return grandtotal;
}

The execute getter calls the getMainWindow() implementing from UISpec4J:

Copyle# Redhuan D. Oon 2011 22


ADempiere Java POS Integration & Testing Guide

Conclusion
This proves that the JavaPOS is now working as tested, and there is a test suite ready to re-
peat those tests quickly to weed out any code change impact to it from others. You can also
extend it to cover more stringent tests by following the examples already done in the code.

From this document you can see that the tests are now easily managed within a suite and
you can now study it more easily by examining the actual code I submitted into
SourceForge.net. If you have any query or questions you can ask in the forum here:
http://red1.org/adempiere/viewtopic.php?f=28&t=1353

I may edit your question to keep it more relevant and specific, and answer it if it is relevant.

The point that I also intend to make is that not only this is the most promising Open
Source project that I have worked on, and it usually makes me proud to showcase it to many
prospects and students as what I often coined as “The Best ERP Software In The World”, it
is also a fun filled life of freedom and fun while doing it.

I hope you will now know why you just got to take the red pill.

And join me.

THE END

Copyle# Redhuan D. Oon 2011 23

Вам также может понравиться