OBPIH-6497 [backend] Determine encumbered and invoiceable items or adjustments#4772
OBPIH-6497 [backend] Determine encumbered and invoiceable items or adjustments#4772awalkowiak merged 8 commits intodevelopfrom
Conversation
| Boolean getIsEncumbered() { | ||
| return !isInvoiced && hasPrepaymentInvoice | ||
| } | ||
|
|
There was a problem hiding this comment.
I know we've done that in some places, but I don't like the naming like getIs.
Booleans should be named as isSomething.
Moreover, those don't have to be marked transients anymore, so you could just have a method isInvoicable().
There was a problem hiding this comment.
Yeah, but the naming convention with get, allows us to use the .getIsEncumbered() in this way: .isEncumbered, so I prefer this groovy syntactic sugar
There was a problem hiding this comment.
I don't see anything bad in using .isEncumbered() vs forcing to access a property via the field name (isEncumbered). I feel like naming booleans using getIs, getHas is an anti-pattern we should avoid.
https://rules.sonarsource.com/java/tag/convention/RSPEC-2047/
There was a problem hiding this comment.
This is groovy, not Java 😄
The rule that you send is another case. They say that we should use hasBar, not getBar
There was a problem hiding this comment.
yeah, and why should we use getBar for a boolean field?
There was a problem hiding this comment.
not getBar, but getIsBar, and then we can use it isBar
There was a problem hiding this comment.
I will repeat it again, and you will do whatever you want - getIs feels like antipattern, and I don't see anything wrong in using isBar() in this case.
There was a problem hiding this comment.
I'm used to seeing fields like:
invoiceable
encumbered
with getters and setters like
isInvoiceable
setInvoiceable
isEncumbered
setEncumbered
From the groovy docs: https://groovy-lang.org/objectorientation.html#_property_naming_conventions
...generated getters and setters will have a name formed by capitalizing the property name and adding a get or set prefix (or optionally "is" for a boolean getter)... isEmpty might be the getter method name for a property named empty.
So with that setup in Groovy we could do boolean isOrderInvoiceable = order.isInvoiceable() as Kacper says. That's my personal preference but if you disagree Alan feel free to do as you wish.
There was a problem hiding this comment.
Java beans use the same convention.
So since we keep having this conversation
... let's just use the java/groovy convention from now one.
So no more "is" prefix in the property name.
Aside: All I really care about is that I want to use Groovy's implicit getter method
if (order.invoiceable)
over the explicit getter methods
if(order.getInvoiceable())
or
if(order.isInvoiceable())
There was a problem hiding this comment.
The problem with getIs is that the property itself would be named with the is prefix, e.g. isInvoiceable instead of invoiceable.
https://stackoverflow.com/a/5322730
Your field should not be called isCurrent in the first place. Is is a verb and verbs are inappropriate to represent an Object's state. Use an adjective instead, and suddenly your getter / setter names will make more sense:
|
|
||
| Boolean getHasNotInvoicedAdjustment() { | ||
| return orderAdjustments.any { !it.isInvoiced } | ||
| } |
| return !hasInvoice && isPrepaymentRequired && hasActiveItemsOrAdjustments | ||
| } | ||
|
|
||
| /* |
There was a problem hiding this comment.
I think you need javadocs to start with /** (two asterisks) to have them work correctly in IDEs and other tools. Good job with the documentation here though!
awalkowiak
left a comment
There was a problem hiding this comment.
First comment is a request change, second one is just a question
| } | ||
|
|
||
| return orderItems.any { | ||
| it.hasNotInvoicedAdjustment || // condition related to first point |
There was a problem hiding this comment.
What if the order adjustment is not tied to any order item? This is possible too
| } | ||
|
|
||
| Boolean getIsEncumbered() { | ||
| return !isInvoiced && hasPrepaymentInvoice |
There was a problem hiding this comment.
Should this be also order.isPlaced() to be considered encumbered or not?
| Set<OrderItem> orderItems = [ | ||
| Mock(OrderItem), | ||
| orderItem, | ||
| Mock(OrderItem) |
There was a problem hiding this comment.
what do these mock order items give us?
There was a problem hiding this comment.
I added those mocked order items, because we have to have at least one order item fulfilling the tested case, so I am testing if one item of those three matches the tested condition.
There was a problem hiding this comment.
I guess my question was more what kind of values do these mocks return? Do they have quantity 0?
| hasPrepaymentInvoice | orderItemStatusCode | isEncumbered || canGenerateInvoice | ||
| false | OrderItemStatusCode.CANCELED | false || false | ||
| true | OrderItemStatusCode.CANCELED | false || false | ||
| true | OrderItemStatusCode.PENDING | true || false |
There was a problem hiding this comment.
what about testing the scenario where Order.stats == PLACED? then you would be able to generate an invoice right?
There was a problem hiding this comment.
Order status cannot be placed. The available options are:
[PENDING, COMPLETED, CANCELED, BACKORDER]
There was a problem hiding this comment.
that's OrderItemStatusCode right? I meant OrderStatus
| where: | ||
| hasPrepaymentInvoice || canGenerateInvoice | ||
| false || false | ||
| true || false |
There was a problem hiding this comment.
shouldn't this condition return true? You have an un-invoiced adjustment that has no associated order items
There was a problem hiding this comment.
that's interesting, why this test doesn't fail
There was a problem hiding this comment.
Oh, got the reason, I didn't take order status into account (orderAdjustment.isInvoiceable takes into account the fact if order is placed)
| /** | ||
| Should return true if at least one PO item is invoiceable. | ||
| A PO item is invoiceable if the order has a prepayment invoice and at least one of those requirements are fulfilled: | ||
| 1. There is an order adjustment on that item that hasn’t already been invoiced |
There was a problem hiding this comment.
I think the first point is misleading.
What is an invoiceable item?
a shipped item or a placed adjustment; any placed adjustment is pulled as invoiceable on the partial final invoice generated (but it can be removed or edited) or a canceled line
Order adjustment should be invoiceable if the order has a prepayment invoice and is placed.
Order item should be invoiceable if it has prepayment invoice and:
- is partially shipped (only this partial quantity not yet invoiced is invoiceable)
- items canceled that are not yet invoiced
Imho there is no need to check in order item is invoiceable if it has NotInvoicedAdjustment, I think the order adjustments should be separated from order items and checked as it is written above.
(to be confirmed)
No description provided.