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

CRM: Add WooSync status to avoid creating invoices and transactions #37276

Conversation

gogdzl
Copy link
Contributor

@gogdzl gogdzl commented May 8, 2024

Fixes https://github.com/Automattic/zero-bs-crm/issues/3463

Proposed changes:

  • This PR adds a status mapping to WooSync to avoid creating invoices and transactions in Jetpack CRM from WooCommerce

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

https://github.com/Automattic/zero-bs-crm/issues/3463

Does this pull request change what data or activity we track or use?

No.

Testing instructions:

Initial Setup and Verification of WooSync:

  1. Verify WooSync Functionality:

    • Navigate to the WooSync hub.
    • Confirm that the status displays Status: Sync Completed.
  2. Enable Invoice Generation:

    • If invoice generation is not active, switch to the trunk branch and activate the feature at /wp-admin/admin.php?page=zerobscrm-plugin-settings&tab=woosync.
  3. Create a WooCommerce Order:

    • Place a new order in WooCommerce.
  4. Verify Transaction and Invoice Creation:

    • Ensure both the transaction and invoice are correctly generated.

Testing the New PR Setting:

  1. Switch to the PR Branch:

    • Change to the branch update/crm/3463-woosync-avoid-creating-invoices-and-transactions-for-woo-draft.
  2. Configure WooCommerce Settings:

    • Access Woo settings at /wp-admin/admin.php?page=zerobscrm-plugin-settings&tab=woosync.
    • Change the status mapping from one of WooCommerce's orders for at least one Invoice and one Transaction status to Do not Create.
  3. Add Another WooCommerce Order:

    • Place a new order with the new mapping and confirm that WooSync is not generating Invoices when the mapping is set to Do not Create.
    • Place a new order with the new mapping and confirm that WooSync is not generating Transactions when the mapping is set to Do not Create.

Documentantion changes

We will need to update our CRM Knowledge Base to reflect this change. It is necessary to update our WooSync page to inform users that we now offer a new setting and explain how it works.

Pinging @StefMattana

image

@gogdzl gogdzl requested a review from cleacos May 8, 2024 01:50
@gogdzl gogdzl self-assigned this May 8, 2024
@gogdzl gogdzl added [Status] Needs Team Review [Plugin] CRM Issues about the Jetpack CRM plugin labels May 8, 2024
@gogdzl gogdzl added this to the crm/6.4.3 milestone May 8, 2024
Copy link
Contributor

github-actions bot commented May 8, 2024

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Once your PR is ready for review, check one last time that all required checks appearing at the bottom of this PR are passing or skipped.
Then, add the "[Status] Needs Team Review" label and ask someone from your team review the code. Once reviewed, it can then be merged.
If you need an extra review from someone familiar with the codebase, you can update the labels from "[Status] Needs Team Review" to "[Status] Needs Review", and in that case Jetpack Approvers will do a final review of your PR.

// Add/update invoice (if enabled) (previously `add_or_update_invoice`)
if ( $settings['wcinv'] == 1 ) {
// Add/update invoice (if enabled) (previously `add_or_update_invoice`), while checking for a 'Do not create' status to avoid creating this invoice if the mapping doesn't allow it
if ( $settings['wcinv'] == 1 && isset( $crm_object_data['invoice'] ) && isset( $crm_object_data['invoice']['status'] ) && $crm_object_data['invoice']['status'] !== WOOSYNC_DO_NOT_CREATE['id'] ) { // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual
Copy link
Contributor

Choose a reason for hiding this comment

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

GH is complaining about something here...

// If we ever have more WooSync constants we should create a separate php file.
if ( ! defined( 'WOOSYNC_DO_NOT_CREATE' ) ) {
define(
'WOOSYNC_DO_NOT_CREATE',
Copy link
Contributor

@cleacos cleacos May 9, 2024

Choose a reason for hiding this comment

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

For this global definition I'd add the JPCRM_ prefix => JPCRM_WOOSYNC_DO_NOT_CREATE

cleacos
cleacos previously approved these changes May 9, 2024
Copy link
Contributor

@cleacos cleacos left a comment

Choose a reason for hiding this comment

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

It works well for me. I'd add the JPCRM_ prefix to the WOOSYNC_DO_NOT_CREATE definition => JPCRM_WOOSYNC_DO_NOT_CREATE

Other than that, LGTM!

@cleacos
Copy link
Contributor

cleacos commented May 9, 2024

As a side note, if an invoice is created because the order is different to Draft, if we set the order a Draft, the invoice/transaction doesn't change its status.

For me that behavior is OK, once the invoice is created, you cannot go back automatically if the order is set as Draft later. But maybe I'd say that, if the invoice/transaction is already created and the new status should be Draft, we have to switch to that status.

@gogdzl
Copy link
Contributor Author

gogdzl commented May 9, 2024

As a side note, if an invoice is created because the order is different to Draft, if we set the order a Draft, the invoice/transaction doesn't change its status.

That is a known problem, we sync only existing transactions, if a transactions gets deleted we don't record that.

// Add/update invoice (if enabled) (previously `add_or_update_invoice`)
if ( $settings['wcinv'] == 1 ) {
// Add/update invoice (if enabled) (previously `add_or_update_invoice`), while checking for a 'Do not create' status to avoid creating this invoice if the mapping doesn't allow it
if ( $settings['wcinv'] == 1 && isset( $crm_object_data['invoice'] ) && isset( $crm_object_data['invoice']['status'] ) && $crm_object_data['invoice']['status'] !== JPCRM_WOOSYNC_DO_NOT_CREATE['id'] ) { // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know why GH is still complaining here...

cleacos
cleacos previously approved these changes May 10, 2024
Copy link
Contributor

@cleacos cleacos left a comment

Choose a reason for hiding this comment

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

Re-approved it...

A test is failing

@cleacos
Copy link
Contributor

cleacos commented May 10, 2024

As a side note, if an invoice is created because the order is different to Draft, if we set the order a Draft, the invoice/transaction doesn't change its status.

That is a known problem, we sync only existing transactions, if a transactions gets deleted we don't record that.

I mean, the user creates an Order in a valid status, let's say completed. JPCRM will generate the invoice as paid, but the user takes that order and changes it to Draft; in JPCRM, the invoice status will not change to Draft, it will leave the invoice as Paid. But it's a side note about this edge case not covered by this PR, not a blocker.

Copy link
Contributor

@cleacos cleacos left a comment

Choose a reason for hiding this comment

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

👍

@gogdzl gogdzl merged commit 8477a12 into trunk May 10, 2024
53 checks passed
@gogdzl gogdzl deleted the update/crm/3463-woosync-avoid-creating-invoices-and-transactions-for-woo-draft branch May 10, 2024 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[CRM] WooSync Module [Plugin] CRM Issues about the Jetpack CRM plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants