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

[Spree Upgrade] Fix adjustments sections in admin order edit page #3445

Merged

Conversation

luisramos0
Copy link
Contributor

@luisramos0 luisramos0 commented Feb 6, 2019

What? Why?

Closes #2940

Adding price_adjustments to a separate table in admin order edit page. This is mimicking what happens in v2.2. I dont think we should pull forward that commit from v2.2 because it depends on order associations not yet available in v2.0 and also because we may start customize this page to OFN needs.

What should we test?

Tax adjustments spec in #2940 (spec/features/admin/orders_spec.rb:266) is now green.

This will need to be manually tested in detail when we test v2.0 as a whole.

Dependencies

This is totally depend on #3194 so I left the commits in this PR. This PR is composed of only one commit, this one.

@luisramos0 luisramos0 self-assigned this Feb 6, 2019
@luisramos0 luisramos0 force-pushed the 2-0-order-adjusts branch 2 times, most recently from 2ba2d21 to 0daac42 Compare February 7, 2019 01:00
@luisramos0 luisramos0 changed the title WIP 2 0 order adjusts [Spree Upgrade] Fix adjustments sections in admin order edit page Feb 7, 2019
…t page so that user is aware of adjustments included in the price like for example tax rates

This change happens in spree v2.2 together with other changes (like adding the, not yet available in v2.0, shipment_adjustments this way). See commit for more details: spree/spree@636d87d
@@ -0,0 +1,14 @@
- if adjustments.present?
Copy link
Contributor

Choose a reason for hiding this comment

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

what if instead, we move this conditional to wrap the lines 7 and 8 of app/views/spree/admin/orders/_form.html.haml? this would decouple this view from the details of adjustments and make it more maintainable. It feels like a responsibility that _adjustments.html.haml shouldn't be aware of and can save us some CPU cycles.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we would require 2 if statements in _form (see that "adjustments" here are different lists in _form)
if in spree v2.2. with shipment_adjustments, that would make 3 if statements.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I know but that is something we would need to fix in _form. If it gets a bit messy is not _adjustments.html.haml responsibility.

Copy link
Contributor

Choose a reason for hiding this comment

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

I created #3475 for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

%th= Spree.t('amount')
%tbody#order-charges.with-border
- adjustments.each do |adjustment|
- if (adjustment.originator_type != 'Spree::ShippingMethod') && !(adjustment.originator_type == 'Spree::TaxRate' && adjustment.amount == 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Along the same lines, this couples a lot this view to the inner details of the adjustment. If we don't want to render anything for these kinds of adjustments we can avoid rendering the table altogether right?

We could accomplish this by loading from DB or filtering only the adjustments we care about and passing those in the adjustments local. This would make things a lot more maintainable IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, I agree, I noticed that problem. this is a problem in the spree code.
my decision was not to deviate too much from the spree code...

do you think I should do some magic in _form to get only adjustments that pass the conditional?
to be honest, instead, I think we should aim to remove these conditionals, these views should just show what's in the DB...

Copy link
Contributor

Choose a reason for hiding this comment

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

do you think I should do some magic in _form to get only adjustments that pass the conditional?
to be honest, instead, I think we should aim to remove these conditionals, these views should just show what's in the DB...

I would just load from DB those that we care about in this partial (shipping method nad tax rate) or do you mean we should display all kinds of adjustments?

Copy link
Contributor

Choose a reason for hiding this comment

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

I created #3476 for this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, thank for creating the issue. I think this can definitely be improved!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, I meant that we should display all kinds of adjustments.

Copy link
Contributor

@sauloperez sauloperez left a comment

Choose a reason for hiding this comment

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

Let's move forward with this PR as it closes an issue and improve things afterward.

@sauloperez sauloperez merged commit b51ad35 into openfoodfoundation:2-0-stable Feb 12, 2019
@sauloperez
Copy link
Contributor

sauloperez commented Feb 12, 2019

🙈 I was totally convinced I was the second reviewer and this was blocked due to my review

@luisramos0 luisramos0 deleted the 2-0-order-adjusts branch February 12, 2019 10:12
@luisramos0 luisramos0 requested a review from mkllnk February 12, 2019 10:14
@luisramos0
Copy link
Contributor Author

we can still have @mkllnk's review and I can include Maikels feedback in a follow up PR.

Copy link
Member

@kristinalim kristinalim left a comment

Choose a reason for hiding this comment

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

I left some comments here.

%thead
%th= Spree.t('name')
%th= Spree.t('amount')
%tbody#order-charges.with-border
Copy link
Member

Choose a reason for hiding this comment

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

It is now possible for the HTML ID order-charges to appear more than once in the page. I see that this is also an issue with in the 2-2-stable version of the file, but it isn't valid HTML.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, good catch. I am not sure what to do? I feel tempted to add this to one of the tech debt issues that Pau created above. maybe #3475 ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good to me @luisramos0

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, it isn't tech debt though. It could get in quicker than #3475, so I would create a new issue for it. 🙂 I'll do that in a bit.

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 just added this to #3477
both your points need to be fixed now @kristinalim they are not tech debt.

%th= Spree.t('name')
%th= Spree.t('amount')
%tbody#order-charges.with-border{"data-hook" => "order_details_adjustments"}
- order.adjustments.eligible.each do |adjustment|
Copy link
Member

Choose a reason for hiding this comment

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

The adjustments are no longer limited to those with eligible: true.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, I just verified that adjustment.set_eligibility is removing adjustments with amount zero...
so, this needs to be fixed now. I will create a spree upgrade issue to fix this and the order-charges issue above.
Thanks for you review @kristinalim

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

@luisramos0 I also realized that the Enterprise Fee Summary still needs to be scoped to just eligible: true. 😁 Thanks.

Copy link
Member

@mkllnk mkllnk left a comment

Choose a reason for hiding this comment

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

I have nothing else to add. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants