Skip to content

fix(observation): stale Sales Invoice Status on Observation records#1066

Open
md-umair-21 wants to merge 1 commit into
earthians:developfrom
md-umair-21:observation
Open

fix(observation): stale Sales Invoice Status on Observation records#1066
md-umair-21 wants to merge 1 commit into
earthians:developfrom
md-umair-21:observation

Conversation

@md-umair-21

Copy link
Copy Markdown
Contributor

Issue description:
When an Observation is linked to a Sales Invoice, the Sales Invoice Status field can incorrectly remain Unpaid even after the invoice has been paid.
This happens because the field was defined with:
fetch_from: "sales_invoice.status"

Due to this, the invoice status was stored on the Observation record. If the Sales Invoice status changed later through payment processing, the Observation field did not refresh automatically.

Before fix:

image

Fix:
The fix changes Observation.sales_invoice_status to a virtual live field(is_virtual).

  • Removed fetch_from from the Observation DocType JSON.
  • Added sales_invoice_status as a property in the Observation Python class.
  • The field now reads the current status directly from the linked Sales Invoice.
  • This keeps the Observation aligned with the actual Sales Invoice payment state.

Test after fix:
Make sure Create Observation on Sales Invoice Submission is enabled in Healthcare Settings.
Test the following scenario:

  1. Create an Observation Template and link the billable Lab Service Item to it.
  2. Create a Sales Invoice for a patient.
  3. Add the Lab Service Item to the Sales Invoice.
  4. Submit the Sales Invoice.
  5. Check the created Observation.

Expected result:

  • If the Sales Invoice is only submitted and not paid, the Observation should show the Sales Invoice Status as Unpaid.
  • After creating the Payment Entry and paying the Sales Invoice, the Observation should show the Sales Invoice Status as Paid.

This confirms that the Observation is now showing the live Sales Invoice payment status instead of a stale stored value.

image

Note:-
After pulling the changes , run bench --site sitename migrate to reflect the changes.

@coderabbitai

coderabbitai Bot commented Jun 27, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 2dc42020-8bf7-49a9-9245-9e65c2332da7

📥 Commits

Reviewing files that changed from the base of the PR and between 53f3931 and ae23f3c.

📒 Files selected for processing (2)
  • healthcare/healthcare/doctype/observation/observation.json
  • healthcare/healthcare/doctype/observation/observation.py

Walkthrough

sales_invoice_status on Observation is now configured as a virtual field in the DocType JSON, with fetch_from removed. The Observation class adds a sales_invoice_status property that reads the linked Sales Invoice’s status from the database when sales_invoice is set.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main fix: preventing stale Sales Invoice status on Observation records.
Description check ✅ Passed The description matches the code changes and explains the stale status bug, fix, and verification steps.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant