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

View entity to fetch eligible records #2

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
5b01be8
Added a view to fetch the order level details of orders eligible for NS
Dec 3, 2024
eb61100
Merge branch 'hotwax:main' into view-entity-to-fetch-eligible-records
Shinde-nutan Dec 3, 2024
32a8a8b
Added the OPP in the view entity
Dec 3, 2024
2c31601
Merge branch 'view-entity-to-fetch-eligible-records' of https://githu…
Dec 3, 2024
d46e953
Added a view to fetch the item level detail
Dec 3, 2024
ab82460
Remove the join of OPP from EligibleOrdersForNetSuiteView and join of…
Dec 4, 2024
2e5bb05
Merge branch 'hotwax:main' into view-entity-to-fetch-eligible-records
Shinde-nutan Dec 4, 2024
998d0cc
Remove the alies-all for OH and OI from the respective views
Dec 4, 2024
ef2d195
Merge branch 'view-entity-to-fetch-eligible-records' of https://githu…
Dec 4, 2024
fa146ae
Added a view IntegrationTypeMappingAndEnum
Dec 4, 2024
210d9a2
Added a view to fetch the eligible order ids and remove the eligiblit…
Dec 5, 2024
3b699cf
added the communicationeventandorder view.
Shinde-nutan Dec 11, 2024
c26d7d2
Added comments in the viewEntity.
Shinde-nutan Dec 13, 2024
8589b1a
shift the view entity into new file.
Shinde-nutan Dec 14, 2024
42b511f
updated the component name
Shinde-nutan Dec 14, 2024
68a40ea
Added the subselect in the EligibleOrdersForNetSuiteView to add a che…
Shinde-nutan Dec 17, 2024
237bd92
added comment in subselect
Shinde-nutan Dec 17, 2024
0b677aa
added the enum code in the view
Shinde-nutan Dec 20, 2024
7e56cf5
Added a view entity (InvalidOrdersForNetsuite) to exculde the invalid…
Shinde-nutan Dec 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion component.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<component xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://moqui.org/xsd/moqui-conf-3.xsd"
name="mantle-net-suite-connector" version="1.0.0">
name="mantle-netsuite-connector" version="1.0.0">
</component>
231 changes: 231 additions & 0 deletions entity/OrderViewEntities.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
<?xml version="1.0" encoding="UTF-8"?>

<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://moqui.org/xsd/entity-definition-3.xsd">
<!--
Created a view to fetch eligible orders for creating an order feed from HotWax to NetSuite.
The view consolidates relevant data from `OrderHeader`, `OrderIdentification`, and `PartyIdentification` entities.

Criteria for fetching eligible records:
1. The order must be of type `SALES_ORDER`
2. The order should not already synced with Netsuite
3. The customer should be synced with Netsuite
4. A date filter can be applied in `OrderIdentification` to fetch the eligible identification.
-->
<view-entity entity-name="EligibleOrdersForNetSuiteView" package="co.hotwax.order" group="ofbiz_transactional">
<member-entity entity-alias="OH" entity-name="org.apache.ofbiz.order.order.OrderHeader"/>
<member-entity entity-alias="OID" entity-name="co.hotwax.order.OrderIdentification" join-from-alias="OH" join-optional="true">
<key-map field-name="orderId"/>
<entity-condition>
<econdition entity-alias="OID" field-name="orderIdentificationTypeId" value="NETSUITE_ORDER_ID"/>
<date-filter/>
</entity-condition>
</member-entity>
<member-entity entity-alias="PID" entity-name="org.apache.ofbiz.party.party.PartyIdentification" join-from-alias="ODR">
<key-map field-name="partyId"/>
<entity-condition>
<econdition entity-alias="PID" field-name="partyIdentificationTypeId" value="NETSUITE_CUSTOMER_ID"/>
</entity-condition>
</member-entity>
<entity-condition>
<econdition entity-alias="OH" field-name="orderTypeId" operator="equals" value="SALES_ORDER"/>
<econdition entity-alias="OID" field-name="orderId" operator="equals" value=""/>
</entity-condition>
<alias-all entity-alias="OH"/>
</view-entity>

<!--Purpose of this view:
- The primary purpose of this view-entity is to fetch the order-related data required by the service to prepare the order feed from Hotwax to NetSuite.

Fetching entities multiple times:
1. OrderContactMech (OCMBL, OCMSL, OCMBP, OCMSP, OCMBE, OCMSE):
- The OrderContactMech entity is fetched multiple times to retrieve contact mechanisms for various purposes:
- `OCMBL`: For billing location details.
- `OCMSL`: For shipping location details.
- `OCMBP`: For billing phone details.
- `OCMSP`: For shipping phone details.
- `OCMBE`: For billing email details.
- `OCMSE`: For shipping email details.
- Each alias is used for a specific contact mechanism purpose, ensuring data is retrieved correctly without overlaps.
2. PostalAddress (PAB, PAS):
- The PostalAddress entity is fetched twice to separately retrieve the billing and shipping addresses.
- `PAB` is used to fetch the billing address associated with the billing contact mechanism (BILLING_LOCATION).
- `PAS` is used to fetch the shipping address associated with the shipping contact mechanism (SHIPPING_LOCATION).
3. TelecomNumber (TN, TNSP):
- Fetched twice to separately retrieve billing and shipping phone numbers.
- `TN` retrieves billing phone details associated with `PHONE_BILLING`.
- `TNSP` retrieves shipping phone details associated with `PHONE_SHIPPING`.
4. Geo (COUNTRYGEOBL, COUNTRYGEOSL):
- Fetched twice to separately retrieve country details for billing and shipping addresses.
- `COUNTRYGEOBL` retrieves the country information for billing address (`PAB`).
- `COUNTRYGEOSL` retrieves the country information for shipping address (`PAS`).

Reason for including all the details in this view:
- To simplify the implementation of the service:
- Fetching details like PostalAddress, TelecomNumber, and other related entities directly in the service would make the implementation complex and harder to maintain.
- Consolidating all the data fetching logic in the view keeps the service focused on business logic rather than data retrieval. (mainly we want to keep the feting logic and the business logic separate)
- To centralize data retrieval logic:
- This approach also makes it easier to modify data retrieval logic in one place (the view) without impacting services.

Approach to alias selection:
- Only the required fields are selected in the alias definitions to avoid fetching unnecessary data.
- Each alias (e.g., `shippingAddress1`, `billingEmail`, `ShippingCost`) maps to a specific field that is directly used in the service.
- This minimizes the size of the result set
-->
<view-entity entity-name="OrdersDetailsForNetSuiteView" package="co.hotwax.order" group="ofbiz_transactional">
<member-entity entity-alias="OH" entity-name="org.apache.ofbiz.order.order.OrderHeader"/>
<member-entity entity-alias="SCENM" entity-name="org.apache.ofbiz.common.enum.Enumeration" join-from-alias="OH" join-optional="true">
<key-map field-name="salesChannelEnumId" related="enumId"/>
</member-entity>
<member-entity entity-alias="ODR" entity-name="org.apache.ofbiz.order.order.OrderRole" join-from-alias="OH" join-optional="true">
<key-map field-name="orderId"/>
<entity-condition>
<econdition entity-alias="ODR" field-name="roleTypeId" operator="equals" value="BILL_TO_CUSTOMER"/>
</entity-condition>
</member-entity>
<member-entity entity-alias="PID" entity-name="org.apache.ofbiz.party.party.PartyIdentification" join-from-alias="ODR">
<key-map field-name="partyId"/>
<entity-condition>
<econdition entity-alias="PID" field-name="partyIdentificationTypeId" value="NETSUITE_CUSTOMER_ID"/>
</entity-condition>
Copy link
Contributor

Choose a reason for hiding this comment

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

@Shinde-nutan,
Add one more entity condition to include "SHOPIFY_CUST_ID"

Copy link
Author

Choose a reason for hiding this comment

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

Hello sir,
In this view we are fetching the details which is required for an order to sync at Netsuite.
the shopify customer id is not required field. if needed we can add that in the custom groovy file which we are preparing specific to client.

Copy link
Contributor

Choose a reason for hiding this comment

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

While we will have Shopify as a constant in our integrations, fetching the field in this view will make this specific to Shopify only and create need for refactoring should orders enter HotWax from another source. For now I agree with @Shinde-nutan here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hello @dt2patel

I agreed.

During the KR Production rollout, someone enabled the "Import Customer Job," which resulted in duplicate customers being created in NetSuite. When we create customers through the "Import Customer Job," we store the Shopify Customer ID in the External ID field of the Party entity.

However, when syncing historical customers from NetSuite or importing a new order from Shopify, we create a PartyIdentification record with the Shopify Customer ID and the corresponding partyIdentificationTypeID defined in OMS.

To avoid duplication issues, we need to add a condition to filter valid customer records appropriately during the fetch process. So we can add the condition in the Groovy file.

CC: @Shinde-nutan

</member-entity>
<member-entity entity-alias="OCMBL" entity-name="org.apache.ofbiz.order.order.OrderContactMech" join-from-alias="OH" join-optional="true">
<key-map field-name="orderId"/>
<entity-condition>
<econdition entity-alias="OCMBL" field-name="contactMechPurposeTypeId" operator="equals" value="BILLING_LOCATION"/>
</entity-condition>
</member-entity>
<member-entity entity-alias="PAB" entity-name="org.apache.ofbiz.party.contact.PostalAddress" join-from-alias="OCMBL" join-optional="true">
<key-map field-name="contactMechId"/>
</member-entity>
<member-entity entity-alias="COUNTRYGEOBL" entity-name="org.apache.ofbiz.common.geo.Geo" join-from-alias="PAB" join-optional="true">
<key-map field-name="countryGeoId" related="geoId"/>
</member-entity>
<member-entity entity-alias="OCMSL" entity-name="org.apache.ofbiz.order.order.OrderContactMech" join-from-alias="OH" join-optional="true">
<key-map field-name="orderId"/>
<entity-condition>
<econdition entity-alias="OCMSL" field-name="contactMechPurposeTypeId" operator="equals" value="SHIPPING_LOCATION"/>
</entity-condition>
</member-entity>
<member-entity entity-alias="PAS" entity-name="org.apache.ofbiz.party.contact.PostalAddress" join-from-alias="OCMSL" join-optional="true">
<key-map field-name="contactMechId"/>
</member-entity>
<member-entity entity-alias="COUNTRYGEOSL" entity-name="org.apache.ofbiz.common.geo.Geo" join-from-alias="PAS" join-optional="true">
<key-map field-name="countryGeoId" related="geoId"/>
</member-entity>
<member-entity entity-alias="OCMBP" entity-name="org.apache.ofbiz.order.order.OrderContactMech" join-from-alias="OH" join-optional="true">
<key-map field-name="orderId"/>
<entity-condition>
<econdition entity-alias="OCMBP" field-name="contactMechPurposeTypeId" operator="equals" value="PHONE_BILLING"/>
</entity-condition>
</member-entity>
<member-entity entity-alias="TN" entity-name="org.apache.ofbiz.party.contact.TelecomNumber" join-from-alias="OCMBP" join-optional="true">
<key-map field-name="contactMechId"/>
</member-entity>
<member-entity entity-alias="OCMSP" entity-name="org.apache.ofbiz.order.order.OrderContactMech" join-from-alias="OH" join-optional="true">
<key-map field-name="orderId"/>
<entity-condition>
<econdition entity-alias="OCMSP" field-name="contactMechPurposeTypeId" operator="equals" value="PHONE_SHIPPING"/>
</entity-condition>
</member-entity>
<member-entity entity-alias="TNSP" entity-name="org.apache.ofbiz.party.contact.TelecomNumber" join-from-alias="OCMSP" join-optional="true">
<key-map field-name="contactMechId"/>
</member-entity>
<member-entity entity-alias="OCMBE" entity-name="org.apache.ofbiz.order.order.OrderContactMech" join-from-alias="OH" join-optional="true">
<key-map field-name="orderId"/>
<entity-condition>
<econdition entity-alias="OCMBE" field-name="contactMechPurposeTypeId" operator="equals" value="BILLING_EMAIL"/>
</entity-condition>
</member-entity>
<member-entity entity-alias="CMBE" entity-name="org.apache.ofbiz.party.contact.ContactMech" join-from-alias="OCMBE" join-optional="true">
<key-map field-name="contactMechId"/>
</member-entity>
<member-entity entity-alias="OCMSE" entity-name="org.apache.ofbiz.order.order.OrderContactMech" join-from-alias="OH" join-optional="true">
<key-map field-name="orderId"/>
<entity-condition>
<econdition entity-alias="OCMSE" field-name="contactMechPurposeTypeId" operator="equals" value="SHIPPING_EMAIL"/>
</entity-condition>
</member-entity>
<member-entity entity-alias="CMSE" entity-name="org.apache.ofbiz.party.contact.ContactMech" join-from-alias="OCMSE" join-optional="true">
<key-map field-name="contactMechId"/>
</member-entity>
<member-entity entity-alias="OADJ" entity-name="org.apache.ofbiz.order.order.OrderAdjustment" join-from-alias="OH" join-optional="true">
<key-map field-name="orderId"/>
<entity-condition>
<econdition field-name="orderAdjustmentTypeId" value="SHIPPING_CHARGES"/>
</entity-condition>
</member-entity>
<alias name="orderName" field="orderName" entity-alias="OH"/>
<alias name="orderId" field="orderId" entity-alias="OH"/>
<alias name="orderDate" field="orderDate" entity-alias="OH"/>
<alias name="shippingContactMechId" field="contactMechId" entity-alias="PAS"/>
<alias name="shippingAddress1" field="address1" entity-alias="PAS"/>
<alias name="shippingAddress2" field="address2" entity-alias="PAS"/>
<alias name="shippingCity" field="city" entity-alias="PAS"/>
<alias name="shippingState" field="stateProvinceGeoId" entity-alias="PAS"/>
<alias name="shippingPostalCode" field="postalCode" entity-alias="PAS"/>
<alias name="shippingCountry" field="geoCode" entity-alias="COUNTRYGEOSL"/>
<alias name="billingContactMechId" field="contactMechId" entity-alias="PAB"/>
<alias name="billingAddress1" field="address2" entity-alias="PAB"/>
<alias name="billingAddress2" field="address2" entity-alias="PAB"/>
<alias name="billingCity" field="city" entity-alias="PAB"/>
<alias name="billingState" field="stateProvinceGeoId" entity-alias="PAB"/>
<alias name="billingPostalCode" field="postalCode" entity-alias="PAB"/>
<alias name="billingCountry" field="geoCode" entity-alias="COUNTRYGEOBL"/>
<alias name="customerId" field="idValue" entity-alias="PID"/>
<alias name="salesChannel" field="description" entity-alias="SCENM"/>
<alias name="billingCountryCode" field="countryCode" entity-alias="TN"/>
<alias name="billingAreaCode" field="countryCode" entity-alias="TN"/>
<alias name="billingContactNumber" field="contactNumber" entity-alias="TN"/>
<alias name="shippingCountryCode" field="countryCode" entity-alias="TNSP"/>
<alias name="shippingAreaCode" field="countryCode" entity-alias="TNSP"/>
<alias name="shippingContactNumber" field="contactNumber" entity-alias="TNSP"/>
<alias name="billingEmail" field="infoString" entity-alias="CMBE"/>
<alias name="shippingEmail" field="infoString" entity-alias="CMSE"/>
<alias name="ShippingCost" field="amount" entity-alias="OADJ"/>
</view-entity>

<!--
Purpose of this view:
- The primary purpose of the `OrderItemsForNetSuiteView` view is to fetch order item-level details that are required for creating the order feed from Hotwax to NetSuite.
- It specifically checks for the eligibility of each order item for NetSuite processing by ensuring that the product has a corresponding NetSuite product ID.`.

Scenarios to consider:
1. **Custom Gift Card Items in POS Orders**:
- In some cases, a POS order might contain both regular items and custom gift card items.
- Custom gift card items typically do not have a `NETSUITE_PRODUCT_ID` associated with them.
- Since this view filters items based on the presence of a `NETSUITE_PRODUCT_ID`, custom gift card items will be excluded from the results.
- This exclusion can lead to incomplete or incorrect data in such scenarios, as the custom gift card item will not be included in the feed sent to NetSuite.

Design decision rationale:
- By enforcing the condition that each product must have a `NETSUITE_PRODUCT_ID`, this view ensures that only eligible items are included in the NetSuite feed.
- However, scenarios like the one described above must be handled at the service level or through a separate mechanism to ensure that excluded items (such as custom gift cards) are appropriately processed or flagged.
- Keeping the data fetching logic in this view simplifies the implementation of the service and maintains separation of concerns between data retrieval and business logic.
-->
<view-entity entity-name="OrderItemsForNetSuiteView" package="co.hotwax.order" group="ofbiz_transactional">
<member-entity entity-alias="OI" entity-name="org.apache.ofbiz.order.order.OrderItem"/>
<member-entity entity-alias="P" entity-name="org.apache.ofbiz.product.product.Product" join-from-alias="OI">
<key-map field-name="productId"/>
</member-entity>
<member-entity entity-alias="GID" entity-name="org.apache.ofbiz.product.product.GoodIdentification" join-from-alias="P">
<key-map field-name="productId"/>
<entity-condition>
<econdition field-name="goodIdentificationTypeId" value="NETSUITE_PRODUCT_ID"/>
<date-filter/>
</entity-condition>
</member-entity>
<member-entity entity-alias="OISG" entity-name="org.apache.ofbiz.order.order.OrderItemShipGroup" join-from-alias="OI">
<key-map field-name="orderId"/>
<key-map field-name="shipGroupSeqId"/>
</member-entity>
<alias name="orderItemSeqId" field="orderItemSeqId" entity-alias="OI"/>
<alias name="orderId" field="orderId" entity-alias="OI"/>
<alias name="price" field="unitPrice" entity-alias="OI"/>
<alias name="quantity" field="quantity" entity-alias="OI"/>
<alias name="itemStatus" field="statusId" entity-alias="OI"/>
<alias name="productId" field="productId" entity-alias="OI"/>
<alias name="NetSuiteProductId" field="idValue" entity-alias="GID"/>
<alias name="shipmentMethodTypeId" entity-alias="OISG"/>
<alias name="location" field="facilityId" entity-alias="OISG"/>
</view-entity>
</entities>
25 changes: 25 additions & 0 deletions entity/omsViewWntities.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://moqui.org/xsd/entity-definition-3.xsd">

<!-- we can shift this view into ofbiz-oms-udm component where all other generic views are created as IntegrationTypeMappingAndEnum view is not specific to netsuite. -->
<view-entity entity-name="IntegrationTypeMappingAndEnum" package="co.hotwax.integration">
<member-entity entity-alias="ITM" entity-name="co.hotwax.integration.IntegrationTypeMapping"/>
<member-entity entity-alias="ENUM" entity-name="org.apache.ofbiz.common.enum.Enumeration" join-from-alias="ITM">
<key-map field-name="integrationTypeId"/>
</member-entity>
<alias-all entity-alias="ITM"/>
<alias-all entity-alias="ENUM"/>
<alias name="EnumDescription" field="description" entity-alias="ENUM"/>
</view-entity>

<!-- we can shift this view into ofbiz-oms-udm component where all other generic views are created as CommunicationEventAndOrder view is not specific to netsuite. -->
<view-entity entity-name="CommunicationEventAndOrder" package="co.hotwax.integration">
<member-entity entity-alias="CO" entity-name="org.apache.ofbiz.order.order.CommunicationEventOrder"/>
<member-entity entity-alias="CE" entity-name="org.apache.ofbiz.party.communication.CommunicationEvent" join-from-alias="CO">
<key-map field-name="communicationEventId"/>
</member-entity>
<alias-all entity-alias="CO"/>
<alias-all entity-alias="CE"/>
</view-entity>
</entities>