@SuppressWarnings("unchecked")
  @Override
  public ActionForward addItem(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    PurchasingFormBase purchasingForm = (PurchasingFormBase) form;
    PurApItem item = purchasingForm.getNewPurchasingItemLine();
    RequisitionItem requisitionItem = (RequisitionItem) item;
    PurchasingDocument purDocument = (PurchasingDocument) purchasingForm.getDocument();

    if (StringUtils.isBlank(requisitionItem.getPurchasingCommodityCode())) {
      boolean commCodeParam =
          SpringContext.getBean(ParameterService.class)
              .getParameterValueAsBoolean(
                  CuRequisitionDocument.class,
                  PurapParameterConstants.ENABLE_DEFAULT_VENDOR_COMMODITY_CODE_IND);

      if (commCodeParam) {
        if (purchasingForm instanceof RequisitionForm) {
          CuRequisitionDocument reqs = (CuRequisitionDocument) purchasingForm.getDocument();
          VendorDetail dtl = reqs.getVendorDetail();
          if (ObjectUtils.isNotNull(dtl)) {
            List<VendorCommodityCode> vcc = dtl.getVendorCommodities();
            String defaultCommodityCode = "";
            Iterator<VendorCommodityCode> it = vcc.iterator();
            while (it.hasNext()) {
              VendorCommodityCode commodity = it.next();
              if (commodity.isCommodityDefaultIndicator()) {
                defaultCommodityCode = commodity.getPurchasingCommodityCode();
                requisitionItem.setPurchasingCommodityCode(defaultCommodityCode);
              }
            }
          }
        }
      }
    }

    boolean rulePassed =
        SpringContext.getBean(KualiRuleService.class)
            .applyRules(new AttributedAddPurchasingAccountsPayableItemEvent("", purDocument, item));

    if (rulePassed) {
      item = purchasingForm.getAndResetNewPurchasingItemLine();
      purDocument.addItem(item);
      // KFSPTS-985
      if (((PurchasingDocumentBase) (purDocument)).isIntegratedWithFavoriteAccount()) {
        populatePrimaryFavoriteAccount(
            item.getSourceAccountingLines(),
            getAccountClassFromNewPurApAccountingLine(purchasingForm));
      }
    }

    return mapping.findForward(KFSConstants.MAPPING_BASIC);
  }
Пример #2
0
 @ConfigureContext(session = parke)
 public void testUpdateItemAccountAmounts_ThreeAccounts() {
   PurapAccountingServiceFixture fixture = PurapAccountingServiceFixture.REQ_PRORATION_THIRDS;
   RequisitionDocument req = fixture.generateRequisitionDocument_OneItem();
   RequisitionItem item = (RequisitionItem) req.getItems().get(0);
   KualiDecimal total = item.getTotalAmount();
   purapAccountingService.updateItemAccountAmounts(item);
   PurApAccountingLine line1 = item.getSourceAccountingLines().get(0);
   assertTrue(line1.getAmount().compareTo(total.divide(new KualiDecimal(3))) == 0);
 }