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

[Flower Farms] - Pay Suppliers Report #12879

Merged

Conversation

chahmedejaz
Copy link
Collaborator

@chahmedejaz chahmedejaz commented Sep 30, 2024

⚠️ Please use clockify code #12476 Flower Farms ⚠️

What? Why?

What should we test?

  • As mentioned in the issue
  • As discussed in comments:
    • Only supplier's per item fees should be included

Release notes

Changelog Category (reviewers may add a label for the release notes):

  • User facing changes
  • API changes (V0, V1, DFC or Webhook)
  • Technical changes only
  • Feature toggled

@chahmedejaz chahmedejaz force-pushed the task/12776-pay-suppliers-report branch from 271aa44 to bbed8f2 Compare September 30, 2024 22:51
@chahmedejaz chahmedejaz marked this pull request as ready for review October 7, 2024 10:14
@dacook dacook self-requested a review October 7, 2024 23:43
Copy link
Member

@dacook dacook left a comment

Choose a reason for hiding this comment

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

Great work! This looks good, but I have a ❓ query and a ± request for a change.

Also some other comments, but they are less important.

lib/reporting/reports/suppliers/helpers/columns_helper.rb Outdated Show resolved Hide resolved
lib/reporting/reports/suppliers/helpers/columns_helper.rb Outdated Show resolved Hide resolved
end

def order_number
proc { |line_items| order(line_items).number }
Copy link
Member

Choose a reason for hiding this comment

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

❓I could be wrong, but it looks like there could be multiple orders grouped together, so I don't think we should show an order number here, should we?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, you are right. Now, that I think of it and reviewed the report again, each order and their respective order cycles should have been displayed here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Doing this fix now.

Copy link
Collaborator Author

@chahmedejaz chahmedejaz Oct 8, 2024

Choose a reason for hiding this comment

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

It's fixed here 8ee8b37

Copy link
Member

Choose a reason for hiding this comment

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

Great!
± Now I think the line item helpers are no longer needed: variant, order, supplier, distributor, item_order_cycle

@chahmedejaz chahmedejaz force-pushed the task/12776-pay-suppliers-report branch from b793d82 to 8ee8b37 Compare October 8, 2024 21:31
@chahmedejaz chahmedejaz requested a review from dacook October 8, 2024 21:52
@chahmedejaz
Copy link
Collaborator Author

@dacook - I've addressed your comments, please review. Thanks

Copy link
Collaborator

@rioug rioug left a comment

Choose a reason for hiding this comment

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

Looks good @chahmedejaz ! But I think we can improve the testing a little bit.

spec/system/admin/reports/pay_your_suppliers_spec.rb Outdated Show resolved Hide resolved
Comment on lines 60 to 67
line_items.each do |line_item|
summary_hash[:total_excl_vat_and_fees] += total_excl_vat_and_fees.call(line_item)
summary_hash[:total_excl_vat] += total_excl_vat.call(line_item)
summary_hash[:total_fees_excl_vat] += total_fees_excl_vat.call(line_item)
summary_hash[:total_vat_on_fees] += total_vat_on_fees.call(line_item)
summary_hash[:total_tax] += total_tax.call(line_item)
summary_hash[:total] += total.call(line_item)
end
Copy link
Collaborator

Choose a reason for hiding this comment

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

We are only testing with one order and one line item. I think we need to update the spec to use more than on order and more than one line item in order for this to be properly tested.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Comment on lines 8 to 10
def variant(line_item)
line_item.variant
end
Copy link
Member

Choose a reason for hiding this comment

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

Now most of these helpers are no longer required and can be removed ;)

Copy link
Collaborator Author

@chahmedejaz chahmedejaz Oct 10, 2024

Choose a reason for hiding this comment

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

Not as of now, I think they are used in multiple places 😅

@chahmedejaz chahmedejaz requested review from dacook and rioug October 10, 2024 01:04
@dacook
Copy link
Member

dacook commented Oct 10, 2024

I think this addresses Gaetan's feedback sufficiently. Ready for manual testing.

@drummer83 drummer83 force-pushed the task/12776-pay-suppliers-report branch from 03c8e2c to 9c70867 Compare October 12, 2024 16:28
@drummer83 drummer83 added pr-staged-au staging.openfoodnetwork.org.au and removed pr-staged-au staging.openfoodnetwork.org.au labels Oct 12, 2024
@drummer83 drummer83 self-assigned this Oct 16, 2024
@drummer83 drummer83 added the pr-staged-au staging.openfoodnetwork.org.au label Oct 16, 2024
@drummer83 drummer83 force-pushed the task/12776-pay-suppliers-report branch from 9c70867 to 7f150c7 Compare October 16, 2024 19:28
@drummer83
Copy link
Contributor

Hi @chahmedejaz, @RachL and @tschumilas,

Wow, there's a lot to think of and to test here. Overall it's looking really great already. I found two things which I would like to have your confirmation for (marked ❓) and two things around fees need updating, I think (marked ❌).

Here is a quick summary:

  • Report is added to the report list for admins and super admins ✔️
  • Each order is listed (no grouping) ✔️
  • Date format ✔️
  • The requested columns are available for selection. ✔️
  • Output of pdf, xls and csv are working ✔️
  • Filtering of date range is working ✔️
  • Test taxes (blank if supplier is not tax registered)
    • Not quite: Even enterprise has "charges tax = no" active, then still the tax is shown in the report, if the product has a tax applied. This is strange, but it's displayed in the same way on the order details page, so I think it's ok. ❓
  • Test fees (blank if no fees applied)
    • Some fees are assigned to the wrong enterprise. ❌
    • Taxes on fees are not displayed. ❌
  • Payment fees and shipping fees are not considered in the report --> I think that's ok ❓

Regarding assignment of fees

This is the fee I have set up:
image

It is applied to the distributor of the order cycle:
image

In the order details we can see that it's charged by the distributor (Konrad Testhub):
image

The fee is added to supplier of the product (not the distributor, who is charging the fee). I think this leads to incorrect results if you want to pay your suppliers.
image

❓ It's tricky to solve. Do we have to list those line items again in the area of the distributor? And then only list the fee there?

Regarding taxes on fees

Taxes on fees are not displayed (all zero):
image

Unfortunately we are not displaying those taxes in the order details, but doing the calculation shows that it is included in 2.78 $:
image

Also the report "Enterprise Fees With Tax Report By Order" shows that the tax was calculated:
image

Open for testing

  • Test more filter options, like order cycle, hub, supplier.

Conclusion

I will move this back to "In progress" but before working on it, let's hear the feedback. Adding the feedback needed label too.
Thanks for the great work so far! 🙏

@drummer83 drummer83 removed the pr-staged-au staging.openfoodnetwork.org.au label Oct 16, 2024
@drummer83 drummer83 removed their assignment Oct 16, 2024
@tschumilas
Copy link

Test taxes (blank if supplier is not tax registered)
Not quite: Even enterprise has "charges tax = no" active, then still the tax is shown in the report, if the product has a tax applied. This is strange, but it's displayed in the same way on the order details page, so I think it's ok. ❓

This is a report to payout suppliers. So it is supplier enterprise fees and supplier tax status (registered or not) that matters. The tax shown may be different than the taxes (on fees or products) shown in other reports. (This is why we need this particular report)

2 scenerios are possible in Canada: 

(1) The supplier is tax registered AND the distributor (hub) is tax registered. The distributor (hub) will collect tax on taxable products. The hub will pay the supplier these taxes the hub collected, so the hub needs this number. (The tax registered supplier will remit this tax to the government)
(2) The supplier is NOT tax registered but the distributor (hub) IS tax registered. The hub collects tax on the sale (so yes, it will be on the order, and in other reports) but the hub will NOT payout this tax to the non-registered supplier. (The tax registered hub remits the tax to the government themselves). So the field for tax in this payout report should show no tax when the supplier is Not registered (eventhough the order and other reports show the tax).
Scenerio (3) - the supplier IS tax registered, but the hub is NOT tax registered is quirky and shouldn't really happen. Because the seller (distributor) is not tax registered, no tax is collected on sales. So no tax can be paid out to the supplier. So if the hub is not tax registered this report would have to show 0 tax collected.

@RachL
Copy link
Contributor

RachL commented Oct 21, 2024

@chahmedejaz is it clear for you on how to proceed here? Let me know if you'd need a call.

@chahmedejaz
Copy link
Collaborator Author

Thanks @drummer83 and @RachL

I'm looking into the issue to understand it properly, I validated the fees part, I think it's worked fine for me. I'm a bit confused on whose fees should be included? Supplier's or the distributor's?
Other than that I think I may need a call but I'll let you know pretty soon. Thanks

@tschumilas
Copy link

In response to the question - whose fees should be included - supplier fees, distributor fees or both?
I would say this report should only include the Supplier fees. This is a report to give a hub the amount they need to payout to suppliers. Hubs do not payout their enterprise fees (ie - their 'mark up') to suppliers.

But maybe there are other use cases elsewhere? I'm going to post in instance managers to see.

@chahmedejaz
Copy link
Collaborator Author

Thanks for the response @tschumilas. Sorry for the delay, I'm just back from my wedding vacation.

Anyhow, as per my understanding, of:

I would say this report should only include the Supplier fees.

Do we need to include only the green highlighted enterprise fees?
image

CC: @RachL , @drummer83

@chahmedejaz chahmedejaz force-pushed the task/12776-pay-suppliers-report branch from 7f150c7 to 25611fd Compare November 1, 2024 15:13
@RachL RachL force-pushed the task/12776-pay-suppliers-report branch from 7a715ea to ed76852 Compare November 15, 2024 10:09
@RachL
Copy link
Contributor

RachL commented Nov 15, 2024

I don't know why this was not merged, but I agree we can move to production and test with real-life cases now, so I've rebased and will merge with bypass.

KUDOS @chahmedejaz @drummer83 @filipefurtad0 this was a tough one

@RachL RachL merged commit db79af4 into openfoodfoundation:master Nov 15, 2024
51 checks passed
@filipefurtad0
Copy link
Contributor

I don't know why this was not merged

Forgot to click the button 😅
Thanks @RachL!! 🎉

@tschumilas
Copy link

I think we have 2 issues with this report.

Maybe this is a translation issue? But the column labelled "Total Tax ($)" is calculating the tax on just the product - column I * tax rate (.13 in this example). So I think this column should be 'Product Tax'. So is this my mislabeling in transifex?

Second issues is trickier - and maybe my mistake at the beginning. A hub collects taxes on the sale. But the hub will only payout these taxes to a supplier IF the supplier is tax registered. That is, if 'charges tax = yes' If for a given supplier, 'charges tax' = no, then NO taxes should be paid out by the hub to this supplier , so columns L and M should be blank.

So - we as a minimum, we need this report to have a column that indicates if the supplier's tax registered status. This should be the 'charges tax' status. Maybe in other places, the ACN/ABN number is this - but here in Canada, an enterprise can have a business number but not be tax registered.

If we have a 'charges tax' column (with yes/no), then the hub manager can 'do the math' and payout or not payout the taxes.
Better yet - would be if we did that for the hub manager, and left columns L & M (the tax columns) blank if supplier charges tax = no.

In the testing notes above @drummer83 noted this same issue during testing:
Test taxes (blank if supplier is not tax registered)
Not quite: Even enterprise has "charges tax = no" active, then still the tax is shown in the report, if the product has a tax applied. This is strange, but it's displayed in the same way on the order details page, so I think it's ok. ❓

Here's an output with a single supplier who does not charge tax. This is their business setting:
Settings-Ball-Tagawa-Growers-102-144-200-plug-trays-OFN-Administration-11-26-2024_10_52_AM

