use of org.compiere.model.MBPartner in project adempiere by adempiere.
the class BPartnerOrgUnLink method doIt.
// prepare
/**
* Perform process.
* @return Message (text with variables)
* @throws Exception if not successful
*/
protected String doIt() throws Exception {
log.info("doIt - C_BPartner_ID=" + p_C_BPartner_ID);
if (p_C_BPartner_ID == 0)
throw new IllegalArgumentException("No Business Partner ID");
MBPartner bp = new MBPartner(getCtx(), p_C_BPartner_ID, get_TrxName());
if (bp.get_ID() == 0)
throw new IllegalArgumentException("Business Partner not found - C_BPartner_ID=" + p_C_BPartner_ID);
//
if (bp.getAD_OrgBP_ID_Int() == 0)
throw new IllegalArgumentException("Business Partner not linked to an Organization");
bp.setAD_OrgBP_ID(null);
if (!bp.save())
throw new IllegalArgumentException("Business Partner not changed");
return "OK";
}
use of org.compiere.model.MBPartner in project adempiere by adempiere.
the class ReplenishReport method createPO.
// fillTable
/**
* Create PO's
*/
private void createPO() {
int noOrders = 0;
String info = "";
//
MOrder order = null;
MWarehouse wh = null;
X_T_Replenish[] replenishs = getReplenish("M_WarehouseSource_ID IS NULL");
for (int i = 0; i < replenishs.length; i++) {
X_T_Replenish replenish = replenishs[i];
if (wh == null || wh.getM_Warehouse_ID() != replenish.getM_Warehouse_ID())
wh = MWarehouse.get(getCtx(), replenish.getM_Warehouse_ID());
//
if (order == null || order.getC_BPartner_ID() != replenish.getC_BPartner_ID() || order.getM_Warehouse_ID() != replenish.getM_Warehouse_ID()) {
order = new MOrder(getCtx(), 0, get_TrxName());
order.setIsSOTrx(false);
order.setC_DocTypeTarget_ID(p_C_DocType_ID);
MBPartner bp = new MBPartner(getCtx(), replenish.getC_BPartner_ID(), get_TrxName());
order.setBPartner(bp);
order.setSalesRep_ID(getAD_User_ID());
order.setDescription(Msg.getMsg(getCtx(), "Replenishment"));
// Set Org/WH
order.setAD_Org_ID(wh.getAD_Org_ID());
order.setM_Warehouse_ID(wh.getM_Warehouse_ID());
if (!order.save())
return;
log.fine(order.toString());
noOrders++;
info += " - " + order.getDocumentNo();
}
MOrderLine line = new MOrderLine(order);
line.setM_Product_ID(replenish.getM_Product_ID());
line.setQty(replenish.getQtyToOrder());
line.setPrice();
line.saveEx();
}
m_info = "#" + noOrders + info;
log.info(m_info);
}
use of org.compiere.model.MBPartner in project adempiere by adempiere.
the class ReplenishReport 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 = getReplenishDO("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.saveEx();
//
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.saveEx();
}
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.MBPartner in project adempiere by adempiere.
the class MBPartnerLocationTest method testCreatePartnerLocation.
public void testCreatePartnerLocation() {
try {
location = new MLocation(getCtx(), 0, getTrxName());
location.setC_Country_ID(getC_Country_ID("United States"));
location.setC_Region_ID(getC_Region_ID("CA"));
location.setCity("Windsor");
location.setAddress1("Happy Lane");
location.setAddress2("Happy Lane 2");
String zipcode = ("95492");
location.setPostal(zipcode);
location.setPostal_Add(zipcode);
location.setAD_Org_ID(0);
location.saveEx();
m_group = new MBPGroup(getCtx(), 0, getTrxName());
// N
m_group.setName("Test Group Name");
// N
m_group.setIsConfidentialInfo(false);
m_group.setIsDefault(false);
m_group.setPriorityBase(MBPGroup.PRIORITYBASE_Same);
m_group.saveEx();
m_partner = new MBPartner(getCtx(), 0, getTrxName());
m_partner.setValue("");
m_partner.setName("Test Business Partner Location");
m_partner.setName2(null);
m_partner.setDUNS("");
m_partner.setFirstSale(null);
//
m_partner.setSO_CreditLimit(Env.ZERO);
m_partner.setSO_CreditUsed(Env.ZERO);
m_partner.setTotalOpenBalance(Env.ZERO);
// s_m_partner.setRating(null);
//
m_partner.setActualLifeTimeValue(Env.ZERO);
m_partner.setPotentialLifeTimeValue(Env.ZERO);
m_partner.setAcqusitionCost(Env.ZERO);
m_partner.setShareOfCustomer(0);
m_partner.setSalesVolume(0);
m_partner.setBPGroup(m_group);
// Reset Created, Updated to current system time ( teo_sarca )
if (m_partner.save()) {
bpl = new MBPartnerLocation(getCtx(), 0, getTrxName());
bpl.setIsActive(true);
bpl.setName("Test Business Partner Location");
bpl.setC_BPartner_ID(m_partner.get_ID());
bpl.setC_Location_ID(location.get_ID());
bpl.saveEx();
}
commit();
} catch (Exception e) {
fail(e.getLocalizedMessage());
}
}
use of org.compiere.model.MBPartner in project adempiere by adempiere.
the class MakeToOrderStandardBOMandWF method test01.
public void test01() throws Exception {
Qty = new BigDecimal(10);
//Define Product
product = MProduct.get(getCtx(), M_Product_ID);
//Define Business Partner
BPartner = new MBPartner(getCtx(), C_BPartner_ID, trxName);
//Setting the BOM
int PP_Product_BOM_ID = MPPProductBOM.getBOMSearchKey(product);
if (PP_Product_BOM_ID > 0)
bom = new MPPProductBOM(getCtx(), PP_Product_BOM_ID, trxName);
else
throw new AdempiereException("@NotFound@ @PP_ProductBOM_ID@");
if (bom != null) {
bom.setValue(product.getValue());
bom.setBOMType(MPPProductBOM.BOMTYPE_Make_To_Order);
bom.setBOMUse(MPPProductBOM.BOMUSE_Manufacturing);
bom.saveEx();
}
//force Workflow as standard
workflow = new MWorkflow(getCtx(), AD_Workflow_ID, trxName);
workflow.setValue(product.getValue());
workflow.saveEx();
if (AD_Workflow_ID > 0)
workflow = MWorkflow.get(getCtx(), AD_Workflow_ID);
else
throw new AdempiereException("@NotFound@ @AD_Workflow_ID@");
/* Validate Exception if a Planning data is no defined
MPPProductPlanning pp = MPPProductPlanning.find(getCtx(), AD_Org_ID, M_Warehouse_ID , S_Resource_ID , M_Product_ID, trxName);
pp.setS_Resource_ID(50000);
pp.saveEx();*/
createOrder();
MPPOrder expected = createPPOrder();
I_PP_Order actual = MPPOrder.forC_OrderLine_ID(getCtx(), oline.get_ID(), oline.getM_Product_ID(), trxName);
if (actual == null) {
throw new AdempiereException("@NotFound@ @PP_Order_ID@ not was generate");
}
assertEquals("Confirming Manufacturing Order", expected, actual);
}
Aggregations