Skip to content

fix: prevent duplicate customer addresses when selling appliances#1370

Open
Zhey-on wants to merge 1 commit intoEnAccess:mainfrom
Zhey-on:fix/1367-no-duplicate-address-on-appliance-sale
Open

fix: prevent duplicate customer addresses when selling appliances#1370
Zhey-on wants to merge 1 commit intoEnAccess:mainfrom
Zhey-on:fix/1367-no-duplicate-address-on-appliance-sale

Conversation

@Zhey-on
Copy link
Copy Markdown

@Zhey-on Zhey-on commented Mar 12, 2026

Summary

This PR fixes issue #1367 where selling an appliance to an existing customer via UI could create an additional non-primary customer address.

Closes #1367.

Root Cause

During appliance sale flows, backend logic was creating and assigning a new record to the customer when a device serial was provided. The sale operation should only bind the sold device and update device geolocation, not mutate customer address records.

The same pattern existed in both:

  • web appliance sale flow ()
  • agent appliance sale flow ()

What Was Changed

1.

  • Removed customer-address creation/assignment from the sale path.
  • Replaced address-geo association with device-geo association.
  • Added safe handling for missing selected device (explicit exception).
  • Updated geolocation update logic to:
    • update existing device geo when present
    • create and attach geo to device when missing
  • Kept down payment sender fallback safe via null-coalescing.

2.

  • Removed address creation/assignment from agent sale processing.
  • Stopped deriving new address payload during sale.
  • Reused customer primary address geo only as a fallback source for points.
  • Applied the same device-geo update/create logic as web flow.
  • Added explicit guard for missing selected device.

Expected Behavior After Fix

Selling an appliance to an existing customer no longer inserts extra customer address rows. Customer address data remains unchanged; only device ownership and device geolocation are updated by sale operations.

Validation

Performed local syntax/error checks on modified backend files:

  • No syntax errors detected in src/backend/app/Http/Controllers/AppliancePersonController.php
  • No syntax errors detected in src/backend/app/Services/AgentSoldApplianceService.php
  • editor diagnostics: no errors in modified backend files.

Notes

This PR is intentionally scoped to the backend sale logic required for #1367 and does not include unrelated local workspace changes.

@beesaferoot
Copy link
Copy Markdown
Contributor

Hi @Zhey-on, thanks for the contribution! I'd like to review your PR, but a few updates are needed in the description first:

  • Please follow the provided PR template.
  • Keep the description concise. We encourage contributors to describe the changes in their own words to demonstrate understanding of the codebase, rather than relying heavily on code-generation tools.

Once these updates are made, I'll proceed with the review. Thanks!

@Zhey-on
Copy link
Copy Markdown
Author

Zhey-on commented Mar 27, 2026

Hi @beesaferoot,

I don't see any clear reference to the aforementioned PR template in the contributing guide.

Schermata del 2026-03-27 12-01-31

@beesaferoot
Copy link
Copy Markdown
Contributor

Hi @beesaferoot,

I don't see any clear reference to the aforementioned PR template in the contributing guide.

Schermata del 2026-03-27 12-01-31

While some details such as issue structure or PR description are not specified in detail, we provide these templates as a guide in our repositories to improve the contribution process.

I encourage you to look at other PRs created on this repo.

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.

[Bug]: Selling an appliance to a customer via UI creates duplicated address records

2 participants