Skip to content

[MODINVOICE-647] Updated models + new migration#623

Merged
damien-git merged 2 commits into
masterfrom
MODINVOICE-647
May 15, 2026
Merged

[MODINVOICE-647] Updated models + new migration#623
damien-git merged 2 commits into
masterfrom
MODINVOICE-647

Conversation

@damien-git
Copy link
Copy Markdown
Contributor

@damien-git damien-git commented May 13, 2026

Purpose

MODINVOICE-647 - Invoice line number is reused after deletion

Approach

  • Updated model removing the readonly attribute for nextPolNumber
  • Added a migration to calculate missing next numbers from lines

Related PRs


Pre-Review Checklist

  • Self-reviewed Code — Reviewed code for issues, unnecessary parts, and overall quality.
  • Change Notes — NEWS.md updated with clear description and issue key.
  • Testing — Confirmed changes were tested locally or on dev environment.
  • Logging: Confirmed that logging is appropriately handled.
  • Breaking Changes — Handled all required actions if changes affect API, DB, or interface versions.
    • API/schema changes
    • Interface version updates
    • DB schema changes / migration scripts
  • New Properties / Environment Variables — Updated README.md if new configs were added.

@BKadirkhodjaev
Copy link
Copy Markdown
Contributor

Did you had the chance to test if with our CLI's upgrade module command?

@damien-git
Copy link
Copy Markdown
Contributor Author

Did you had the chance to test if with our CLI's upgrade module command?

Not yet, I will try.

SELECT po.id, COALESCE(MAX(REGEXP_REPLACE(pol.jsonb ->> 'poLineNumber', '^[^-]+-([^-])$', '\1')::int), 0) + 1 AS number
FROM ${myuniversity}_${mymodule}.purchase_order po
LEFT JOIN ${myuniversity}_${mymodule}.po_line pol ON pol.purchaseOrderId = po.id
WHERE po.jsonb -> 'nextPolNumber' IS NULL
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think po.jsonb ? 'nextPolNumber' would have any benefits?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we would have to use NOT; might as well use IS NULL, which I have tested successfully (I doubt it makes a difference in performance)

@@ -0,0 +1,14 @@
<#if mode.name() == "UPDATE">
WITH missing_next_numbers AS (
SELECT po.id, COALESCE(MAX(REGEXP_REPLACE(pol.jsonb ->> 'poLineNumber', '^[^-]+-([^-])$', '\1')::int), 0) + 1 AS number
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

([^-]) without + matches exactly 1 character. So migration can fail for po line numbers >=10

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, fixed

@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants