Skip to content

OBPIH-6499 [backend] Calculate inverse items#4779

Merged
awalkowiak merged 6 commits intofeature/OBPIH-6398-partial-invoices-for-prepaid-pofrom
OBPIH-6499
Aug 19, 2024
Merged

OBPIH-6499 [backend] Calculate inverse items#4779
awalkowiak merged 6 commits intofeature/OBPIH-6398-partial-invoices-for-prepaid-pofrom
OBPIH-6499

Conversation

@alannadolny
Copy link
Collaborator

Because I am going ooo, I am pushing my branch with the next steps:
Inverse items are created during the creation of regular, but relations are missing, so:
Check if adding relations (to shipment items etc.) to inverse items will break logic, if so, check how to avoid that, or do it another way. We have to add those relations because some data is missing while displaying invoice items on React pages. After fixing the missing data, inverse the quantity (should be a simple change in calculation + remember about prepaid / 50, etc.)

@alannadolny alannadolny added the warn: do not merge Marks a pull request that is not yet ready to be merged label Aug 6, 2024
@alannadolny alannadolny self-assigned this Aug 6, 2024
@github-actions github-actions bot added domain: backend Changes or discussions relating to the backend server flag: schema change Hilights a pull request that contains a change to the database schema labels Aug 6, 2024
@alannadolny alannadolny marked this pull request as draft August 6, 2024 15:37
@awalkowiak awalkowiak added the status: work in progress For issues or pull requests that are in progress but not yet completed label Aug 6, 2024
@awalkowiak
Copy link
Collaborator

I will be taking over this one

@awalkowiak awalkowiak self-assigned this Aug 7, 2024
@github-actions github-actions bot added the domain: frontend Changes or discussions relating to the frontend UI label Aug 12, 2024
@awalkowiak awalkowiak marked this pull request as ready for review August 13, 2024 15:06
@awalkowiak awalkowiak removed status: work in progress For issues or pull requests that are in progress but not yet completed warn: do not merge Marks a pull request that is not yet ready to be merged labels Aug 13, 2024
@awalkowiak awalkowiak changed the base branch from develop to feature/OBPIH-6398-partial-invoices-for-prepaid-po August 13, 2024 15:20

String id
Invoice invoice
InvoiceItemType invoiceItemType
Copy link
Collaborator

Choose a reason for hiding this comment

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

@jmiranda let me know if you prefer this one as a separate InvoiceItemType domain that has name and code as InvoiceItemTypeCode enum instead straight away using enum here, and I'll adjust that

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, now that I'm seeing how it's being used, I don't think InvoiceItemType is correct. An invoice item type would describe what the invoice item is for i.e. product, service, adjustment, subscription, labor, tax, discount, fees, etc.

What we're talking about here is something I still don't really understand. But it feels like it might be the invoice type (prepayment, standard, final) and should go at the Invoice level.

This is why I wish we had done the "from scratch" design instead of trying to build on what we had (at least from the data model perspective) so that we could have spent more time thinking about the proper way to do this. Frankly, I don't have a good enough understanding of it so I guess I'll leave it up to you. But I would really consider moving this "type" to the invoice and derive the "inverse" logic based on, I guess whether the item is in an invoice with InvoiceTypeCode.FINAL (and whatever other)

In either case, the safer option would be to use the enum here since we could always migrate to using a type domain that maps to the enum later.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@jmiranda replied in the other comment

return invoiceItem
}

InvoiceItem createFromOrderItem(OrderItem orderItem) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If anyone wonders, I moved these to PrepaymntInvoiceService


enum InvoiceItemType {

INVERSE('Inverse'),
Copy link
Collaborator

Choose a reason for hiding this comment

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

@jmiranda Let me know if other types come to your mind you'd like to have added here

Copy link
Member

Choose a reason for hiding this comment

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

If we added InvoiceTypeCode.FINAL, could the INVERSEness of an item be derived? I assume that the other two (prepayment, regular) could already be derived from the InvoiceType. So even if there's a need to store whether an invoice item is an "inverse" item, we could do so with just a boolean field.

Side note: If/when you add REGULAR InvoiceTypeCode it should be called STANDARD.

Source: https://www.freshbooks.com/hub/invoicing/types-of-invoices

Copy link
Collaborator

Choose a reason for hiding this comment

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

@jmiranda Yeah, to be honest, this part was not designed properly, because we wanted to go with calculating all the time and we switched to keeping inverse items on the final invoice right before we started the development. So something that was my suggested direction in case we want to go with storing inverse items somehow was cemented in my brain as the version we want to do. As deriving item type from invoice type does not work for me here (due to mixing both standard/regular items with inverse items), I decided that the boolean fits here more, and this is what I implemented for now (we can still revise it again in the final feature PR).

@awalkowiak
Copy link
Collaborator

@ewaterman I replied (and made change requests) to your comments, but don't be mad at me for resolving conversations, I just kept track of resolved requests with this.

String type

String toString() {
return name()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return name()
return type

Either that or I'd just remove the type field entirely since it's not being used anywhere but ultimately it's not a big deal.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@ewaterman i replaced InvoiceItemType with inverse boolean

@alannadolny
Copy link
Collaborator Author

LGTM, but I can't approve this PR because I created it 😄

@awalkowiak awalkowiak merged commit 6ccd001 into feature/OBPIH-6398-partial-invoices-for-prepaid-po Aug 19, 2024
@awalkowiak awalkowiak deleted the OBPIH-6499 branch August 19, 2024 13:32
awalkowiak added a commit that referenced this pull request Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain: backend Changes or discussions relating to the backend server domain: frontend Changes or discussions relating to the frontend UI flag: schema change Hilights a pull request that contains a change to the database schema

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants