use of org.compiere.model.MPriceListVersion in project adempiere by adempiere.
the class InventoryUtil method getCreatePriceList.
public static MPriceList getCreatePriceList(String value, boolean IsSOPriceList) {
Properties ctx = Env.getCtx();
int C_Currency_ID = Env.getContextAsInt(ctx, "$C_Currency_ID");
String whereClause = MPriceList.COLUMNNAME_Name + "=?" + " AND " + MPriceList.COLUMNNAME_IsSOPriceList + "=?" + " AND " + MPriceList.COLUMNNAME_C_Currency_ID + "=?";
MPriceList pl = new Query(ctx, MPriceList.Table_Name, whereClause, null).setParameters(new Object[] { value, IsSOPriceList, C_Currency_ID }).setClient_ID().setOnlyActiveRecords(true).firstOnly();
if (pl == null) {
pl = new MPriceList(ctx, 0, null);
pl.setName(value);
pl.setIsSOPriceList(IsSOPriceList);
pl.setC_Currency_ID(C_Currency_ID);
}
setGeneratedTag(pl);
pl.setIsTaxIncluded(false);
pl.saveEx();
//
Timestamp ValidFrom = TimeUtil.getDay(1970, 1, 1);
MPriceListVersion plv = pl.getPriceListVersion(ValidFrom);
if (plv == null) {
plv = new MPriceListVersion(pl);
plv.setValidFrom(ValidFrom);
plv.setM_DiscountSchema_ID(getM_DiscountSchema_ID());
setGeneratedTag(plv);
plv.saveEx();
}
//
return pl;
}
use of org.compiere.model.MPriceListVersion in project adempiere by adempiere.
the class MPriceListVersionTest method testQuery.
public void testQuery() throws Exception {
MPriceListVersion plv = new MPriceListVersion(getCtx(), 101, getTrxName());
//red1 tested also with (true) and (false)
MProductPrice[] pp = plv.getProductPrice("AND isActive='Y'");
assertTrue("product must have prices", pp.length > 0);
}
use of org.compiere.model.MPriceListVersion in project adempiere by adempiere.
the class InventoryUtil method getCreatePriceList.
public static MPriceList getCreatePriceList(String value, boolean IsSOPriceList) {
Properties ctx = Env.getCtx();
int C_Currency_ID = Env.getContextAsInt(ctx, "$C_Currency_ID");
String whereClause = MPriceList.COLUMNNAME_Name + "=?" + " AND " + MPriceList.COLUMNNAME_IsSOPriceList + "=?" + " AND " + MPriceList.COLUMNNAME_C_Currency_ID + "=?";
MPriceList pl = new Query(ctx, MPriceList.Table_Name, whereClause, null).setParameters(new Object[] { value, IsSOPriceList, C_Currency_ID }).setClient_ID().setOnlyActiveRecords(true).firstOnly();
if (pl == null) {
pl = new MPriceList(ctx, 0, null);
pl.setName(value);
pl.setIsSOPriceList(IsSOPriceList);
pl.setC_Currency_ID(C_Currency_ID);
}
setGeneratedTag(pl);
pl.setIsTaxIncluded(false);
pl.saveEx();
//
Timestamp ValidFrom = TimeUtil.getDay(1970, 1, 1);
MPriceListVersion plv = pl.getPriceListVersion(ValidFrom);
if (plv == null) {
plv = new MPriceListVersion(pl);
plv.setValidFrom(ValidFrom);
plv.setM_DiscountSchema_ID(getM_DiscountSchema_ID());
setGeneratedTag(plv);
plv.saveEx();
}
//
return pl;
}
use of org.compiere.model.MPriceListVersion in project adempiere by adempiere.
the class CPOS method loadPriceListVersion.
// getM_PriceList_ID
/**
* Load Price List Version from Price List
* @param priceListId
* @return
* @return MPriceListVersion
*/
protected MPriceListVersion loadPriceListVersion(int priceListId) {
priceListVersionId = 0;
this.priceListId = priceListId;
MPriceList priceList = MPriceList.get(ctx, priceListId, null);
//
MPriceListVersion priceListVersion = priceList.getPriceListVersion(getToday());
if (priceListVersion != null && priceListVersion.getM_PriceList_Version_ID() != 0) {
priceListVersionId = priceListVersion.getM_PriceList_Version_ID();
}
// Default Return
return priceListVersion;
}
use of org.compiere.model.MPriceListVersion in project adempiere by adempiere.
the class CopyPriceToStandard method doIt.
protected String doIt() throws Exception {
MAcctSchema accountSchema = MAcctSchema.get(getCtx(), getAccountingSchemaId());
MCostElement costElement = MCostElement.get(getCtx(), getCostElementId());
if (!MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType()))
throw new AdempiereException("Only Material Cost Elements are allowed");
AtomicInteger countUpdated = new AtomicInteger(0);
MPriceListVersion priceListVersion = new MPriceListVersion(getCtx(), getPriceListVersionId(), get_TrxName());
Arrays.stream(priceListVersion.getProductPrice(" AND " + MProductPrice.COLUMNNAME_PriceStd + " <> 0")).forEach(productPrice -> {
final BigDecimal price;
int currencyId = priceListVersion.getPriceList().getC_Currency_ID();
if (currencyId != accountSchema.getC_Currency_ID()) {
price = MConversionRate.convert(getCtx(), productPrice.getPriceStd(), currencyId, accountSchema.getC_Currency_ID(), getAD_Client_ID(), getOrganizationId());
} else
price = productPrice.getPriceStd();
MProduct product = MProduct.get(getCtx(), productPrice.getM_Product_ID());
CostDimension costDimension = new CostDimension(product, accountSchema, getCostTypeId(), getOrganizationId(), 0, 0, getCostElementId());
List<MCost> costs = costDimension.toQuery(MCost.class, get_TrxName()).list();
costs.stream().filter(cost -> cost != null && cost.getM_CostElement_ID() == costElement.get_ID()).findFirst().ifPresent(cost -> {
cost.setFutureCostPrice(price);
cost.saveEx();
countUpdated.getAndUpdate(count -> count + 1);
});
});
return "@Updated@ # " + countUpdated;
}
Aggregations