use of org.kuali.kfs.module.purap.businessobject.RequisitionItem in project cu-kfs by CU-CommunityApps.
the class CuPurapAccountingServiceImplTest method testUpdateAccountAmounts_AccountingLinePercentChanged.
public void testUpdateAccountAmounts_AccountingLinePercentChanged() throws Exception {
changeCurrentUser(UserNameFixture.ccs1);
// Save the requisition with items, but without accounting lines and then add the accounting lines and save again
// This odd methodology is to workaround an NPE that occurs when access security is enabled and refreshNonUpdatableReferences
// is called on the account. For some reason the RequisitionItem cannot be found in ojb's cache and so when
// it is attempted to be instantiated and constructor methods called, an NPE is thrown. This little dance works around the exception.
// More analysis could probably be done to determine the root cause and address it, but for now this is good enough.
RequisitionDocument requisitionDocument = RequisitionFixture.REQ_NON_B2B_WITH_ITEMS.createRequisition(documentService);
requisitionDocument.getFinancialSystemDocumentHeader().setFinancialDocumentTotalAmount(new KualiDecimal(200));
RequisitionItem item = RequisitionItemFixture.REQ_ITEM3.createRequisitionItem(false);
requisitionDocument.addItem(item);
AccountingDocumentTestUtils.saveDocument(requisitionDocument, documentService);
requisitionDocument.refreshNonUpdateableReferences();
item.getSourceAccountingLines().add(PurapAccountingLineFixture.REQ_ITEM_ACCT_LINE3.createRequisitionAccount(item.getItemIdentifier()));
item.getSourceAccountingLines().add(PurapAccountingLineFixture.REQ_ITEM_ACCT_LINE3.createRequisitionAccount(item.getItemIdentifier()));
item.refreshNonUpdateableReferences();
AccountingDocumentTestUtils.saveDocument(requisitionDocument, documentService);
PurchaseOrderDocument purchaseOrderDocument = (PurchaseOrderDocument) documentService.getNewDocument(PurchaseOrderDocument.class);
purchaseOrderDocument.populatePurchaseOrderFromRequisition(requisitionDocument);
purchaseOrderDocument.setContractManagerCode(10);
purchaseOrderDocument.setPurchaseOrderCurrentIndicator(true);
purchaseOrderDocument.getDocumentHeader().setDocumentDescription("Description");
purchaseOrderDocument.setApplicationDocumentStatus(PurchaseOrderStatuses.APPDOC_OPEN);
purchaseOrderDocument.refreshNonUpdateableReferences();
purchaseOrderDocument.setVendorShippingPaymentTermsCode("AL");
purchaseOrderDocument.setVendorPaymentTermsCode("00N30");
purchaseOrderDocument.refreshNonUpdateableReferences();
AccountingDocumentTestUtils.saveDocument(purchaseOrderDocument, documentService);
changeCurrentUser(UserNameFixture.mo14);
PaymentRequestDocument paymentRequestDocument = PaymentRequestFixture.PAYMENT_REQ_DOC.createPaymentRequestDocument(purchaseOrderDocument.getPurapDocumentIdentifier());
paymentRequestDocument.initiateDocument();
paymentRequestDocument.populatePaymentRequestFromPurchaseOrder(purchaseOrderDocument);
paymentRequestDocument.setApplicationDocumentStatus(PurapConstants.PaymentRequestStatuses.APPDOC_AWAITING_FISCAL_REVIEW);
paymentRequestDocument.getItem(0).setExtendedPrice(new KualiDecimal(1));
paymentRequestDocument.getItem(1).setExtendedPrice(new KualiDecimal(4));
((PaymentRequestAccount) (((PaymentRequestItem) paymentRequestDocument.getItems().get(1)).getSourceAccountingLine(0))).setAmount(new KualiDecimal(3));
((PaymentRequestAccount) (((PaymentRequestItem) paymentRequestDocument.getItems().get(1)).getSourceAccountingLine(1))).setAmount(new KualiDecimal(1));
cuPurapAccountingServiceImpl.updateAccountAmounts(paymentRequestDocument);
assertEquals(new BigDecimal(75).setScale(2), ((PaymentRequestAccount) (((PaymentRequestItem) paymentRequestDocument.getItems().get(1)).getSourceAccountingLine(0))).getAccountLinePercent());
}
use of org.kuali.kfs.module.purap.businessobject.RequisitionItem in project cu-kfs by CU-CommunityApps.
the class CuPurapAccountingServiceImplTest method testUpdateAccountAmounts_AccountingLinePercentUnchanged.
public void testUpdateAccountAmounts_AccountingLinePercentUnchanged() throws Exception {
changeCurrentUser(UserNameFixture.ccs1);
// Save the requisition with items, but without accounting lines and then add the accounting lines and save again
// This odd methodology is to workaround an NPE that occurs when access security is enabled and refreshNonUpdatableReferences
// is called on the account. For some reason the RequisitionItem cannot be found in ojb's cache and so when
// it is attempted to be instantiated and constructor methods called, an NPE is thrown. This little dance works around the exception.
// More analysis could probably be done to determine the root cause and address it, but for now this is good enough.
RequisitionDocument requisitionDocument = RequisitionFixture.REQ_NON_B2B_WITH_ITEMS.createRequisition(documentService);
requisitionDocument.getFinancialSystemDocumentHeader().setFinancialDocumentTotalAmount(new KualiDecimal(200));
RequisitionItem item = RequisitionItemFixture.REQ_ITEM3.createRequisitionItem(false);
requisitionDocument.addItem(item);
AccountingDocumentTestUtils.saveDocument(requisitionDocument, documentService);
requisitionDocument.refreshNonUpdateableReferences();
item.getSourceAccountingLines().add(PurapAccountingLineFixture.REQ_ITEM_ACCT_LINE3.createRequisitionAccount(item.getItemIdentifier()));
item.getSourceAccountingLines().add(PurapAccountingLineFixture.REQ_ITEM_ACCT_LINE3.createRequisitionAccount(item.getItemIdentifier()));
item.refreshNonUpdateableReferences();
AccountingDocumentTestUtils.saveDocument(requisitionDocument, documentService);
PurchaseOrderDocument purchaseOrderDocument = (PurchaseOrderDocument) documentService.getNewDocument(PurchaseOrderDocument.class);
purchaseOrderDocument.populatePurchaseOrderFromRequisition(requisitionDocument);
purchaseOrderDocument.setContractManagerCode(10);
purchaseOrderDocument.setPurchaseOrderCurrentIndicator(true);
purchaseOrderDocument.getDocumentHeader().setDocumentDescription("Description");
purchaseOrderDocument.setApplicationDocumentStatus(PurchaseOrderStatuses.APPDOC_OPEN);
purchaseOrderDocument.refreshNonUpdateableReferences();
purchaseOrderDocument.setVendorShippingPaymentTermsCode("AL");
purchaseOrderDocument.setVendorPaymentTermsCode("00N30");
purchaseOrderDocument.refreshNonUpdateableReferences();
AccountingDocumentTestUtils.saveDocument(purchaseOrderDocument, documentService);
changeCurrentUser(UserNameFixture.mo14);
PaymentRequestDocument paymentRequestDocument = PaymentRequestFixture.PAYMENT_REQ_DOC.createPaymentRequestDocument(purchaseOrderDocument.getPurapDocumentIdentifier());
paymentRequestDocument.initiateDocument();
paymentRequestDocument.populatePaymentRequestFromPurchaseOrder(purchaseOrderDocument);
paymentRequestDocument.setApplicationDocumentStatus(PurapConstants.PaymentRequestStatuses.APPDOC_IN_PROCESS);
paymentRequestDocument.getItem(0).setExtendedPrice(new KualiDecimal(1));
paymentRequestDocument.getItem(1).setExtendedPrice(new KualiDecimal(4));
((PaymentRequestAccount) (((PaymentRequestItem) paymentRequestDocument.getItems().get(1)).getSourceAccountingLine(0))).setAmount(new KualiDecimal(3));
((PaymentRequestAccount) (((PaymentRequestItem) paymentRequestDocument.getItems().get(1)).getSourceAccountingLine(1))).setAmount(new KualiDecimal(1));
cuPurapAccountingServiceImpl.updateAccountAmounts(paymentRequestDocument);
assertEquals(new BigDecimal(50).setScale(2), ((PaymentRequestAccount) (((PaymentRequestItem) paymentRequestDocument.getItems().get(1)).getSourceAccountingLine(0))).getAccountLinePercent());
}
use of org.kuali.kfs.module.purap.businessobject.RequisitionItem in project cu-kfs by CU-CommunityApps.
the class FavoriteAccountLineBuilderTest method setUp.
@BeforeClass
public static void setUp() throws Exception {
userProcurementProfileValidationService = new UserProcurementProfileValidationServiceImpl();
userFavoriteAccountService = new ExtendedTestUserFavoriteAccountService();
reqsAccounts = new ArrayList<PurApAccountingLine>();
poAccounts = new ArrayList<PurApAccountingLine>();
reqsItem = new RequisitionItem();
poItem = new PurchaseOrderItem();
reqsDoc = getMockedDocument(CuRequisitionDocument.class);
poDoc = getMockedDocument(PurchaseOrderDocument.class);
iwntDoc = getMockedDocument(IWantDocument.class);
iwntDoc.setAccounts(new ArrayList<IWantAccount>());
// Favorite Account with only some fields populated.
testFavoriteAccount = new FavoriteAccount();
testFavoriteAccount.setAccountLineIdentifier(TEST_FAVORITE_ACCOUNT_LINE_ID);
testFavoriteAccount.setUserProfileId(TEST_USER_PROFILE_ID);
testFavoriteAccount.setChartOfAccountsCode(TEST_CHART_CODE);
testFavoriteAccount.setAccountNumber(TEST_ACCOUNT_NUMBER);
testFavoriteAccount.setFinancialObjectCode(TEST_OBJECT_CODE);
// Favorite Account with all fields populated (except reference objects or object ID or version number).
testAltFavoriteAccount = new FavoriteAccount();
testAltFavoriteAccount.setAccountLineIdentifier(TEST_ALT_FAVORITE_ACCOUNT_LINE_ID);
testAltFavoriteAccount.setUserProfileId(TEST_ALT_USER_PROFILE_ID);
testAltFavoriteAccount.setChartOfAccountsCode(TEST_ALT_CHART_CODE);
testAltFavoriteAccount.setAccountNumber(TEST_ALT_ACCOUNT_NUMBER);
testAltFavoriteAccount.setSubAccountNumber(TEST_ALT_SUB_ACCOUNT_NUMBER);
testAltFavoriteAccount.setFinancialObjectCode(TEST_ALT_OBJECT_CODE);
testAltFavoriteAccount.setFinancialSubObjectCode(TEST_ALT_SUB_OBJECT_CODE);
testAltFavoriteAccount.setProjectCode(TEST_ALT_PROJECT_CODE);
testAltFavoriteAccount.setOrganizationReferenceId(TEST_ALT_ORG_REF_ID);
GlobalVariables.setMessageMap(new MessageMap());
}
use of org.kuali.kfs.module.purap.businessobject.RequisitionItem in project cu-kfs by CU-CommunityApps.
the class CuB2BShoppingServiceImplTest method testCreateRequisitionItem.
public void testCreateRequisitionItem() {
RequisitionItem requisitionItem = b2bShoppingService.createRequisitionItem(B2BShoppingCartItemFixture.B2B_ITEM_USING_VENDOR_ID.createB2BShoppingCartItem(), 0, "80141605");
assertNotNull(requisitionItem);
assertTrue(requisitionItem.isControlled());
assertTrue(requisitionItem.isRadioactiveMinor());
assertTrue(requisitionItem.isGreen());
assertTrue(requisitionItem.isHazardous());
assertTrue(requisitionItem.isSelectAgent());
assertTrue(requisitionItem.isRadioactive());
assertTrue(requisitionItem.isToxin());
assertTrue(requisitionItem.isRecycled());
assertTrue(requisitionItem.isEnergyStar());
}
use of org.kuali.kfs.module.purap.businessobject.RequisitionItem in project cu-kfs by CU-CommunityApps.
the class CuRequisitionDocument method toCopyFromGateway.
/**
* toCopyFromGateway
*/
public void toCopyFromGateway() throws WorkflowException, ValidationException {
// no validation for the KFS copy requisition rules:
String sourceDocumentHeaderId = getDocumentNumber();
setNewDocumentHeader();
getDocumentHeader().setDocumentTemplateNumber(sourceDocumentHeaderId);
// Clear out existing notes.
if (getNotes() != null) {
getNotes().clear();
}
addCopyErrorDocumentNote("copied from document " + sourceDocumentHeaderId);
// --- LedgerPostingDocumentBase:
setAccountingPeriod(retrieveCurrentAccountingPeriod());
// --GeneralLedgerPostingDocumentBase:
getGeneralLedgerPendingEntries().clear();
// --AccountingDocumentBase:
copyAccountingLines(false);
updatePostingYearForAccountingLines(getSourceAccountingLines());
updatePostingYearForAccountingLines(getTargetAccountingLines());
// --RequisitionDocument:
// Clear related views
this.setAccountsPayablePurchasingDocumentLinkIdentifier(null);
this.setRelatedViews(null);
Person currentUser = GlobalVariables.getUserSession().getPerson();
ChartOrgHolder purapChartOrg = SpringContext.getBean(FinancialSystemUserService.class).getPrimaryOrganization(currentUser, PurapConstants.PURAP_NAMESPACE);
this.setPurapDocumentIdentifier(null);
// Set req status to INPR.
// for app doc status
updateAndSaveAppDocStatus(PurapConstants.RequisitionStatuses.APPDOC_IN_PROCESS);
// Set fields from the user.
if (ObjectUtils.isNotNull(purapChartOrg)) {
this.setChartOfAccountsCode(purapChartOrg.getChartOfAccountsCode());
this.setOrganizationCode(purapChartOrg.getOrganizationCode());
}
this.setPostingYear(SpringContext.getBean(UniversityDateService.class).getCurrentFiscalYear());
boolean activeVendor = true;
boolean activeContract = true;
Date today = SpringContext.getBean(DateTimeService.class).getCurrentDate();
VendorContract vendorContract = new VendorContract();
vendorContract.setVendorContractGeneratedIdentifier(this.getVendorContractGeneratedIdentifier());
Map keys = SpringContext.getBean(PersistenceService.class).getPrimaryKeyFieldValues(vendorContract);
vendorContract = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(VendorContract.class, keys);
if (!(vendorContract != null && today.after(vendorContract.getVendorContractBeginningDate()) && today.before(vendorContract.getVendorContractEndDate()))) {
activeContract = false;
}
VendorDetail vendorDetail = SpringContext.getBean(VendorService.class).getVendorDetail(this.getVendorHeaderGeneratedIdentifier(), this.getVendorDetailAssignedIdentifier());
if (!(vendorDetail != null && vendorDetail.isActiveIndicator())) {
activeVendor = false;
}
// KFSPTS-916 : need vendor address key for business rules and only way to get it is to retrieve the default PO address for the vendor.
if (vendorDetail != null) {
VendorAddress vendorAddress = SpringContext.getBean(VendorService.class).getVendorDefaultAddress(this.getVendorHeaderGeneratedIdentifier(), this.getVendorDetailAssignedIdentifier(), VendorConstants.AddressTypes.PURCHASE_ORDER, "");
if (vendorAddress != null) {
super.templateVendorAddress(vendorAddress);
}
}
// B2B - only copy if contract and vendor are both active (throw separate errors to print to screen)
if (this.getRequisitionSourceCode().equals(PurapConstants.RequisitionSources.B2B)) {
if (!activeContract) {
// -- throw new ValidationException(PurapKeyConstants.ERROR_REQ_COPY_EXPIRED_CONTRACT);
}
if (!activeVendor) {
// -- throw new ValidationException(PurapKeyConstants.ERROR_REQ_COPY_INACTIVE_VENDOR);
}
}
if (!activeVendor) {
this.setVendorContractGeneratedIdentifier(null);
}
if (!activeContract) {
this.setVendorContractGeneratedIdentifier(null);
}
// These fields should not be set in this method; force to be null
this.setOrganizationAutomaticPurchaseOrderLimit(null);
this.setPurchaseOrderAutomaticIndicator(false);
for (Iterator iter = this.getItems().iterator(); iter.hasNext(); ) {
RequisitionItem item = (RequisitionItem) iter.next();
item.setPurapDocumentIdentifier(null);
item.setItemIdentifier(null);
for (Iterator acctIter = item.getSourceAccountingLines().iterator(); acctIter.hasNext(); ) {
RequisitionAccount account = (RequisitionAccount) acctIter.next();
account.setAccountIdentifier(null);
account.setItemIdentifier(null);
}
}
if (!PurapConstants.RequisitionSources.B2B.equals(this.getRequisitionSourceCode())) {
SpringContext.getBean(PurapService.class).addBelowLineItems(this);
}
this.setOrganizationAutomaticPurchaseOrderLimit(SpringContext.getBean(PurapService.class).getApoLimit(this.getVendorContractGeneratedIdentifier(), this.getChartOfAccountsCode(), this.getOrganizationCode()));
clearCapitalAssetFields();
SpringContext.getBean(PurapService.class).clearTax(this, this.isUseTaxIndicator());
this.refreshNonUpdateableReferences();
}
Aggregations