And here is the report output for a charges tax = 0 supplier
Screenshot 2024-11-26 105541

@RachL
Copy link
Contributor

RachL commented Nov 26, 2024

@tschumilas thank you for this detailed testing!

regarding the tax, can I clarify who is the owner of the fee in your example? I'm a bit confused why the tax on the fee is greater than the total tax 🤔

Regarding the naming, I don't think this is how we've specified it in the issue: https://docs.google.com/spreadsheets/d/1XDi3whY2h2DnHQtYS0Fbogr_VTJmYhAXzt1p9ElBBbM/edit?gid=0#gid=0

The total tax was (to my understanding) the sum of all taxes, including fees. So that total excl. tax + total tax = total.

But maybe what's missing is actually a column showing the total product tax?

@chahmedejaz
Copy link
Collaborator Author

chahmedejaz commented Nov 26, 2024

The total tax was (to my understanding) the sum of all taxes, including fees. So that total excl. tax + total tax = total.

The total tax does not include the tax on fees. Maybe that's what is missing here 😅

Moreover, as per this:

So - we as a minimum, we need this report to have a column that indicates if the supplier's tax registered status. This should be the 'charges tax' status. Maybe in other places, the ACN/ABN number is this - but here in Canada, an enterprise can have a business number but not be tax registered.

I think we need another column in the report to show the tax status of the supplier.

@tschumilas
Copy link

so if I understand - right now on the example above - 'total tax' is the tax on product, sorry I missed that. Yes that calculates. .13 (the tax rate on for this product) * 21.69 (total excluding fees and taxes ) - total tax (2.82)
Now I get it.
I'm going to make a note that this total tax figure will not add up to be the total taxes on an order (because an order will have per order fees, shipping fees and taxes on those ..., and taxes on an order will include hub fees and their taxes as well). So thats good.

And, it makes sense that total tax in this report (tax on product) can be less than total tax on fees. In the example above there are very steep per item shipping fees - so thats why. (These are supplier fees - which is why they are showing in this report - so all good there.)

As an aside - I've been thinking of trying to make a section for the user guide dedicated to understanding reports. We have a not of new ones, that are very specific. I know I'm getting the mixed up - and questions on reports is now the most common area of questioning I'm getting from users.

So yes we need a column to show tax status of the supplier. Perfect!

@RachL
Copy link
Contributor

RachL commented Nov 28, 2024

@tschumilas maybe we should have a quick call about it?

I'm thinking it would be clearer to have a column called product tax + a total tax column. so we have the full breakdown.

We can add a column indicating if the producer is tax registered, but to me, if the producer is not tax registered, then the product tax column is 0. So I think we have a bug in the example you've shared?

@tschumilas
Copy link

I agree with you @RachL and maybe we should have a call because I'm also wanting make sure this report is useful outside of Canada. But I'm not clear how hubs where taxes are included in prices issue payouts. So my thining was to have all the numbers show - even when the supplier is not tax registered - and the hub can decide which total to payout (without or with tax). It seems its more generally useable that way.

@RachL
Copy link
Contributor

RachL commented Nov 29, 2024

just a quick answer:

and the hub can decide which total to payout (without or with tax). It seems its more generally usable that way.

I don't think there is an OFN country currently that pays taxes to suppliers if they are not registered. So, the CA use case is as far as I know the general use case; So let's make it easy for our users 👍

@RachL
Copy link
Contributor

RachL commented Dec 2, 2024

@chahmedejaz I've created #13013 in order to add the columns.

Theresa has sent me on slack the fees set up in the example above, I will try to set them up on a staging server to reproduce the problem of tax columns not at 0 when producer is not tax registered and create an issue accordingly.

@chahmedejaz
Copy link
Collaborator Author

Sure, Rachel 👍🏻

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

Successfully merging this pull request may close these issues.

[Report] As an admin, I should access a new report: "Pay Suppliers"
7 participants