Commit 8378292
authored
fix: reset TempOrderLine between iterations in SetAndInsertOrderLines to prevent Tip flag from persisting across order lines (#7787)
Fixes #6811
## Problem
In codeunit 30161 Shpfy Import Order, the procedure
SetAndInsertOrderLines iterates over a JsonArray of order lines and
passes TempOrderLine by reference to SetOrderLineValuesFromJson. When a
line named Tip with a null product is encountered, the Tip field is set
to true on the record. Because TempOrderLine is never re-initialized
between iterations, the next line in the loop inherits all field values
including Tip = true from the previous iteration. This causes every
order line that follows a Tip line to be incorrectly classified as a
Tip, even standard item lines.
The stale-value problem only manifests for new lines. When
LocalOrderLine.Get succeeds (the line already exists in the database),
OrderLine.Copy(LocalOrderLine) overwrites all fields. For brand-new
lines, no such reset occurs, so the previous iteration's values persist.
## Solution
Add TempOrderLine.Init() at the start of the foreach loop body in
SetAndInsertOrderLines. This resets all fields to their default values
before SetOrderLineValuesFromJson populates them from the JSON token,
ensuring each iteration starts from a clean state.
## Changes
- ShpfyImportOrder.Codeunit.al: Wrapped the foreach body in a
begin...end block and added TempOrderLine.Init() before calling
SetOrderLineValuesFromJson.
- ShpfyOrdersAPITest.Codeunit.al: Added
UnitTestTipFlagNotPropagatedToSubsequentOrderLines, which imports a Tip
line followed by a regular line using
ImportCreateAndUpdateOrderLinesFromMock and asserts that only the Tip
line has Tip = true.
## How to Test
1. In a Business Central environment with the Shopify connector, create
a Shopify order containing a Tip item followed by one or more regular
items.
2. Sync the order to Business Central.
3. Open the imported Shopify Order and inspect the order lines.
4. Expected: only the Tip line has the Tip indicator set. Subsequent
lines do not inherit the Tip flag.
Alternatively, run the automated test
UnitTestTipFlagNotPropagatedToSubsequentOrderLines in codeunit 139608
Shpfy Orders API Test. The test fails without the fix and passes with
it.1 parent 142447a commit 8378292
2 files changed
Lines changed: 53 additions & 1 deletion
File tree
- src/Apps/W1/Shopify
- App/src/Order handling/Codeunits
- Test/Order Handling
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
636 | 636 | | |
637 | 637 | | |
638 | 638 | | |
639 | | - | |
| 639 | + | |
| 640 | + | |
640 | 641 | | |
641 | 642 | | |
642 | 643 | | |
643 | 644 | | |
| 645 | + | |
644 | 646 | | |
645 | 647 | | |
646 | 648 | | |
| |||
Lines changed: 50 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1486 | 1486 | | |
1487 | 1487 | | |
1488 | 1488 | | |
| 1489 | + | |
| 1490 | + | |
| 1491 | + | |
| 1492 | + | |
| 1493 | + | |
| 1494 | + | |
| 1495 | + | |
| 1496 | + | |
| 1497 | + | |
| 1498 | + | |
| 1499 | + | |
| 1500 | + | |
| 1501 | + | |
| 1502 | + | |
| 1503 | + | |
| 1504 | + | |
| 1505 | + | |
| 1506 | + | |
| 1507 | + | |
| 1508 | + | |
| 1509 | + | |
| 1510 | + | |
| 1511 | + | |
| 1512 | + | |
| 1513 | + | |
| 1514 | + | |
| 1515 | + | |
| 1516 | + | |
| 1517 | + | |
| 1518 | + | |
| 1519 | + | |
| 1520 | + | |
| 1521 | + | |
| 1522 | + | |
| 1523 | + | |
| 1524 | + | |
| 1525 | + | |
| 1526 | + | |
| 1527 | + | |
| 1528 | + | |
| 1529 | + | |
| 1530 | + | |
| 1531 | + | |
| 1532 | + | |
| 1533 | + | |
| 1534 | + | |
| 1535 | + | |
| 1536 | + | |
| 1537 | + | |
| 1538 | + | |
1489 | 1539 | | |
1490 | 1540 | | |
1491 | 1541 | | |
| |||
0 commit comments