POS - Add reference product to a ticket line
Code snippetName: POS - Add reference product to a ticket line
|
This article is an attempt on how to store the reference of an article as an attribute of the ticket line, to print on the receipt.
Implementation
The method is:
- You must create a new ticket addline event. So you must edit Ticket.Buttons resource and add this line in the <configuration> section:
<event key="ticket.addline" code="event.addline"/>
- Then you must create a new resource called event.addline with this content:
// Add product reference to a ticket line, y in the line is a product (discounts and others have no reference). import com.openbravo.pos.forms.DataLogicSales; import com.openbravo.pos.ticket.ProductInfoExt; import com.openbravo.data.loader.Session; import com.openbravo.pos.ticket.TicketLineInfo; Session session = new Session(database_url, database_user, database_password); DataLogicSales logic = new DataLogicSales(); logic.init(session); try { ProductInfoExt product = logic.getProductInfo(line.getProductID()); line.setProperty("product.reference", product.getReference()); } catch (Exception e) { line.setProperty("product.reference", " "); }
- In this scriptlet you must replace database_url, database_user and database_password by their corresponding values.
- Now all lines will have reference as an attribute: product.reference. If you want to print it in your ticket receipt,then you must edit Printer.Ticket resource (or what you use), and add this where you want ('in line section'):
${ticketline.getProperty("product.reference", "")}
Example
<line> <text>----------------------------------------</text> </line> #foreach ($ticketline in $ticket.getLines()) <line> #if ($ticketline.isProductCom()) <text align ="left" length="10">*${ticketline.printName()}</text> #else <text align ="left" length="10">${ticketline.printName()}</text> #end <text align ="right" length="5">x${ticketline.printMultiply()}</text> <text align ="right" length="25">${ticketline.getProperty("product.reference", "")}</text> </line> #if ($ticketline.productAttSetInstId) <line> <text align ="left" length="40"> ${ticketline.productAttSetInstDesc}</text> </line> #end #end <line> <text>----------------------------------------</text> </line>