Compiere provides a variety of options how to generate and manage document numbers and formats. It also allows to maintain gapless sequence numbers. When any table has a the field "DocumentNo", it is recognized and managed as a document number.
The default algorithm checks, if the field is empty and if so, a number is assigned. This number comes from an automatically created Document Sequence, which is sufficient for many areas. When a table has a Document Type (field "C_DocType_ID"), you determine for that Document Type if the numbering is manual the default behavior applies (i.e. if it is not entered, the number is created from the automatically created sequence). If the document type is document number controlled, a Sequence is referenced. Multiple document types can share a sequence or can have it's own sequence.
A Document Sequence can also have a user defined prefix and suffix, so you can create document numbers like "Sales-12345-Export". Same algorithm here, if the Document number is empty, the number is created from the document sequence for the specific document type.
For documents, where document numbers are especially important like Orders, Invoices and Shipments, a temporary document number is created and displayed in <number>, so that you know before you save, what number it would get. If someone else would save a document with that document type, you will get the next number.
For some documents, like AP Invoices or Material Receipts, you want to set the Document Type that it is not document number controlled. This allows that you enter the vendor invoice number or the vendor shipment number. Again, if you do not enter a document sequence, the default number is automatically applied.
Payments have a special treatment. If the payment represents an outgoing check, transfer, etc. the appropriate sequence number from the bank account document (e.g. check) is used. If the payment is a customer credit card payment, the obscured credit card number is used if the charge was rejected or not performed yet - otherwise, the credit card processor confirmation number will be used. If it is a customer check, that check number is used. This ensures consistency, so that you can find documents faster.
Gapless document sequences is sometimes a requirement. You achieve this with the following steps:
- Make sure that you cannot delete documents: In window "Table and Column" for the table with gapless sequences, deselect "Records deletable".
- For Orders, Invoices and Shipments, use the same document sequence for all document types for that area.
- Change the Column definition, so that the document number is updateable - until the document is processed, you now can change the document number
- Use the Model Validation Listener to change/set the document number before you save or update the document - or before or after you processed the document.
The latter enables that you to maintain gapless sequence numbers where you can delete documents (Compiere allows to delete unprocessed documents but prevents deletion of processed documents) with different number schemas (e.g. domestic and export orders).
Here an example implementation:
In method initialize:
engine.addModelChange(X_C_Order.Table_Name, this);In method docValidate:
// You may prepare a document several times, you can complete it just once
if (timing == DOCTIMING_AFTER_COMPLETE
&& po.get_TableName().equals(X_C_Order.Table_Name))
{
MOrder order = (MOrder)po; // Make sure that it complete (may have failed)
if (order.getDocStatus().equals(MOrder.DOCSTATUS_Completed))
order.setDocumentNo(getGaplessSeqNo());
}
If you have any questions, just contact me.