Skip to content

Feat/copy assets#2017

Open
joshuaunity wants to merge 8 commits intomainfrom
feat/copy-assets
Open

Feat/copy assets#2017
joshuaunity wants to merge 8 commits intomainfrom
feat/copy-assets

Conversation

@joshuaunity
Copy link
Contributor

@joshuaunity joshuaunity commented Mar 11, 2026

Description

This PR introduces an API allowing users to copy assets from one account to another, using the original account's assets as templates. The feature is currently in progress and being developed incrementally.

##TODO

  • Successfully Copy Assets to target account
  • Write a test to confirm the above feature
  • Write a test to confirm that asset parents and children are accurate
  • Successfully copy assets and asset sensors to the target account
  • Write a test to confirm the above feature
  • Successfully copy asset flexconfig... (i dont know how feasible this would be yet, mayb e 80% ?)
  • Write a test to confirm the above feature

Look & Feel

None

How to test

Further Improvements

Related Items

This PR closes #1966

Sign-off

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on code under GPL or other license that is incompatible with FlexMeasures

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
@joshuaunity joshuaunity requested a review from Flix6x March 11, 2026 11:45
@joshuaunity joshuaunity self-assigned this Mar 11, 2026
@joshuaunity joshuaunity added the enhancement New feature or request label Mar 11, 2026
@joshuaunity
Copy link
Contributor Author

CC @nhoening

@read-the-docs-community
Copy link

read-the-docs-community bot commented Mar 11, 2026

Documentation build overview

📚 flexmeasures | 🛠️ Build #31796443 | 📁 Comparing fb39eac against latest (c6bb60f)


🔍 Preview build

Show files changed (4 files in total): 📝 4 modified | ➕ 0 added | ➖ 0 deleted
File Status
genindex.html 📝 modified
_autosummary/flexmeasures.api.common.utils.api_utils.html 📝 modified
_autosummary/flexmeasures.api.v3_0.assets.html 📝 modified
api/v3_0.html 📝 modified

@Flix6x
Copy link
Contributor

Flix6x commented Mar 11, 2026

Thank you for requesting a review. It looks like the scope of this PR may be mistaken? You are creating an endpoint to copy all assets under a given account*, rather than an endpoint to copy a given asset, including all assets under it.

@nhoening
Copy link
Contributor

We can also discuss the test strategy. Joshua chose to implement a part of the solution, then tests for that, then the next part, test for that etc.

I believe we suggested initially to have one test case that tests a complete successful copy, then work on making it pass.

  • The test can assert the first part first (e.g. assets and subassets are copied), and others later(sensors, flex-config are copied), so you can still follow along how far you are in kaking the test pass, layer by layer.
  • This way would be more helpful in understanding together if the scope is agreed between all of us. The test is easier to write (I suggest using AI to help) and to read than the actual implementation.

"20 \u00b0C",
"3 * 230V * 16A"
]
"description": "Quantity string describing a fixed quantity."
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a mistake.

]
}
},
"/api/v3_0/assets/copy": {},
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd expect the API endpoint to live under "/api/v3_0/assets/<id>/copy".

Comment on lines +1552 to +1553
"account_id": fields.Int(required=True),
"target_account_id": fields.Int(required=True),
Copy link
Contributor

Choose a reason for hiding this comment

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

  • Please move these to a new class CopyAssetSchema(ma.Schema).
  • I'd propose two arguments for the "/api/v3_0/assets/<id>/copy" endpoint:
    • account_id = AccountIdField(data_key="account", required=False) # defaults to the account of the asset whose ID is part of the endpoint
    • parent_id = AssetIdField(data_key="parent", required=Flase) # defaults to the parent of the asset whose ID is part of the endpoint
  • The schema should also (@post_load):
    • If an account is explicitly given and no parent is explicitly given, then set parent to None, so it becomes a top-level asset (i.e. no parent) in the explicitly stated account
    • If a parent is explicitly stated and no account is explicitly given, then set the account to the account of the parent, so that the copied asset belongs to the same account as the parent.
    • Document that, if an account and parent are both explicitly stated, this makes it possible to create a copied asset that belongs to a different account than its parent. This is fine.
  • Finally, the endpoint should check for create-children permissions using both the account and parent as context.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I may have gotten this wrong, the current function actually copies over everything (asset) in the account, but from your feedback, it Is suppose to only cover a single asset(and its children along with sensors) that was specified

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm a bit confused. Why do we need to specify an account and a parent?

We can get this info from the asset we want to copy by asset.parent_asset_id.

If we are going to pass the asset ID in the URL, why are we not just copying that specified ID? As you said, with those two parameters, I can specify things outside the account.

I imagine the copy button on the UI will be in each asset detail page. When it is clicked on, a modal may pop up in which you need to select a target account to copy to.

Copy link
Contributor

Choose a reason for hiding this comment

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

I also don't understand why these two are required.

Copy link
Contributor

Choose a reason for hiding this comment

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

Suppose I have in a client's account two assets both with no parent representing two houses A and B. House A has a child asset representing an EV charger. I also have a house under my own account, house C. Here are some use cases:

1. Extra charger on house A

Copy charger asset with default account and parent. The new charger lives under house A next to the existing charger.

2. Same charger on house B

Copy charger asset with parent set to house B. The new charger lives under house B, and belongs to the same account.

3. Copy charger to my account

Copy charger asset with account set to my account. The new charger lives under my account, without a parent.

4. Copy charger to my house C

Parent asset is set to house C. Account defaults to the account of house C. New charger lives under house C and belongs to my account.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see, i think i get it now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ive made updates to this, what do you think @Flix6x

Signed-off-by: Joshua Edward <oghenerobojosh01@gmail.com>
@joshuaunity joshuaunity requested a review from Flix6x March 13, 2026 12:03
Signed-off-by: Joshua Edward <oghenerobojosh01@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Copying assets

3 participants