Skip to content

CRM: Resolves #3303 - handle invoice status dropdown mismatches#32909

Merged
tbradsha merged 13 commits intotrunkfrom
fix/crm/3303-fix_invoice_status_dropdown_mismatches
Sep 15, 2023
Merged

CRM: Resolves #3303 - handle invoice status dropdown mismatches#32909
tbradsha merged 13 commits intotrunkfrom
fix/crm/3303-fix_invoice_status_dropdown_mismatches

Conversation

@tbradsha
Copy link
Copy Markdown
Contributor

@tbradsha tbradsha commented Sep 6, 2023

Resolves Automattic/zero-bs-crm#3303 - handle invoice status dropdown mismatches

Proposed changes:

If the invoice status in the database doesn't match an available status, the edit page dropdown defaults to the first item on the list, making it appear to be selected.

Quotes don't have real statuses, and contact statuses are not translated. This was already solved for transactions (#30644), but we need to the same for invoices.

This PR does the following:

  • If the status is an unexpected one, it appends the status as a dropdown option and selects it.
  • WooSync was translating some statuses before saving, and now it should properly save the status in English.
  • Along with the above, the invoice object now has a status_label key that can be used to output the translated status (e.g. listviews, edit page, client portal, and contact/company profiles).

The larger issue involves the fact that we store labels instead of keys in the database (#1497), which hopefully will be addressed at a future date. This PR begins to lay the groundwork for invoice status keys, though the "key" stored in the database is just the English name for the status at this stage.

Note also that this won't fix any existing errant saves in the database. We haven't had any complaints on this to date, but if it comes up after this is released, the easiest fix is to do a full Woo resync.

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

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

Testing instructions:

  1. Change the WP language to Spanish.
  2. Create a Woo order and sync it to the CRM.

In trunk:

  • 👍 It will show as expected in Spanish in the listview and Client Portal.
  • 👍 It will show as expected in Spanish in the assigned contact or company profile.
  • 👎 The status will save in the database in Spanish.
  • 👎 Listview quickfilters don't match statuses.
  • 👎 When editing the invoice, the status dropdown will look like it's set to the first status in the dropdown (Borrador), whereas it just wasn't able to find a match, so the dropdown defaults to the first item.
  • 👎 If you set the invoice to a non-existent status via the database, the above point applies; the dropdown seems to have the first item selected.
  • 👎 If you change the WP language back to English, the status shows in Spanish for the first two points.

In the fix/crm/3303-fix_invoice_status_dropdown_mismatches branch:

  • 👍 It will show as expected in Spanish in the listview and Client Portal.
  • 👍 It will show as expected in Spanish in the assigned contact or company profile.
  • 👍 The status will save in the database in English.
  • 👍 Listview quickfilters match statuses.
  • 👍 When editing the invoice, the status dropdown will properly select the current status.
  • 👍 If you set the invoice to a non-existent status via the database, the dropdown shows said status as selected.
  • 👍 If you change the WP language back to English, the status shows in English everywhere.

@tbradsha tbradsha added [Status] Needs Team Review Obsolete. Use Needs Review instead. [Plugin] CRM Issues about the Jetpack CRM plugin labels Sep 6, 2023
@tbradsha tbradsha requested a review from a team September 6, 2023 21:15
@tbradsha tbradsha self-assigned this Sep 6, 2023
@github-actions github-actions bot added [CRM] Woo Sync Module Admin Page React-powered dashboard under the Jetpack menu labels Sep 6, 2023
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Sep 6, 2023

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 (other than "Required review") 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.


Crm plugin:

  • Next scheduled release: September 27, 2023.
  • Scheduled code freeze: September 20, 2023.

Comment on lines 267 to 273
if ( in_array( $order_status, $paid_statuses, true ) ) {
$status = __( 'Paid', 'zero-bs-crm' );
$status = 'Paid';
} elseif ( $order_status === 'checkout-draft' ) {
$status = __( 'Draft', 'zero-bs-crm' );
$status = 'Draft';
} else {
$status = __( 'Unpaid', 'zero-bs-crm' );
$status = 'Unpaid';
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Don't we need to add some kind of migration to be backwards compatible?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We have this problem throughout the whole codebase.
E.g.:

includes/ZeroBSCRM.DAL3.Helpers.php

		// retrieves statuses from object :)
		function zeroBSCRM_getInvoicesStatuses(){
		    
		    // for DAL3+ these are hard typed, probably need to sit in the obj:
		    return array(
		    	__( 'Draft', 'zero-bs-crm' ),
		    	__( 'Unpaid', 'zero-bs-crm' ),
		    	__( 'Paid', 'zero-bs-crm' ),
		    	__( 'Overdue', 'zero-bs-crm' ),
		    	__( 'Deleted', 'zero-bs-crm' )
		    );
		}

Copy link
Copy Markdown
Contributor Author

@tbradsha tbradsha Sep 8, 2023

Choose a reason for hiding this comment

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

Don't we need to add some kind of migration to be backwards-compatible?

I mentioned this briefly above; to my knowledge, only WooSync had this bug. A migration gets messy because we have know way of knowing if:

  1. The user has changed languages since, or
  2. The value in the database is not something they manually added.

Since there's an easy workaround (Woo resync), I think avoiding a migration is best until we actually move to some real key-based status setup.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We have this problem throughout the whole codebase.

Indeed, my goal here was primarily to address the specific Woo situation, and to make output more i18n-friendly. But I'll poke around and see if there are other cases we can clean things up.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed code block that was meant to set an invoice to "Unpaid" if it was "Draft" and emailed to a user: 56380a3

Because 'Draft' !== __( 'Draft', 'zero-bs-crm' ) if the status has translations, the condition was never met previously.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed invoice bulk action status change which hasn't worked previously on non-English installs: ab85f34

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

WooSync status mapping was previously using translated status, but now correctly uses the English status with translated output: 6ebf0c0

@tbradsha
Copy link
Copy Markdown
Contributor Author

tbradsha commented Sep 8, 2023

@gogdzl I've widened the scope of this PR to cover all invoice statuses I could find, and I think they're all properly handled (along with some bug fixes that have existed since who knows when).

@tbradsha tbradsha force-pushed the fix/crm/3303-fix_invoice_status_dropdown_mismatches branch from 5c2b7b2 to e7c36dc Compare September 15, 2023 12:43
@tbradsha
Copy link
Copy Markdown
Contributor Author

Rebased, as this has been sitting some time...

@tbradsha tbradsha requested a review from a team September 15, 2023 12:47
Copy link
Copy Markdown
Contributor

@gogdzl gogdzl 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 and it is a solid move towards fixing our statuses issues with translation.

Great job!

@tbradsha tbradsha merged commit 393dc93 into trunk Sep 15, 2023
@tbradsha tbradsha deleted the fix/crm/3303-fix_invoice_status_dropdown_mismatches branch September 15, 2023 13:26
@github-actions github-actions bot added this to the crm/6.1.1 milestone Sep 15, 2023
@github-actions github-actions bot removed the [Status] Needs Team Review Obsolete. Use Needs Review instead. label Sep 15, 2023
@cleacos
Copy link
Copy Markdown
Contributor

cleacos commented Sep 21, 2023

A minor issue with this change. This happens on the WooSync order mapping in sites translated to other languages:

Before the change:

image

After the change:

image

As you can see, any previous mapping will be reset to the default. So if the user had a different mapping (low probability), they will lose it.

@tbradsha
Copy link
Copy Markdown
Contributor Author

Thanks, @cleacos! I have notes from our call as well and will look into this today to see if it's something we can/should address.

@tbradsha
Copy link
Copy Markdown
Contributor Author

Handled in #33254.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Admin Page React-powered dashboard under the Jetpack menu [CRM] Portal Module [CRM] WooSync Module [Plugin] CRM Issues about the Jetpack CRM plugin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants