Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev/core#2486 Add in FinancialItem APIv4 Entity #20433

Merged
merged 1 commit into from
Jun 1, 2021

Conversation

seamuslee001
Copy link
Contributor

Overview

Does what it says on the tin

Before

No APIv4 entity

After

APIv4 Entity

ping @eileenmcnaughton @JoeMurray @monishdeb

@civibot
Copy link

civibot bot commented May 27, 2021

(Standard links)

@civibot civibot bot added the master label May 27, 2021
@eileenmcnaughton
Copy link
Contributor

eileenmcnaughton commented May 27, 2021

@seamuslee001 did you check in search kit if this works in terms of it being able to discover the joins? I think that with the other financial entities I had to do some metadata fixes to make them bridgeable

@colemanw
Copy link
Member

Since this isn't a bridge entity, it should work ok with joins... except...
I noticed that the field entity_table doesn't have a pseudoconstant, which means the API will have no clue what other entities it can potentially join onto.

@monishdeb
Copy link
Member

Agree that this is not a bridge entity. I think the entity_table field shouldn't be required to have pseudoconstant like LineItem.entity_table or EntityFinancialTrxn.entity_table . Here entity_table holds civicrm_line_item|civicrm_financial_trxn

@colemanw
Copy link
Member

colemanw commented May 28, 2021

If there are only 2 possibilities for the value of entity_table then we definitely should add a pseudoconstant. That would make it much easier to understand what's going on here. A simple function callback to return those 2 items would be fine.

@eileenmcnaughton
Copy link
Contributor

I think it's fine to go with a callback but it would be nice to be able to just put options in the xml when there are only a couple

@colemanw
Copy link
Member

Maybe, but IMO we already have too many ways to define a pseudoconstant list.

@monishdeb
Copy link
Member

monishdeb commented May 31, 2021

Currently we are able to do joins on entity_table as in

$financialItems = \Civi\Api4\FinancialItem::get()
  ->setJoin([
    ['LineItem AS line_item', 'INNER', NULL, ['line_item.id', '=', 'entity_id'], ['entity_table', '=', "'civicrm_line_item'"]],
  ])
  ->execute();

But I am thinking how to declare psueduconstant for field which can dynamically extend to entity_table fields. I didn't find any such pseudoconstant declaration in xmls. How about:

--- a/xml/schema/Financial/FinancialItem.xml
+++ b/xml/schema/Financial/FinancialItem.xml
@@ -147,6 +147,10 @@
   <title>Entity ID</title>
   <type>int unsigned</type>
   <comment>The specific source item that is responsible for the creation of this financial_item</comment>
+    <pseudoconstant>
+      <entityTable>civicrm_financial_trxn|civicrm_line_item</entityTable>
+    </pseudoconstant>
   <add>4.3</add>
 </field>
 <dynamicForeignKey> 

and there would be callback function to expose the two table options on JOIN , SELECT and WHERE entity_id

@eileenmcnaughton
Copy link
Contributor

@monishdeb I think @colemanw is suggesting we stick with the approach in EntityFinancialTrxn

    <pseudoconstant>
      <callback>CRM_Financial_BAO_EntityFinancialTrxn::entityTables</callback>
    </pseudoconstant>
    <add>3.2</add>

Note search kit can figure out the join for that table based on the metadata - ie you can search for 'contributions with financial transactions' & it figures out the join based on the metadata

@monishdeb
Copy link
Member

@monishdeb I think @colemanw is suggesting we stick with the approach in EntityFinancialTrxn

    <pseudoconstant>
      <callback>CRM_Financial_BAO_EntityFinancialTrxn::entityTables</callback>
    </pseudoconstant>
    <add>3.2</add>

Note search kit can figure out the join for that table based on the metadata - ie you can search for 'contributions with financial transactions' & it figures out the join based on the metadata

Ah right, didn't knw that. I have submitted a PR #20464 which adds the pseudoconstant callback for LineItem and FinancialItem entity_table.

@eileenmcnaughton
Copy link
Contributor

ok - I'm good to merge this then - the other just needs a pair of eyes fresher than mine to take a look - ideally before we fork

@eileenmcnaughton eileenmcnaughton merged commit 15a79a5 into civicrm:master Jun 1, 2021
@eileenmcnaughton eileenmcnaughton deleted the financial_item_v4 branch June 1, 2021 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants