Class MOrder

All Implemented Interfaces:
Serializable, Cloneable, Comparator<Object>, I_C_Order, I_Persistent, DocAction, Evaluatee

public class MOrder extends X_C_Order implements DocAction
Order Model.
Version:
$Id: MOrder.java,v 1.5 2006/10/06 00:42:24 jjanke Exp $
Author:
Jorg Janke, victor.perez@e-evolution.com, e-Evolution http://www.e-evolution.com
  • FR [ 2520591 ] Support multiples calendar for Org, Teo Sarca, www.arhipac.ro
  • BF [ 2419978 ] Voiding PO, requisition don't set on NULL
  • BF [ 2892578 ] Order should autoset only active price lists https://sourceforge.net/p/adempiere/feature-requests/873/, Michael Judd, www.akunagroup.com
  • BF [ 2804888 ] Incorrect reservation of products with attributes
  • See Also:
    • Field Details

      • NOT_FULLY_MATCHED_TO_RECEIPT

        public static final String NOT_FULLY_MATCHED_TO_RECEIPT
      • NOT_FULLY_MATCHED_TO_RECEIPT_GROUP_BY

        public static final String NOT_FULLY_MATCHED_TO_RECEIPT_GROUP_BY
      • FULL_OR_PARTIALLY_MATCHED_TO_RECEIPT

        public static final String FULL_OR_PARTIALLY_MATCHED_TO_RECEIPT
      • FULL_OR_PARTIALLY_MATCHED_TO_RECEIPT_GROUP_BY

        public static final String FULL_OR_PARTIALLY_MATCHED_TO_RECEIPT_GROUP_BY
      • NOT_FULLY_MATCHED_TO_INVOICE

        public static final String NOT_FULLY_MATCHED_TO_INVOICE
      • NOT_FULLY_MATCHED_TO_INVOICE_GROUP_BY

        public static final String NOT_FULLY_MATCHED_TO_INVOICE_GROUP_BY
      • FULL_OR_PARTIALLY_MATCHED_TO_INVOICE

        public static final String FULL_OR_PARTIALLY_MATCHED_TO_INVOICE
      • FULL_OR_PARTIALLY_MATCHED_TO_INVOICE_GROUP_BY

        public static final String FULL_OR_PARTIALLY_MATCHED_TO_INVOICE_GROUP_BY
      • m_lines

        protected MOrderLine[] m_lines
        Order Lines
      • m_taxes

        protected MOrderTax[] m_taxes
        Tax Lines
      • m_forceCreation

        protected boolean m_forceCreation
        Force Creation of order
      • DocSubTypeSO_Standard

        public static final String DocSubTypeSO_Standard
        Sales Order Sub Type - SO
        See Also:
      • DocSubTypeSO_Quotation

        public static final String DocSubTypeSO_Quotation
        Sales Order Sub Type - OB
        See Also:
      • DocSubTypeSO_Proposal

        public static final String DocSubTypeSO_Proposal
        Sales Order Sub Type - ON
        See Also:
      • DocSubTypeSO_Prepay

        public static final String DocSubTypeSO_Prepay
        Sales Order Sub Type - PR
        See Also:
      • DocSubTypeSO_POS

        public static final String DocSubTypeSO_POS
        Sales Order Sub Type - WR
        See Also:
      • DocSubTypeSO_Warehouse

        public static final String DocSubTypeSO_Warehouse
        Sales Order Sub Type - WP
        See Also:
      • DocSubTypeSO_OnCredit

        public static final String DocSubTypeSO_OnCredit
        Sales Order Sub Type - WI
        See Also:
      • DocSubTypeSO_RMA

        public static final String DocSubTypeSO_RMA
        Sales Order Sub Type - RM
        See Also:
      • m_processMsg

        protected String m_processMsg
        Process Message
      • m_justPrepared

        protected boolean m_justPrepared
        Just Prepared Flag
    • Constructor Details

      • MOrder

        public MOrder(Properties ctx, String C_Order_UU, String trxName)
        UUID based Constructor
        Parameters:
        ctx - Context
        C_Order_UU - UUID key
        trxName - Transaction
      • MOrder

        public MOrder(Properties ctx, int C_Order_ID, String trxName)
        Parameters:
        ctx - context
        C_Order_ID - order to load, (0 create new order)
        trxName - trx name
      • MOrder

        public MOrder(Properties ctx, int C_Order_ID, String trxName, String... virtualColumns)
        Parameters:
        ctx -
        C_Order_ID -
        trxName -
        virtualColumns -
      • MOrder

        public MOrder(MProject project, boolean IsSOTrx, String DocSubTypeSO)
        Project Constructor
        Parameters:
        project - Project to create Order from
        IsSOTrx - sales order
        DocSubTypeSO - if SO DocType Target (default DocSubTypeSO_OnCredit)
      • MOrder

        public MOrder(Properties ctx, ResultSet rs, String trxName)
        Load Constructor
        Parameters:
        ctx - context
        rs - result set record
        trxName - transaction
    • Method Details

      • getNotFullyMatchedToReceipt

        public static List<MOrder.MatchingRecord> getNotFullyMatchedToReceipt(int C_BPartner_ID, int M_Product_ID, int M_InOutLine_ID, Timestamp from, Timestamp to, String trxName)
        Parameters:
        C_BPartner_ID -
        M_Product_ID -
        M_InOutLine_ID -
        from -
        to -
        trxName -
        Returns:
        list of orders not fully matched to receipt
      • getFullOrPartiallyMatchedToReceipt

        public static List<MOrder.MatchingRecord> getFullOrPartiallyMatchedToReceipt(int C_BPartner_ID, int M_Product_ID, int M_InOutLine_ID, Timestamp from, Timestamp to, String trxName)
        Parameters:
        C_BPartner_ID -
        M_Product_ID -
        M_InOutLine_ID -
        from -
        to -
        trxName -
        Returns:
        list of orders full or partially match to receipt
      • getNotFullyMatchedToInvoice

        public static List<MOrder.MatchingRecord> getNotFullyMatchedToInvoice(int C_BPartner_ID, int M_Product_ID, int C_InvoiceLine_ID, Timestamp from, Timestamp to, String trxName)
        Parameters:
        C_BPartner_ID -
        M_Product_ID -
        C_InvoiceLine_ID -
        from -
        to -
        trxName -
        Returns:
        list of orders not fully matched to invoice
      • getFullOrPartiallyMatchedToInvoice

        public static List<MOrder.MatchingRecord> getFullOrPartiallyMatchedToInvoice(int C_BPartner_ID, int M_Product_ID, int C_InvoiceLine_ID, Timestamp from, Timestamp to, String trxName)
        Parameters:
        C_BPartner_ID -
        M_Product_ID -
        C_InvoiceLine_ID -
        from -
        to -
        trxName -
        Returns:
        list of orders full or partially match to invoice
      • copyFrom

        public static MOrder copyFrom(MOrder from, Timestamp dateDoc, int C_DocTypeTarget_ID, boolean isSOTrx, boolean counter, boolean copyASI, String trxName)
        Create new Order by copying
        Parameters:
        from - order
        dateDoc - date of the document date
        C_DocTypeTarget_ID - target document type
        isSOTrx - sales order
        counter - create counter links
        copyASI - copy line attributes Attribute Set Instance, Resaouce Assignment
        trxName - trx
        Returns:
        Order
      • setClientOrg

        public void setClientOrg(int AD_Client_ID, int AD_Org_ID)
        Overwrite Client/Org if required
        Overrides:
        setClientOrg in class PO
        Parameters:
        AD_Client_ID - client
        AD_Org_ID - org
      • addDescription

        public void addDescription(String description)
        Add to Description
        Parameters:
        description - text
      • setC_BPartner_ID

        public void setC_BPartner_ID(int C_BPartner_ID)
        Set Business Partner (Ship+Bill)
        Specified by:
        setC_BPartner_ID in interface I_C_Order
        Overrides:
        setC_BPartner_ID in class X_C_Order
        Parameters:
        C_BPartner_ID - bpartner
      • setC_BPartner_Location_ID

        public void setC_BPartner_Location_ID(int C_BPartner_Location_ID)
        Set Business Partner Location (Ship+Bill)
        Specified by:
        setC_BPartner_Location_ID in interface I_C_Order
        Overrides:
        setC_BPartner_Location_ID in class X_C_Order
        Parameters:
        C_BPartner_Location_ID - bp location
      • setAD_User_ID

        public void setAD_User_ID(int AD_User_ID)
        Set Business Partner Contact (Ship+Bill)
        Specified by:
        setAD_User_ID in interface I_C_Order
        Overrides:
        setAD_User_ID in class X_C_Order
        Parameters:
        AD_User_ID - contact
      • setShip_BPartner_ID

        public void setShip_BPartner_ID(int C_BPartner_ID)
        Set Ship Business Partner
        Parameters:
        C_BPartner_ID - bpartner
      • setShip_Location_ID

        public void setShip_Location_ID(int C_BPartner_Location_ID)
        Set Ship Business Partner Location
        Parameters:
        C_BPartner_Location_ID - bp location
      • setShip_User_ID

        public void setShip_User_ID(int AD_User_ID)
        Set Ship Business Partner Contact
        Parameters:
        AD_User_ID - contact
      • setM_Warehouse_ID

        public void setM_Warehouse_ID(int M_Warehouse_ID)
        Set Warehouse
        Specified by:
        setM_Warehouse_ID in interface I_C_Order
        Overrides:
        setM_Warehouse_ID in class X_C_Order
        Parameters:
        M_Warehouse_ID - warehouse
      • setIsDropShip

        public void setIsDropShip(boolean IsDropShip)
        Set Drop Ship
        Specified by:
        setIsDropShip in interface I_C_Order
        Overrides:
        setIsDropShip in class X_C_Order
        Parameters:
        IsDropShip - drop ship
      • setC_DocTypeTarget_ID

        public void setC_DocTypeTarget_ID(String DocSubTypeSO_x)
        Set Target Sales Document Type
        Parameters:
        DocSubTypeSO_x - SO sub type - see DocSubTypeSO_*
      • setC_DocTypeTarget_ID

        public void setC_DocTypeTarget_ID()
        Set Target Document Type. Standard Order or PO.
      • setBPartner

        public void setBPartner(MBPartner bp)
        Set Business Partner Defaults and Details. SOTrx should be set prior to this call.
        Parameters:
        bp - business partner
      • copyLinesFrom

        public int copyLinesFrom(MOrder otherOrder, boolean counter, boolean copyASI)
        Copy Lines From other Order
        Parameters:
        otherOrder - order
        counter - set counter info
        copyASI - true to copy line Attribute Set Instance and Resource Assignment
        Returns:
        number of lines copied
      • toString

        public String toString()
        String Representation
        Overrides:
        toString in class X_C_Order
        Returns:
        info
      • getDocumentInfo

        public String getDocumentInfo()
        Get Document Info
        Specified by:
        getDocumentInfo in interface DocAction
        Returns:
        document info (untranslated)
      • createPDF

        public File createPDF()
        Create PDF
        Specified by:
        createPDF in interface DocAction
        Returns:
        File or null
      • createPDF

        public File createPDF(File file)
        Create PDF file
        Parameters:
        file - output file
        Returns:
        file if success
      • setM_PriceList_ID

        public void setM_PriceList_ID(int M_PriceList_ID)
        Set Price List (and Currency, TaxIncluded) when valid
        Specified by:
        setM_PriceList_ID in interface I_C_Order
        Overrides:
        setM_PriceList_ID in class X_C_Order
        Parameters:
        M_PriceList_ID - price list
      • getLines

        public MOrderLine[] getLines(String whereClause, String orderClause)
        Get Lines of Order
        Parameters:
        whereClause - where clause or null (must start with AND)
        orderClause - order clause or null
        Returns:
        lines
      • getLines

        public MOrderLine[] getLines(boolean requery, String orderBy)
        Get Lines of Order
        Parameters:
        requery - true to re-query from DB
        orderBy - optional order by columns
        Returns:
        lines
      • getLines

        public MOrderLine[] getLines()
        Get Lines of Order.
        Returns:
        lines
      • renumberLines

        public void renumberLines(int step)
        Renumber Lines
        Parameters:
        step - start and step
      • isOrderLine

        public boolean isOrderLine(int C_OrderLine_ID)
        Does the Order Line belong to this Order
        Parameters:
        C_OrderLine_ID - line
        Returns:
        true if part of the order
      • getTaxes

        public MOrderTax[] getTaxes(boolean requery)
        Get Taxes of Order
        Parameters:
        requery - true to re-query from DB
        Returns:
        array of taxes
      • getInvoices

        public MInvoice[] getInvoices()
        Get Invoices of Order
        Returns:
        invoices
      • getC_Invoice_ID

        public int getC_Invoice_ID()
        Get latest Invoice of Order
        Returns:
        invoice id or 0
      • getShipments

        public MInOut[] getShipments()
        Get Shipments of Order
        Returns:
        shipments
      • getCurrencyISO

        public String getCurrencyISO()
        Get ISO Code of Currency
        Returns:
        Currency ISO
      • getPrecision

        public int getPrecision()
        Get Currency Precision
        Returns:
        precision
      • getDocStatusName

        public String getDocStatusName()
        Get Document Status Name
        Returns:
        Document Status Name
      • setDocAction

        public void setDocAction(String DocAction)
        Set DocAction
        Specified by:
        setDocAction in interface I_C_Order
        Overrides:
        setDocAction in class X_C_Order
        Parameters:
        DocAction - DocAction.ACTION_*
      • setDocAction

        public void setDocAction(String DocAction, boolean forceCreation)
        Set DocAction
        Parameters:
        DocAction - DocAction.ACTION_*
        forceCreation - force creation
      • setProcessed

        public void setProcessed(boolean processed)
        Set Processed. Propagate to Lines/Taxes
        Specified by:
        setProcessed in interface I_C_Order
        Overrides:
        setProcessed in class X_C_Order
        Parameters:
        processed - processed
      • validatePaySchedule

        public boolean validatePaySchedule()
        Validate Order Pay Schedule
        Returns:
        pay schedule is valid
      • beforeSave

        protected boolean beforeSave(boolean newRecord)
        Description copied from class: PO
        Called before Save for Pre-Save Operation.
        Default implementation is nop, to be implemented in sub-classes that needed it.
        Overrides:
        beforeSave in class PO
        Parameters:
        newRecord - true if it is a new record
        Returns:
        true if record can be saved
      • afterSave

        protected boolean afterSave(boolean newRecord, boolean success)
        Description copied from class: PO
        Called after Save for Post-Save Operation.
        Default implementation is nop, to be implemented in sub-classes that needed it.
        Overrides:
        afterSave in class PO
        Parameters:
        newRecord - true if it is a new record
        success - true if save operation was success
        Returns:
        if save was a success
      • beforeDelete

        protected boolean beforeDelete()
        Description copied from class: PO
        Execute before Delete operations.
        Default implementation is nop, to be implemented in sub-classes that needed it.
        Overrides:
        beforeDelete in class PO
        Returns:
        true if record can be deleted
      • processIt

        public boolean processIt(String processAction)
        Process document
        Specified by:
        processIt in interface DocAction
        Parameters:
        processAction - document action
        Returns:
        true if performed
      • unlockIt

        public boolean unlockIt()
        Unlock Document.
        Specified by:
        unlockIt in interface DocAction
        Returns:
        true if success
      • invalidateIt

        public boolean invalidateIt()
        Invalidate Document
        Specified by:
        invalidateIt in interface DocAction
        Returns:
        true if success
      • prepareIt

        public String prepareIt()
        Prepare Document
        Specified by:
        prepareIt in interface DocAction
        Returns:
        new status (In Progress or Invalid)
      • calculateFreightCharge

        protected boolean calculateFreightCharge()
        Calculate freight charge and create order line for freight charge (if needed).
        Returns:
        true if no error
      • explodeBOM

        protected boolean explodeBOM()
        Explode non stocked BOM (i.e IsBOM=Y and IsStocked=N).
        Returns:
        true if bom exploded
      • reserveStock

        protected boolean reserveStock(MDocType dt, MOrderLine[] lines)
        Reserve Inventory. Release of reservation: MInOut.completeIt().
        Parameters:
        dt - document type or null
        lines - order lines (ordered by M_Product_ID for deadlock prevention)
        Returns:
        true if (un) reserved
      • calculateTaxTotal

        public boolean calculateTaxTotal()
        Calculate Tax and Total (delete and re-create C_OrderTax records).
        Returns:
        true if no error
      • createPaySchedule

        protected boolean createPaySchedule()
        (Re) Create Pay Schedule
        Returns:
        true if valid schedule
      • approveIt

        public boolean approveIt()
        Approve Document
        Specified by:
        approveIt in interface DocAction
        Returns:
        true if success
      • rejectIt

        public boolean rejectIt()
        Reject Approval
        Specified by:
        rejectIt in interface DocAction
        Returns:
        true if success
      • completeIt

        public String completeIt()
        Complete Document
        Specified by:
        completeIt in interface DocAction
        Returns:
        new status (Complete, In Progress, Invalid, Waiting ..)
      • landedCostAllocation

        protected String landedCostAllocation()
        distribute landed cost.
        Returns:
        error message or empty string
      • createPOSPayments

        protected String createPOSPayments()
        Returns:
        error message or null
      • setDefiniteDocumentNo

        protected void setDefiniteDocumentNo()
        Set the definite document number after completed
      • createShipment

        protected MInOut createShipment(MDocType dt, Timestamp movementDate)
        Create Shipment
        Parameters:
        dt - order document type
        movementDate - optional movement date (default today)
        Returns:
        shipment or null
      • createInvoice

        protected MInvoice createInvoice(MDocType dt, MInOut shipment, Timestamp invoiceDate)
        Create Invoice
        Parameters:
        dt - order document type
        shipment - optional shipment
        invoiceDate - invoice date
        Returns:
        invoice or null
      • createCounterDoc

        protected MOrder createCounterDoc()
        Create Counter Document
        Returns:
        counter order
      • voidIt

        public boolean voidIt()
        Void Document. Set Qtys to 0 - Sales: reverse all documents
        Specified by:
        voidIt in interface DocAction
        Returns:
        true if success
      • createReversals

        protected boolean createReversals()
        Create Shipment/Invoice Reversals
        Returns:
        true if success
      • createPOReversals

        protected boolean createPOReversals()
        Create match po reversals
        Returns:
        true if success
      • closeIt

        public boolean closeIt()
        Close Document. Cancel not delivered Quantities.
        Specified by:
        closeIt in interface DocAction
        Returns:
        true if success
      • reopenIt

        public String reopenIt()
        Returns:
        error message or null
      • reverseCorrectIt

        public boolean reverseCorrectIt()
        Reverse Correction - same as void
        Specified by:
        reverseCorrectIt in interface DocAction
        Returns:
        true if success
      • reverseAccrualIt

        public boolean reverseAccrualIt()
        Reverse Accrual
        Specified by:
        reverseAccrualIt in interface DocAction
        Returns:
        not implemented, always return false
      • reActivateIt

        public boolean reActivateIt()
        Re-activate.
        Specified by:
        reActivateIt in interface DocAction
        Returns:
        true if success
      • getSummary

        public String getSummary()
        Get Summary
        Specified by:
        getSummary in interface DocAction
        Returns:
        Summary of Document
      • getProcessMsg

        public String getProcessMsg()
        Get Process Message
        Specified by:
        getProcessMsg in interface DocAction
        Returns:
        clear text error message
      • getDoc_User_ID

        public int getDoc_User_ID()
        Get Document Owner (Responsible)
        Specified by:
        getDoc_User_ID in interface DocAction
        Returns:
        AD_User_ID
      • getApprovalAmt

        public BigDecimal getApprovalAmt()
        Get Document Approval Amount
        Specified by:
        getApprovalAmt in interface DocAction
        Returns:
        amount
      • deleteMatchPOCostDetail

        protected String deleteMatchPOCostDetail(MOrderLine line)
        Delete cost detail for order line
        Parameters:
        line -
        Returns:
        error message or null
      • isComplete

        public boolean isComplete()
        Document Status is Complete or Closed
        Returns:
        true if CO, CL or RE
      • setProcessMessage

        public void setProcessMessage(String processMsg)
        Set process message
        Parameters:
        processMsg -
      • getTaxProviders

        public MTaxProvider[] getTaxProviders()
        Get tax providers
        Returns:
        array of tax provider
      • getDocTypeID

        public int getDocTypeID()
        Returns C_DocType_ID (or C_DocTypeTarget_ID if C_DocType_ID is not set)
      • getPaymentAmt

        public BigDecimal getPaymentAmt()
        Returns:
        payment amount for order (prepayment + invoice payment)