-
-
Notifications
You must be signed in to change notification settings - Fork 729
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][PI] Make Product Import create stock items (1 broken spec) #2783
Comments
104) ProductImport::ProductImporter updating various fields saves and updates
Failure/Error: expect(beetroot.on_demand).to_not eq true
expected: value != true
got: true
(compared using ==)
Diff:
# ./spec/models/product_importer_spec.rb:312:in `block (3 levels) in <top (required)>' |
the description is a bit outdated now because we have since then agreed that we will not play with stock items but instead use the variant_stock facade to handle these cases. done in #3355 |
the only case where this is still a problem is the only broken spec after #3355: In this spec, we test entry_processor.assign_defaults where we set the defaults. Lets use this issue to represent this broken spec, ok? |
the build error for this broken spec:
|
I think we are hitting a design flaw within product import here and may need to refactor some parts first. Wrong assumptionProduct import assumes that columns in the spreadsheet correlate to attributes on products, variants or inventory items. This is not the case in Spree 2. For example, products and variants don't have if object.public_send(attribute).blank? ||
((attribute == 'on_hand' || attribute == 'count_on_hand') &&
entry.on_hand_nil)
object.assign_attributes(attribute => setting['value'])
end def check_on_hand_nil(entry, object)
return if entry.on_hand.present?
object.on_hand = 0 if object.respond_to?(:on_hand)
object.count_on_hand = 0 if object.respond_to?(:count_on_hand)
entry.on_hand_nil = true
end Other code smellProduct import uses a class def save_to_product_list(entry)
save_new_product entry if entry.validates_as? 'new_product'
if entry.validates_as? 'new_variant'
save_variant entry
@variants_created += 1
end
return unless entry.validates_as? 'existing_variant'
# ...
end ProposalWe create new classes for the five different entry types.
They could be named like
Most of those may be private and the only methods called by the processor are |
Hey @mkllnk yes, I totally agree with the problem and I like the solution. Having said that, I dont think this is strictly needed now, I think it's tech debt that we don't necessarily need to pay now (my opinion). We can add one more branch now and get the upgrade done. The main reason I say this about this task is that ProductImport (although it has a few OO flaws, this is just one) is far from being core to OFN and we should invest quality refactoring time on core parts of the system, that's where it will pay off really quickly. For this reason I'd create a tech debt issue that is lower in priority than for example both openfoodfoundation/wishlist#334 and #2763 |
I totally agree. This is where I miss Java, too. In Ruby we don't have typed variables and therefore no support of interfaces. We only have unit tests to verify it something adheres to an interface. I also share your opinion about the priority since I found a quick hacky solution in #3425. I created a new tech-debt issue: openfoodfoundation/wishlist#368. |
I had that same concern when I first looked at PI's code being familiar with v2 data model. I do agree that if we can fix PI in v2 with too much hassle we can focus on other more core things. However, I'm of the opinion that when implementing new requirements to any existing code devs should take a first refactoring step to adapt the existing design to fit the new needs. This makes refactorings well scoped and quick and make subsequent requirements easy to implement. In this case, I'd have done that the first time we touched PI in v2. Just a first small refactor. But that's just my experience and opinion. |
Agree @sauloperez we could have done the refactor and this refactor move is very important as it will clarify PI a lot. I am just not sure about the size. I think it's a M and that's why I think we should skip it for now. In the last 6 months for the spree upgrade, I think I have 20 examples (PRs) where I could have done a lot more refactoring. Choosing the refactoring path means delaying delivery, in the spree upgrade case, I could easily take another 6 months just for refactoring! Taking this path of not refactoring is true tech debt in my opinion, true tech debt is deliberate. "We must ship now I deal with the consequences" https://martinfowler.com/bliki/TechnicalDebtQuadrant.html |
Yes, I also agree. It's been reeeeeaaaally hard for me to be pragmatic and refrain myself from refactoring and cleaning things up within the upgrade. I'm sure you've noticed |
yes, it's very hard but the bright side is that we do see how to improve it and we are slowly improving the code base. |
Description
In Product Import spreadsheet entries map directly to product, variant and variant override records. That is, an entry can become any of these entities in our DB.
With Spree 2.0 this gets more complex and
variant.count_on_hand
becomesvariant.stock_items.first.count_on_hand
. It can't be longer assumed thatentry.attributes == variant.attributes
(or product or variant override).The text was updated successfully, but these errors were encountered: