transfer into an existing resource hands the source resource's rights and custody to the receiver

Open Beginner friendly
#87 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
elixir
Domain
backend, databases

Research direction

Read the to_resource_inventoried_as_id branch in src/zenflows/vf/economic_event/domain.ex around lines 980–990 and compare it with the branch around lines 1023–1029. Add a partial transfer test in test/vf/economic_event/domain.test.exs, based on the existing :to_resource_inventoried_as test, and check the source resource's accountable and custodian. Done when the source retains both after a partial transfer into an existing resource.

Written by the indexing model from the issue text.

Description

Problem

When a transfer names an existing destination (toResourceInventoriedAs), the update of the source resource also sets its primaryAccountable and custodian to the receiver:

domain.ex L980-L990

|> Multi.update_all("#{key}.set_and_dec",
	where(EconomicResource, id: ^evt.resource_inventoried_as_id),
	set: [
		previous_event_id: evt.id,
		primary_accountable_id: evt.receiver_id,
		custodian_id: evt.receiver_id,
	],
	inc: [ ...negate(resource_quantity)... ])

A partial transfer (for example 2 of 5 units into the buyer's existing resource) therefore gives the receiver the rights and custody of the 3 units the provider kept. The branch without a destination keeps the source's owner (set: [previous_event_id: evt.id] only, L1023-L1029). That is what we'd expect in both cases.

The existing test "pass with :to_resource_inventoried_as" transfers the whole accounting quantity and does not assert the source's accountable or custodian afterwards, so this goes unnoticed.

Proposal

In the to_resource_inventoried_as_id branch, set only previous_event_id on the source, as the other branch does. Add a test with a partial transfer into an existing resource that asserts the source keeps its accountable and custodian.

If moving ownership of the source is intended (for example, only for full transfers), it should be conditioned on the transfer emptying the resource, and documented.

The marketplace does not use toResourceInventoriedAs today: each sale creates a new resource for the buyer. Reusing the buyer's existing resource with N-unit sales (interfacerproject/interfacer-gui#962) would hit this. Read from the code at 91be858, not reproduced against a running instance.


Generated by Claude Code

Dominant language
Elixir
Stars
18
Forks
4
Avg merge
22d 17h
Merged PRs (30d)
1

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from interfacerproject/zenflows

All issues in interfacerproject/zenflows

Similar issues

More Elixir issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.