Price groups now available

General Discussions
Best Practices
Examples

Price groups now available

Postby Christian Estrup » Fri Jan 08, 2010 12:52 pm

By request from many customers using the e-conomic Stock Management add-on module, we have now exposed price groups in the API:

1. The IDebtor and IDebtorData classes now expose a PriceGroup property.
2. The IPriceGroup interface has a GetPrice(IProduct oProduct) method.

Note that both of the above are only available for customers using the Stock Management add-on module.

If no special price is defined on the supplied product in the product group, the product's default sales price will be returned. This will save you some round-trips :-)

Note that the price group may not be set on all customers - so doing something like this would be very bad practice:

Code: Select all
objCurrentInvoiceLineData.UnitNetPrice = objDebtor.PriceGroup.GetPrice (objProduct);


- since it may obviously result in your language's choice of NULL-pointer exception...

Another tempting approach is something like this:

Code: Select all
objCurrentInvoiceLineData.UnitNetPrice = (objDebtor.PriceGroup != null ? objDebtor.PriceGroup.GetPrice (objProduct) : objProduct.SalesPrice);


While this won't result in errors per se, you'd be reading the PriceGroup property twice, resulting in two round-trips.

The best approach is this.

Code: Select all
IPriceGroup pg = objDebtor.PriceGroup;
objCurrentInvoiceLineData.UnitNetPrice = (pg != null ? pg.GetPrice (objProduct) : objProduct.SalesPrice);


If you're using .NET, to use this feature, you'll have to use the latest version of our .NET assembly - which is available here.
Christian Estrup
Chief Architect

Image
Online accounting
User avatar
Christian Estrup
 
Posts: 206
Joined: Tue Jun 09, 2009 6:37 pm

Return to Miscellaneous