use of org.compiere.model.MClient in project adempiere by adempiere.
the class WebSessionCtx method getDefaults.
// setWStore
/**
* Get Web Store Defaults
* @return context
*/
private Properties getDefaults() {
// No Web Store
if (wstore == null)
return new Properties();
//
Integer key = new Integer(wstore.getW_Store_ID());
Properties newCtx = (Properties) s_cacheCtx.get(key);
/** Create New Context */
if (newCtx == null) {
log.info(wstore.getWebContext());
newCtx = new Properties();
// copy explicitly
Enumeration e = ctx.keys();
while (e.hasMoreElements()) {
String pKey = (String) e.nextElement();
newCtx.setProperty(pKey, ctx.getProperty(pKey));
}
Env.setContext(newCtx, "#AD_Client_ID", wstore.getAD_Client_ID());
Env.setContext(newCtx, "#AD_Org_ID", wstore.getAD_Org_ID());
//
Env.setContext(newCtx, "#SalesRep_ID", wstore.getSalesRep_ID());
Env.setContext(newCtx, "#M_PriceList_ID", wstore.getM_PriceList_ID());
Env.setContext(newCtx, "#M_Warehouse_ID", wstore.getM_Warehouse_ID());
//
String s = wstore.getWebParam1();
Env.setContext(newCtx, "webParam1", s == null ? "" : s);
s = wstore.getWebParam2();
Env.setContext(newCtx, "webParam2", s == null ? "" : s);
s = wstore.getWebParam3();
Env.setContext(newCtx, "webParam3", s == null ? "" : s);
s = wstore.getWebParam4();
Env.setContext(newCtx, "webParam4", s == null ? "" : s);
s = wstore.getWebParam5();
Env.setContext(newCtx, "webParam5", s == null ? "" : s);
s = wstore.getWebParam6();
Env.setContext(newCtx, "webParam6", s == null ? "" : s);
s = wstore.getStylesheet();
if (s == null)
s = "standard";
else {
int index = s.lastIndexOf('.');
if (index != -1)
s = s.substring(0, index);
}
Env.setContext(newCtx, "Stylesheet", s);
//
s = wstore.getWebInfo();
if (s != null && s.length() > 0)
Env.setContext(newCtx, HDR_INFO, s);
// Payment Term
Env.setContext(newCtx, "#M_PriceList_ID", wstore.getM_PriceList_ID());
// Default User - SalesRep
if (Env.getContextAsInt(newCtx, "#AD_User_ID") == 0)
Env.setContext(newCtx, "#AD_User_ID", wstore.getSalesRep_ID());
// Default Role for access
if (Env.getContextAsInt(newCtx, "#AD_Role_ID") == 0) {
// HARDCODED - System
int AD_Role_ID = 0;
Env.setContext(newCtx, "#AD_Role_ID", AD_Role_ID);
}
// Client
MClient client = MClient.get(newCtx, wstore.getAD_Client_ID());
// Name,Description, SMTPHost,RequestEMail,RequestUser, RequestUserPw
Env.setContext(newCtx, "name", client.getName());
Env.setContext(newCtx, "description", client.getDescription());
// AD_Language
if (newCtx.getProperty("#AD_Language") == null && client.getAD_Language() != null)
Env.setContext(newCtx, "#AD_Language", client.getAD_Language());
// DocumentDir
String docDir = client.getDocumentDir();
Env.setContext(newCtx, CTX_DOCUMENT_DIR, docDir == null ? "" : docDir);
// Default Language
if (newCtx.getProperty("#AD_Language") == null)
Env.setContext(newCtx, "#AD_Language", "en_US");
// Save Context - Key is AD_Client_ID
s_cacheCtx.put(key, newCtx);
}
// return new Properties (pp); seems not to work with JSP
Enumeration e = newCtx.keys();
while (e.hasMoreElements()) {
String pKey = (String) e.nextElement();
ctx.setProperty(pKey, newCtx.getProperty(pKey));
}
return ctx;
}
use of org.compiere.model.MClient in project adempiere by adempiere.
the class MWFActivity method performWork.
// run
/**
* Perform Work.
* Set Text Msg.
* @param trx transaction
* @return true if completed, false otherwise
* @throws Exception if error
*/
private boolean performWork(Trx trx) throws Exception {
log.info(m_node + " [" + trx.getTrxName() + "]");
m_docStatus = null;
if (// overwrite priority if defined
m_node.getPriority() != 0)
setPriority(m_node.getPriority());
String action = m_node.getAction();
/****** Sleep (Start/End) ******/
if (MWFNode.ACTION_WaitSleep.equals(action)) {
log.fine("Sleep:WaitTime=" + m_node.getWaitTime());
if (m_node.getWaitingTime() == 0)
// done
return true;
Calendar cal = Calendar.getInstance();
cal.add(m_node.getDurationCalendarField(), m_node.getWaitTime());
setEndWaitTime(new Timestamp(cal.getTimeInMillis()));
// not done
return false;
} else /****** Document Action ******/
if (MWFNode.ACTION_DocumentAction.equals(action)) {
log.fine("DocumentAction=" + m_node.getDocAction());
getPO(trx);
if (m_po == null)
throw new Exception("Persistent Object not found - AD_Table_ID=" + getAD_Table_ID() + ", Record_ID=" + getRecord_ID());
boolean success = false;
String processMsg = null;
DocAction doc = null;
if (m_po instanceof DocAction) {
doc = (DocAction) m_po;
//
try {
// ** Do the work
success = doc.processIt(m_node.getDocAction());
setTextMsg(doc.getSummary());
processMsg = doc.getProcessMsg();
// the rest of methods return boolean, so doc status must not be taken into account when not successful
if (DocAction.ACTION_Prepare.equals(m_node.getDocAction()) || DocAction.ACTION_Complete.equals(m_node.getDocAction()) || success)
m_docStatus = doc.getDocStatus();
} catch (Exception e) {
if (m_process != null)
m_process.setProcessMsg(e.getLocalizedMessage());
throw e;
}
if (m_process != null)
m_process.setProcessMsg(processMsg);
} else
throw new IllegalStateException("Persistent Object not DocAction - " + m_po.getClass().getName() + " - AD_Table_ID=" + getAD_Table_ID() + ", Record_ID=" + getRecord_ID());
//
if (!m_po.save()) {
success = false;
processMsg = "SaveError";
}
if (!success) {
if (processMsg == null || processMsg.length() == 0) {
processMsg = "PerformWork Error - " + m_node.toStringX();
if (// problem: status will be rolled back
doc != null)
processMsg += " - DocStatus=" + doc.getDocStatus();
}
throw new Exception(processMsg);
}
return success;
} else /****** Report ******/
if (MWFNode.ACTION_AppsReport.equals(action)) {
log.fine("Report:AD_Process_ID=" + m_node.getAD_Process_ID());
// Process
MProcess process = MProcess.get(getCtx(), m_node.getAD_Process_ID());
process.set_TrxName(trx != null ? trx.getTrxName() : null);
if (!process.isReport() || process.getAD_ReportView_ID() == 0)
throw new IllegalStateException("Not a Report AD_Process_ID=" + m_node.getAD_Process_ID());
//
ProcessInfo pi = new ProcessInfo(m_node.getName(true), m_node.getAD_Process_ID(), getAD_Table_ID(), getRecord_ID());
pi.setAD_User_ID(getAD_User_ID());
pi.setAD_Client_ID(getAD_Client_ID());
MPInstance pInstance = new MPInstance(process, getRecord_ID());
pInstance.set_TrxName(trx != null ? trx.getTrxName() : null);
fillParameter(pInstance, trx);
pi.setAD_PInstance_ID(pInstance.getAD_PInstance_ID());
// Report
ReportEngine re = ReportEngine.get(getCtx(), pi);
if (re == null)
throw new IllegalStateException("Cannot create Report AD_Process_ID=" + m_node.getAD_Process_ID());
File report = re.getPDF();
// Notice
// HARDCODED WorkflowResult
int AD_Message_ID = 753;
MNote note = new MNote(getCtx(), AD_Message_ID, getAD_User_ID(), trx.getTrxName());
note.setTextMsg(m_node.getName(true));
note.setDescription(m_node.getDescription(true));
note.setRecord(getAD_Table_ID(), getRecord_ID());
note.saveEx();
// Attachment
MAttachment attachment = new MAttachment(getCtx(), MNote.Table_ID, note.getAD_Note_ID(), get_TrxName());
attachment.addEntry(report);
attachment.setTextMsg(m_node.getName(true));
attachment.saveEx();
return true;
} else /****** Process ******/
if (MWFNode.ACTION_AppsProcess.equals(action)) {
log.fine("Process:AD_Process_ID=" + m_node.getAD_Process_ID());
// Process
MProcess process = MProcess.get(getCtx(), m_node.getAD_Process_ID());
MPInstance pInstance = new MPInstance(process, getRecord_ID());
fillParameter(pInstance, trx);
//
ProcessInfo pi = new ProcessInfo(m_node.getName(true), m_node.getAD_Process_ID(), getAD_Table_ID(), getRecord_ID());
pi.setAD_User_ID(getAD_User_ID());
pi.setAD_Client_ID(getAD_Client_ID());
pi.setAD_PInstance_ID(pInstance.getAD_PInstance_ID());
return process.processItWithoutTrxClose(pi, trx);
} else /****** EMail ******/
if (MWFNode.ACTION_EMail.equals(action)) {
log.fine("EMail:EMailRecipient=" + m_node.getEMailRecipient());
getPO(trx);
if (m_po == null)
throw new Exception("Persistent Object not found - AD_Table_ID=" + getAD_Table_ID() + ", Record_ID=" + getRecord_ID());
if (m_po instanceof DocAction) {
m_emails = new ArrayList<String>();
sendEMail();
setTextMsg(m_emails.toString());
} else {
MClient client = MClient.get(getCtx(), getAD_Client_ID());
MMailText mailtext = new MMailText(getCtx(), getNode().getR_MailText_ID(), null);
String subject = getNode().getDescription() + ": " + mailtext.getMailHeader();
String message = mailtext.getMailText(true) + "\n-----\n" + getNodeHelp();
String to = getNode().getEMail();
client.sendEMail(to, subject, message, null);
}
// done
return true;
} else /****** Set Variable ******/
if (MWFNode.ACTION_SetVariable.equals(action)) {
String value = m_node.getAttributeValue();
log.fine("SetVariable:AD_Column_ID=" + m_node.getAD_Column_ID() + " to " + value);
MColumn column = m_node.getColumn();
int dt = column.getAD_Reference_ID();
return setVariable(value, dt, null, trx);
} else /****** TODO Start WF Instance ******/
if (MWFNode.ACTION_SubWorkflow.equals(action)) {
log.warning("Workflow:AD_Workflow_ID=" + m_node.getAD_Workflow_ID());
log.warning("Start WF Instance is not implemented yet");
} else /****** User Choice ******/
if (MWFNode.ACTION_UserChoice.equals(action)) {
log.fine("UserChoice:AD_Column_ID=" + m_node.getAD_Column_ID());
// Approval
if (m_node.isUserApproval() && getPO(trx) instanceof DocAction) {
DocAction doc = (DocAction) m_po;
boolean autoApproval = false;
// Approval Hierarchy
if (isInvoker()) {
// Set Approver
int startAD_User_ID = Env.getAD_User_ID(getCtx());
if (startAD_User_ID == 0)
startAD_User_ID = doc.getDoc_User_ID();
int nextAD_User_ID = getApprovalUser(startAD_User_ID, doc.getC_Currency_ID(), doc.getApprovalAmt(), doc.getAD_Org_ID(), // own doc
startAD_User_ID == doc.getDoc_User_ID());
// same user = approved
autoApproval = startAD_User_ID == nextAD_User_ID;
if (!autoApproval)
setAD_User_ID(nextAD_User_ID);
} else // fixed Approver
{
MWFResponsible resp = getResponsible();
// [ 1742751 ] Workflow: User Choice is not working
if (resp.isHuman()) {
autoApproval = resp.getAD_User_ID() == Env.getAD_User_ID(getCtx());
if (!autoApproval && resp.getAD_User_ID() != 0)
setAD_User_ID(resp.getAD_User_ID());
} else if (resp.isRole()) {
MUserRoles[] urs = MUserRoles.getOfRole(getCtx(), resp.getAD_Role_ID());
for (int i = 0; i < urs.length; i++) {
if (urs[i].getAD_User_ID() == Env.getAD_User_ID(getCtx())) {
autoApproval = true;
break;
}
}
} else if (resp.isOrganization()) {
throw new AdempiereException("Support not implemented for " + resp);
} else {
throw new AdempiereException("@NotSupported@ " + resp);
}
// end MZ
}
if (autoApproval && doc.processIt(DocAction.ACTION_Approve) && doc.save())
// done
return true;
}
// wait for user
return false;
} else /****** User Form ******/
if (MWFNode.ACTION_UserForm.equals(action)) {
log.fine("Form:AD_Form_ID=" + m_node.getAD_Form_ID());
return false;
} else if (MWFNode.ACTION_SmartBrowse.equals(action)) {
log.fine("Form:AD_Browse_ID=" + m_node.getAD_Browse_ID());
return false;
} else /****** User Window ******/
if (MWFNode.ACTION_UserWindow.equals(action)) {
log.fine("Window:AD_Window_ID=" + m_node.getAD_Window_ID());
return false;
}
//
throw new IllegalArgumentException("Invalid Action (Not Implemented) =" + action);
}
use of org.compiere.model.MClient in project adempiere by adempiere.
the class Viewer method cmd_find.
// cmd_report
/**
* Query Report
*/
private void cmd_find() {
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
int AD_Table_ID = m_reportEngine.getPrintFormat().getAD_Table_ID();
String title = null;
String tableName = null;
// Get Find Tab Info
String sql = "SELECT t.AD_Tab_ID " + // ,w.Name, t.Name, w.IsDefault, t.SeqNo, ABS (tt.AD_Window_ID-t.AD_Window_ID)
"FROM AD_Tab t" + " INNER JOIN AD_Window w ON (t.AD_Window_ID=w.AD_Window_ID)" + " INNER JOIN AD_Table tt ON (t.AD_Table_ID=tt.AD_Table_ID) " + "WHERE tt.AD_Table_ID=? " + "ORDER BY w.IsDefault DESC, t.SeqNo, ABS (tt.AD_Window_ID-t.AD_Window_ID)";
int AD_Tab_ID = DB.getSQLValue(null, sql, AD_Table_ID);
// ASP
MClient client = MClient.get(Env.getCtx());
String ASPFilter = "";
if (client.isUseASP())
ASPFilter = " AND ( AD_Tab_ID IN ( " + // Just ASP subscribed tabs for client "
" SELECT t.AD_Tab_ID " + " FROM ASP_Tab t, ASP_Window w, ASP_Level l, ASP_ClientLevel cl " + " WHERE w.ASP_Level_ID = l.ASP_Level_ID " + " AND cl.AD_Client_ID = " + client.getAD_Client_ID() + " AND cl.ASP_Level_ID = l.ASP_Level_ID " + " AND t.ASP_Window_ID = w.ASP_Window_ID " + " AND t.IsActive = 'Y' " + " AND w.IsActive = 'Y' " + " AND l.IsActive = 'Y' " + " AND cl.IsActive = 'Y' " + // Show
" AND t.ASP_Status = 'S') " + " OR AD_Tab_ID IN ( " + // + show ASP exceptions for client
" SELECT AD_Tab_ID " + " FROM ASP_ClientException ce " + " WHERE ce.AD_Client_ID = " + client.getAD_Client_ID() + " AND ce.IsActive = 'Y' " + " AND ce.AD_Tab_ID IS NOT NULL " + " AND ce.AD_Field_ID IS NULL " + // Show
" AND ce.ASP_Status = 'S') " + " ) " + " AND AD_Tab_ID NOT IN ( " + // minus hide ASP exceptions for client
" SELECT AD_Tab_ID " + " FROM ASP_ClientException ce " + " WHERE ce.AD_Client_ID = " + client.getAD_Client_ID() + " AND ce.IsActive = 'Y' " + " AND ce.AD_Tab_ID IS NOT NULL " + " AND ce.AD_Field_ID IS NULL " + // Hide
" AND ce.ASP_Status = 'H')";
//
sql = "SELECT Name, TableName FROM AD_Tab_v WHERE AD_Tab_ID=? " + ASPFilter;
if (!Env.isBaseLanguage(Env.getCtx(), "AD_Tab"))
sql = "SELECT Name, TableName FROM AD_Tab_vt WHERE AD_Tab_ID=?" + " AND AD_Language='" + Env.getAD_Language(Env.getCtx()) + "' " + ASPFilter;
try {
PreparedStatement pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, AD_Tab_ID);
ResultSet rs = pstmt.executeQuery();
//
if (rs.next()) {
title = rs.getString(1);
tableName = rs.getString(2);
}
//
rs.close();
pstmt.close();
} catch (SQLException e) {
log.log(Level.SEVERE, sql, e);
}
GridField[] findFields = null;
if (tableName != null)
findFields = GridField.createFields(m_ctx, m_WindowNo, 0, AD_Tab_ID);
// FR [ 295 ]
if (findFields == null) {
// No Tab for Table exists
if (launchProcessPara()) {
revalidate();
} else {
return;
}
} else {
ASearch search = new ASearch(bFind, this, title, AD_Tab_ID, AD_Table_ID, tableName, m_reportEngine, findFields, 1);
search = null;
revalidate();
}
// setCursor
cmd_drill();
}
use of org.compiere.model.MClient in project adempiere by adempiere.
the class ReplenishReportProduction method createMovements.
// createRequisition
/**
* Create Inventory Movements
*/
private void createMovements() {
int noMoves = 0;
String info = "";
//
MClient client = null;
MMovement move = null;
int M_Warehouse_ID = 0;
int M_WarehouseSource_ID = 0;
MWarehouse whSource = null;
MWarehouse wh = null;
X_T_Replenish[] replenishs = getReplenish("M_WarehouseSource_ID IS NOT NULL AND C_BPartner_ID > 0");
for (int i = 0; i < replenishs.length; i++) {
X_T_Replenish replenish = replenishs[i];
if (whSource == null || whSource.getM_WarehouseSource_ID() != replenish.getM_WarehouseSource_ID())
whSource = MWarehouse.get(getCtx(), replenish.getM_WarehouseSource_ID());
if (wh == null || wh.getM_Warehouse_ID() != replenish.getM_Warehouse_ID())
wh = MWarehouse.get(getCtx(), replenish.getM_Warehouse_ID());
if (client == null || client.getAD_Client_ID() != whSource.getAD_Client_ID())
client = MClient.get(getCtx(), whSource.getAD_Client_ID());
//
if (move == null || M_WarehouseSource_ID != replenish.getM_WarehouseSource_ID() || M_Warehouse_ID != replenish.getM_Warehouse_ID()) {
M_WarehouseSource_ID = replenish.getM_WarehouseSource_ID();
M_Warehouse_ID = replenish.getM_Warehouse_ID();
move = new MMovement(getCtx(), 0, get_TrxName());
move.setC_DocType_ID(p_C_DocType_ID);
move.setDescription(Msg.getMsg(getCtx(), "Replenishment") + ": " + whSource.getName() + "->" + wh.getName());
// Set Org
move.setAD_Org_ID(whSource.getAD_Org_ID());
if (!move.save())
return;
log.fine(move.toString());
noMoves++;
info += " - " + move.getDocumentNo();
}
// To
int M_LocatorTo_ID = wh.getDefaultLocator().getM_Locator_ID();
// From: Look-up Storage
MProduct product = MProduct.get(getCtx(), replenish.getM_Product_ID());
String MMPolicy = product.getMMPolicy();
MStorage[] storages = MStorage.getWarehouse(getCtx(), whSource.getM_Warehouse_ID(), replenish.getM_Product_ID(), 0, 0, true, null, MClient.MMPOLICY_FiFo.equals(MMPolicy), get_TrxName());
//
BigDecimal target = replenish.getQtyToOrder();
for (int j = 0; j < storages.length; j++) {
MStorage storage = storages[j];
if (storage.getQtyOnHand().signum() <= 0)
continue;
BigDecimal moveQty = target;
if (storage.getQtyOnHand().compareTo(moveQty) < 0)
moveQty = storage.getQtyOnHand();
//
MMovementLine line = new MMovementLine(move);
line.setM_Product_ID(replenish.getM_Product_ID());
line.setMovementQty(moveQty);
if (replenish.getQtyToOrder().compareTo(moveQty) != 0)
line.setDescription("Total: " + replenish.getQtyToOrder());
// from
line.setM_Locator_ID(storage.getM_Locator_ID());
line.setM_AttributeSetInstance_ID(storage.getM_AttributeSetInstance_ID());
// to
line.setM_LocatorTo_ID(M_LocatorTo_ID);
line.setM_AttributeSetInstanceTo_ID(storage.getM_AttributeSetInstance_ID());
line.save();
//
target = target.subtract(moveQty);
if (target.signum() == 0)
break;
}
}
if (replenishs.length == 0) {
m_info = "No Source Warehouse";
log.warning(m_info);
} else {
m_info = "#" + noMoves + info;
log.info(m_info);
}
}
use of org.compiere.model.MClient in project adempiere by adempiere.
the class ReplenishReportProduction method createDO.
// Create Inventory Movements
/**
* Create Distribution Order
*/
private void createDO() throws Exception {
int noMoves = 0;
String info = "";
//
MClient client = null;
MDDOrder order = null;
int M_Warehouse_ID = 0;
int M_WarehouseSource_ID = 0;
MWarehouse whSource = null;
MWarehouse wh = null;
X_T_Replenish[] replenishs = getReplenish("M_WarehouseSource_ID IS NOT NULL");
for (X_T_Replenish replenish : replenishs) {
if (whSource == null || whSource.getM_WarehouseSource_ID() != replenish.getM_WarehouseSource_ID())
whSource = MWarehouse.get(getCtx(), replenish.getM_WarehouseSource_ID());
if (wh == null || wh.getM_Warehouse_ID() != replenish.getM_Warehouse_ID())
wh = MWarehouse.get(getCtx(), replenish.getM_Warehouse_ID());
if (client == null || client.getAD_Client_ID() != whSource.getAD_Client_ID())
client = MClient.get(getCtx(), whSource.getAD_Client_ID());
//
if (order == null || M_WarehouseSource_ID != replenish.getM_WarehouseSource_ID() || M_Warehouse_ID != replenish.getM_Warehouse_ID()) {
M_WarehouseSource_ID = replenish.getM_WarehouseSource_ID();
M_Warehouse_ID = replenish.getM_Warehouse_ID();
order = new MDDOrder(getCtx(), 0, get_TrxName());
order.setC_DocType_ID(p_C_DocType_ID);
order.setDescription(Msg.getMsg(getCtx(), "Replenishment") + ": " + whSource.getName() + "->" + wh.getName());
// Set Org
order.setAD_Org_ID(whSource.getAD_Org_ID());
// Set Org Trx
MOrg orgTrx = MOrg.get(getCtx(), wh.getAD_Org_ID());
order.setAD_OrgTrx_ID(orgTrx.getAD_Org_ID());
int C_BPartner_ID = orgTrx.getLinkedC_BPartner_ID(get_TrxName());
if (C_BPartner_ID == 0)
throw new AdempiereUserError(Msg.translate(getCtx(), "C_BPartner_ID") + " @FillMandatory@ ");
MBPartner bp = new MBPartner(getCtx(), C_BPartner_ID, get_TrxName());
// Set BPartner Link to Org
order.setBPartner(bp);
order.setDateOrdered(new Timestamp(System.currentTimeMillis()));
//order.setDatePromised(DatePromised);
order.setDeliveryRule(MDDOrder.DELIVERYRULE_Availability);
order.setDeliveryViaRule(MDDOrder.DELIVERYVIARULE_Delivery);
order.setPriorityRule(MDDOrder.PRIORITYRULE_Medium);
order.setIsInDispute(false);
order.setIsApproved(false);
order.setIsDropShip(false);
order.setIsDelivered(false);
order.setIsInTransit(false);
order.setIsPrinted(false);
order.setIsSelected(false);
order.setIsSOTrx(false);
// Warehouse in Transit
MWarehouse[] whsInTransit = MWarehouse.getForOrg(getCtx(), whSource.getAD_Org_ID());
for (MWarehouse whInTransit : whsInTransit) {
if (whInTransit.isInTransit())
order.setM_Warehouse_ID(whInTransit.getM_Warehouse_ID());
}
if (order.getM_Warehouse_ID() == 0)
throw new AdempiereUserError("Warehouse inTransit is @FillMandatory@ ");
if (!order.save())
return;
log.fine(order.toString());
noMoves++;
info += " - " + order.getDocumentNo();
}
// To
int M_LocatorTo_ID = wh.getDefaultLocator().getM_Locator_ID();
int M_Locator_ID = whSource.getDefaultLocator().getM_Locator_ID();
if (M_LocatorTo_ID == 0 || M_Locator_ID == 0)
throw new AdempiereUserError(Msg.translate(getCtx(), "M_Locator_ID") + " @FillMandatory@ ");
// From: Look-up Storage
/*MProduct product = MProduct.get(getCtx(), replenish.getM_Product_ID());
MProductCategory pc = MProductCategory.get(getCtx(), product.getM_Product_Category_ID());
String MMPolicy = pc.getMMPolicy();
if (MMPolicy == null || MMPolicy.length() == 0)
MMPolicy = client.getMMPolicy();
//
MStorage[] storages = MStorage.getWarehouse(getCtx(),
whSource.getM_Warehouse_ID(), replenish.getM_Product_ID(), 0, 0,
true, null,
MClient.MMPOLICY_FiFo.equals(MMPolicy), get_TrxName());
BigDecimal target = replenish.getQtyToOrder();
for (int j = 0; j < storages.length; j++)
{
MStorage storage = storages[j];
if (storage.getQtyOnHand().signum() <= 0)
continue;
BigDecimal moveQty = target;
if (storage.getQtyOnHand().compareTo(moveQty) < 0)
moveQty = storage.getQtyOnHand();
//
MDDOrderLine line = new MDDOrderLine(order);
line.setM_Product_ID(replenish.getM_Product_ID());
line.setQtyEntered(moveQty);
if (replenish.getQtyToOrder().compareTo(moveQty) != 0)
line.setDescription("Total: " + replenish.getQtyToOrder());
line.setM_Locator_ID(storage.getM_Locator_ID()); // from
line.setM_AttributeSetInstance_ID(storage.getM_AttributeSetInstance_ID());
line.setM_LocatorTo_ID(M_LocatorTo_ID); // to
line.setM_AttributeSetInstanceTo_ID(storage.getM_AttributeSetInstance_ID());
line.setIsInvoiced(false);
line.save();
//
target = target.subtract(moveQty);
if (target.signum() == 0)
break;
}*/
MDDOrderLine line = new MDDOrderLine(order);
line.setM_Product_ID(replenish.getM_Product_ID());
line.setQty(replenish.getQtyToOrder());
if (replenish.getQtyToOrder().compareTo(replenish.getQtyToOrder()) != 0)
line.setDescription("Total: " + replenish.getQtyToOrder());
// from
line.setM_Locator_ID(M_Locator_ID);
line.setM_AttributeSetInstance_ID(0);
// to
line.setM_LocatorTo_ID(M_LocatorTo_ID);
line.setM_AttributeSetInstanceTo_ID(0);
line.setIsInvoiced(false);
line.save();
}
if (replenishs.length == 0) {
m_info = "No Source Warehouse";
log.warning(m_info);
} else {
m_info = "#" + noMoves + info;
log.info(m_info);
}
}
Aggregations