From 0c745710ad0a7b89919565d73e2e22b70217d8ad Mon Sep 17 00:00:00 2001 From: Alessandro Domanico Date: Tue, 29 Oct 2024 17:24:42 +0100 Subject: [PATCH 1/2] workflow: get fork and branch upon pull_request and push events (#2076) * Try to get pull-requests branches from fork * Fix history commit depth * workflow: get fork and branch upon pull_request and push events --- .github/workflows/maven.yml | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index d71a136bd4..91e0b29c70 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -14,12 +14,41 @@ jobs: steps: - uses: actions/checkout@v4 + + - name: Debug GitHub variables + run: | + echo "GITHUB_EVENT_NAME: ${GITHUB_EVENT_NAME}" + echo "GITHUB_HEAD_REPOSITORY: ${GITHUB_HEAD_REPOSITORY}" + echo "GITHUB_HEAD_REF: ${GITHUB_HEAD_REF}" + echo "GITHUB_REPOSITORY: ${GITHUB_REPOSITORY}" + echo "GITHUB_REF: ${GITHUB_REF}" + echo "GITHUB_ACTOR: ${GITHUB_ACTOR}" - name: Determine PR source branch and fork repository id: vars run: | - echo "BRANCH_NAME=${GITHUB_HEAD_REF:-develop}" >> $GITHUB_ENV - echo "FORK_REPO=${GITHUB_HEAD_REPOSITORY:-informatici/openhospital-core}" >> $GITHUB_ENV + # Get branch name from either pull_request or push context + if [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then + # Get branch and fork repo for PR events + echo "BRANCH_NAME=${GITHUB_HEAD_REF}" >> $GITHUB_ENV + echo "FORK_REPO=${GITHUB_HEAD_REPOSITORY:-informatici/openhospital-core}" >> $GITHUB_ENV + elif [[ "${GITHUB_EVENT_NAME}" == "push" ]]; then + # Get branch name for push events + echo "BRANCH_NAME=${GITHUB_REF##*/}" >> $GITHUB_ENV + + # Default FORK_REPO to main repository, with option to fallback if the fork exists + OWNER=${GITHUB_ACTOR} + if curl -s -o /dev/null -w "%{http_code}" "https://api.github.com/repos/${OWNER}/openhospital-core/branches/${GITHUB_REF##*/}" | grep -q "200"; then + echo "FORK_REPO=${OWNER}/openhospital-core" >> $GITHUB_ENV + else + echo "FORK_REPO=informatici/openhospital-core" >> $GITHUB_ENV + fi + fi + + - name: Log variables + run: | + echo "FORK_REPO: ${{ env.FORK_REPO }}" + echo "BRANCH_NAME: ${{ env.BRANCH_NAME }}" - name: Set up JDK 17 uses: actions/setup-java@v4 From 7ce5c114ffb2792d0323c1f75e359d27a04731a7 Mon Sep 17 00:00:00 2001 From: Alessandro Domanico Date: Tue, 29 Oct 2024 21:07:26 +0100 Subject: [PATCH 2/2] OP-1340 Fix when medical has no previous lots (#2075) * Fix when medical has no previous lots * Improve * Fix when AUTOMATICLOT_IN=true * Simplify the logic * Remove comments * Update src/main/java/org/isf/medicalstock/gui/MovStockMultipleCharging.java * Update src/main/java/org/isf/medicalstock/gui/MovStockMultipleCharging.java --- .../gui/MovStockMultipleCharging.java | 61 ++++++++++++------- 1 file changed, 40 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/isf/medicalstock/gui/MovStockMultipleCharging.java b/src/main/java/org/isf/medicalstock/gui/MovStockMultipleCharging.java index a4d6c1750f..8e458a6c4e 100644 --- a/src/main/java/org/isf/medicalstock/gui/MovStockMultipleCharging.java +++ b/src/main/java/org/isf/medicalstock/gui/MovStockMultipleCharging.java @@ -410,43 +410,33 @@ private JTextField getJTextFieldSearch() { return; } - // Lot (PreparationDate && ExpiringDate) + // Lot Lot lot; boolean isNewLot = false; boolean updateLot = false; if (isAutomaticLotIn()) { - LocalDateTime preparationDate = TimeTools.getNow().truncatedTo(ChronoUnit.MINUTES); - LocalDateTime expiringDate = askExpiringDate(); - lot = new Lot("", preparationDate, expiringDate); //$NON-NLS-1$ - // Lot Cost - BigDecimal cost = new BigDecimal(0); - if (GeneralData.LOTWITHCOST) { - cost = askCost(qty); - if (cost.compareTo(new BigDecimal(0)) == 0) { - return; - } - } + lot = createNewLot(med, qty); isNewLot = true; - lot.setCost(cost); } else { do { lot = chooseLot(med); if (lot == null) { - lot = askLot(); + lot = askLot(med); if (lot == null) { return; } + if (!setOrValidateCost(lot, qty)) { + return; + } + isNewLot = true; } - // Lot Cost - BigDecimal cost = lot.getCost(); - if ((cost == null || cost.equals(new BigDecimal(0))) && GeneralData.LOTWITHCOST) { + // Lot without cost + if (needsCostUpdate(lot)) { MessageDialog.warning(null, "angal.medicalstock.multiplecharging.selectedlotwithoutcostpleasespecify", lot.getCode()); - cost = askCost(qty); - if (cost.compareTo(new BigDecimal(0)) == 0) { + if (!setOrValidateCost(lot, qty)) { return; } updateLot = true; - lot.setCost(cost); } } while (lot == null); } @@ -470,6 +460,34 @@ private JTextField getJTextFieldSearch() { return jTextFieldSearch; } + private Lot createNewLot(Medical med, int qty) { + LocalDateTime preparationDate = TimeTools.getNow().truncatedTo(ChronoUnit.MINUTES); + LocalDateTime expiringDate = askExpiringDate(); + Lot newLot = new Lot("", preparationDate, expiringDate); + newLot.setMedical(med); + + if (!setOrValidateCost(newLot, qty)) { + return null; + } + return newLot; + } + + private boolean setOrValidateCost(Lot lot, int qty) { + BigDecimal cost = lot.getCost() != null ? lot.getCost() : BigDecimal.ZERO; + if (GeneralData.LOTWITHCOST && (cost.equals(BigDecimal.ZERO) || lot.getCost() == null)) { + cost = askCost(qty); + if (cost.compareTo(BigDecimal.ZERO) == 0) { + return false; + } + lot.setCost(cost); + } + return true; + } + + private boolean needsCostUpdate(Lot lot) { + return (lot.getCost() == null || lot.getCost().equals(BigDecimal.ZERO)) && GeneralData.LOTWITHCOST; + } + private GoodDateTimeSpinnerChooser getJDateChooser() { if (jDateChooser == null) { jDateChooser = new GoodDateTimeSpinnerChooser(TimeTools.getNow()); @@ -542,7 +560,7 @@ protected double askTotalCost() { return total; } - protected Lot askLot() { + protected Lot askLot(Medical med) { LocalDateTime preparationDate; LocalDateTime expiringDate; Lot lot = null; @@ -585,6 +603,7 @@ protected Lot askLot() { expiringDate = expireDateChooser.getDateEndOfDay(); preparationDate = preparationDateChooser.getDateStartOfDay(); lot = new Lot(lotName, preparationDate, expiringDate); + lot.setMedical(med); } } else { return null;