Skip to content

Add completed_qty to test fixtures #280

Merged
agritheory merged 4 commits intomobile_v15from
fix-demo_data_job_cards
Aug 11, 2025
Merged

Add completed_qty to test fixtures #280
agritheory merged 4 commits intomobile_v15from
fix-demo_data_job_cards

Conversation

@lauty95
Copy link
Copy Markdown
Collaborator

@lauty95 lauty95 commented Jul 24, 2025

ERPNext has updated recently: frappe/erpnext#48745

If you try to execute bench execute 'beam.tests.setup.before_test' with ERPNext updated to v15.71.1, it will throw an error:

Screenshot 2025-07-24 at 1 40 00 PM

erpnext.manufacturing.doctype.job_card.job_card.OperationSequenceError: Job Card PO-JOB00002: As per the sequence of the operations in the work order MFG-WO-2025-00001, complete the operation Gather Pie Filling Ingredients before the operation Cook Pie Filling Operation.

This error occurs because Work Order has a new function,validate_operations_sequence:

https://github.com/frappe/erpnext/blob/3825490f0dbbd5530b739e928d012f639b6efafe/erpnext/manufacturing/doctype/work_order/work_order.py#L173

This function assignssequence_id to all operations that don't have one assigned, and then we have this function:

https://github.com/frappe/erpnext/blob/ad45063c76880a443c772a0ea3aa7ab6ca33da3c/erpnext/manufacturing/doctype/job_card/job_card.py#L1032

That function was created one year ago, but it wasn't a problem because it has this condition:

    if not (self.work_order and self.sequence_id):
        return

Since we didn't assignsequence_id to our operations, this validation wasn't a problem.

But this function has a condition before:

	def validate_sequence_id(self):
		if self.is_corrective_job_card:
			return

That is the reason for my change.

@lauty95 lauty95 self-assigned this Jul 24, 2025
@lauty95 lauty95 requested a review from agritheory July 24, 2025 17:00
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jul 24, 2025

Coverage

Coverage Report
FileStmtsMissCoverMissing
__init__.py10100% 
beam
   barcodes.py793456%20, 22, 24, 27, 38–39, 41–42, 47–48, 50–51, 53–55, 61, 71, 79, 86, 89–90, 96–97, 103, 109, 115, 121, 128, 131–134, 136–137
   handling_unit.py814346%26, 32, 64–66, 69, 72–76, 84, 95–96, 102–103, 105–106, 108–109, 111–112, 114, 116–119, 121–123, 125, 127, 129–130, 135, 137, 141, 143–144, 147, 149–150, 158
   printing.py826421%18–19, 32–43, 45–48, 57–61, 65–66, 68–69, 78–82, 85–86, 92–94, 101–102, 104–106, 108–109, 111, 116, 118–119, 134–139, 141–150
beam/demand
   demand.py3389472%51, 66, 123, 209, 243, 290, 293, 425–426, 428–429, 432–433, 435, 439–444, 446, 448–449, 452, 457, 459–464, 466, 468, 471, 474, 479, 483–485, 490–491, 493, 495–497, 499, 505, 507–510, 512–515, 517, 519, 522–523, 525–526, 529, 543, 560–561, 563–565, 621, 625, 662, 667, 674, 695–696, 707, 713–729, 853
   receiving.py1251786%79, 131, 173, 214, 244, 249–260
   sqlite.py59198%40
   utils.py59788%56, 67, 72–75, 83
beam/doctype/beam_mobile_route
   beam_mobile_route.py30100% 
beam/doctype/beam_settings
   beam_settings.py281739%35–37, 40–41, 43, 50, 55–58, 66–68, 72–74
beam/doctype/handling_unit
   __init__.py9366%12–14
   handling_unit.py150100% 
beam/doctype/warehouse_types
   warehouse_types.py30100% 
beam/overrides
   sales_order.py10640%11–16
   stock_entry.py671873%61–62, 67–74, 80–81, 97, 112, 123, 129, 132–133
   work_order.py10280%14, 16
beam/report/demand_map
   demand_map.py35350%4–5, 7–8, 11–12, 15–16, 103–111, 127, 129–143, 146–147
beam/report/handling_unit_traceability
   handling_unit_traceability.py44440%4–6, 9–11, 30–32, 34–35, 37–38, 41–42, 45–46, 48–49, 51–52, 54–55, 57, 63–65, 67–69, 71, 74–77, 79–81, 83–86, 89–90
beam/scan
   __init__.py1432880%21, 25, 31, 39, 90, 93–94, 118–119, 129, 131–132, 136, 140–141, 144, 155–156, 160, 181, 185, 214, 216, 235–236, 242, 245, 248
   config.py28280%4, 6, 9–17, 19–21, 23–26, 28–30, 32–35, 38–39, 41
   user_login.py31310%4–6, 8, 11–13, 17–19, 21–22, 24–25, 27–29, 31–33, 35–38, 40–45, 47
www/beam
   __init__.py14140%4–7, 10–19
   index.py770%4, 6, 9–13
TOTAL127149361% 

@lauty95 lauty95 mentioned this pull request Jul 28, 2025
@agritheory
Copy link
Copy Markdown
Owner

An alternative is to add sequence id in the fixturing: https://github.com/agritheory/beam/blob/version-14/beam/tests/setup.py#L343

@lauty95
Copy link
Copy Markdown
Collaborator Author

lauty95 commented Aug 11, 2025

@agritheory I tested the sorting with order_by:

job_cards = frappe.get_all("Job Card", {"work_order": wo.name}, order_by="sequence_id ASC, creation ASC")

It didn’t solve the issue, so I kept debugging.

The problem comes from validate_sequence_id in job_card.py:L1058:

row.status != "Completed"  # This condition is true, it is not completed yet
row.completed_qty < current_operation_qty  # This is also true, and I believe this is what should be avoided

Case where it fails:

  • row.completed_qty = 0
  • current_operation_qty = 160.0
  • Happens on Job Card PO-JOB00002 from Work Order MFG-WO-2025-00001.

current_operation_qty comes from self.total_completed_qty, which is set in validate_time_logs (L232):

if d.completed_qty and not self.sub_operations:
	self.total_completed_qty += d.completed_qty

This causes the validation to fail.

Fix applied: when adding time_logs to the job card, do not set "completed_qty":

job_card.append(
"time_logs",
{
	#"completed_qty": wo.qty,
	"from_time": start_time,
	"to_time": start_time + datetime.timedelta(minutes=time_in_mins),
	"time_in_mins": time_in_mins,
	"remaining_time_in_mins": time_in_mins,
},
)

Tests still pass, and Playwright tests run without issues.

Not entirely sure if setting "completed_qty" here is ever required.

Copy link
Copy Markdown
Owner

@agritheory agritheory left a comment

Choose a reason for hiding this comment

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

I think the completed_qty fix is the correct approach

@agritheory agritheory changed the title fix: is_corrective_job_card Add completed_qty to test fixtures Aug 11, 2025
@agritheory
Copy link
Copy Markdown
Owner

@lauty95 Please also cherry pick this for a PR against the version-15 branch

@agritheory agritheory merged commit f575ff4 into mobile_v15 Aug 11, 2025
5 checks passed
@agritheory agritheory deleted the fix-demo_data_job_cards branch August 11, 2025 16:18
@agritheory agritheory restored the fix-demo_data_job_cards branch August 11, 2025 23:04
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.

2 participants