Access to add and change pages is restricted. See: https://cwiki.apache.org/confluence/display/OFBIZ/Wiki+access

1. Introduction

As part of our ongoing effort to explore AI-driven development for Apache OFBiz, this document illustrates a real-life example of solving a Jira ticket using OpenAI Codex Cloud. The goal is to demonstrate how Codex can assist developers in implementing features faster, while maintaining correctness and code quality.

2. Jira Ticket Overview

Ticket ID: OFBIZ-13269

Scenario:
When configuring a Cart Range Percent Discount for promotions, OFBiz did not provide an option to set a maximum discount cap. For example, if a business wanted to apply a 15% discount with a ceiling of $100, the system would instead apply 15% to the entire cart, regardless of the order total.

3. Prompt Given to Codex

The following task prompt was given to Codex:

Task is to give support for maximum discount cap in Promotions. Let me explain the business scenario:

While configuring a Cart Range Percent Discount for promotions, there doesn’t seem to be an out-of-the-box option to set a maximum discount cap. For instance, if the business wants to offer a 15% discount on the cart total, but with a maximum discount limit of $100 irrespective of the cart total value, the system currently applies the percentage across the total cart value without a ceiling.

The primary aim is not to enforce a minimum margin rule for the product price but to set a maximum discount limit regardless of the cart total particularly for the high valued cart totals.

To keep the requirements simple, let’s consider only one promotion is applied to the cart. No need to handle the case of multiple promotions.

Solution Proposal: Extend the ProductPromoAction entity with a maxDiscountAmount field and consider this configuration in the promotion engine to validate the max discount that can be provided to the customer.

Let me know if you have any questions before you start coding.

4. Codex Execution Flow

Once the task was assigned, Codex executed the following steps automatically:

  1. Initial build: It first built Apache OFBiz to ensure the current state of the repo was stable.
  2. Code navigation: Codex navigated the file structure, explaining in logs what it was doing at each step.



  3. Code changes:
    • Added a maxDiscountAmount field to ProductPromoAction in product-entitymodel.xml.
    • Updated productOrderPercent logic in ProductPromoActionServices.groovy to enforce the discount cap.
    • Extended promotion rule editor forms and labels to expose the new field in the UI.
    • Added a regression test in ProductPromoActionTests.groovy.
  4. Rebuild and validation: After making changes, Codex rebuilt Apache OFBiz again. If anything broke, it attempted fixes and rebuilt until the build was successful.
  5. Commit & branch creation: Codex created a new feature branch, committed changes locally, and pushed them to the newly created feature branch. Here is the link to the feature branch created by Codex where code is pushed.
    codex/add-maximum-discount-cap-for-promotions

Execution time: 4 minutes 30 seconds.

5. Pull Request Workflow

  • Once the feature branch was ready, Codex gave me the option to create a PR. There is a button called “Create PR” at the top right corner. Once PR is created, the button is changed to “View PR”.



  • I created a PR from the feature branch to my trunk:
    PR #1 in my fork (already merged)

Issue observed:

During the PR creation, I noticed that all other UI labels in file ProductUiLabels.xml were deleted, which was not part of the intended changes.

Codex code review safeguard:

6. Final Merge

  • Once the fixes were applied and the PR looked correct, I merged the feature branch into my fork’s trunk.
  • After merging, the feature branch was deleted.
  • Finally, I created a PR from my fork’s trunk → Apache OFBiz trunk:
    Apache OFBiz PR #910

7. Testing

The changes were tested by Ankit Joshi, who originally raised the Jira ticket.

Steps:

  • Switched local trunk repo to the PR branch:
    git fetch origin pull/910/head:pr-910

  • Tested Max Discount Amount scenarios:
    • Case 1: 10% discount applied when cart total discount < $30 (max cap = $30).
    • Case 2: 10% discount applied but capped at $30 when cart discount > $30.

Result: The feature worked successfully, both in UI (Add/Edit UX) and in promotion calculation logic.

8. My Review & Observations

  • Codex identified the correct files and implemented changes exactly where a human developer would have.
  • The logic was correct, and the code was production-ready with only minor manual fixes.
  • Productivity impact:
    • Senior developer effort reduced from ~1 hour → 5 minutes.
    • Junior developer effort reduced from ~2–3 hours → 5 minutes.
  • The Codex code review feature was invaluable in catching unintended changes.
  • While Codex struggled to undo the unwanted deletions, manual intervention was straightforward.

9. Conclusion

This case study demonstrates that Codex can handle easy to medium level Apache OFBiz feature work end-to-end:

  • From building the repo, to applying changes, to committing and creating PRs.
  • With safeguards (manual review + Codex code review), the workflow is reliable.
  • Codex acts like a fast, junior developer, but always requires a senior developer to review and finalize changes.

The final code is now available in Apache OFBiz PR #910, awaiting community review.

  • No labels