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

Changing a variant unit scale from items to weight/volume does not remove variant unit name #13027

Conversation

chahmedejaz
Copy link
Collaborator

@chahmedejaz chahmedejaz commented Dec 10, 2024

What? Why?

What should we test?

  • As mentioned in the issue

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 added bug-s3 The bug is stopping a critical or non-critical feature but there is a usable workaround. technical changes only These pull requests do not contain user facing changes and are grouped in release notes labels Dec 10, 2024
@chahmedejaz chahmedejaz force-pushed the bugfix/13026-reset-variant-unit-name branch from c8269a8 to 3e031ab Compare December 10, 2024 22:14
@@ -987,11 +987,11 @@

variant.variant_unit = 'weight'
variant.variant_unit_scale = 1
variant.variant_unit_name = 'g'
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think we need to remove this step as per the logic described in the issue that only variants with unit equal items have the value for variant_unit_name, otherwise it should be empty.

@@ -65,6 +65,7 @@ def update_units
def unit_value_attributes
units = { unit_presentation: option_value_name }
units.merge!(variant_unit:) if has_attribute?(:variant_unit)
units.merge!(variant_unit_name: '') if reset_variant_unit_name?
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updating with the emtpy string as per Line#123 of the spec:

it "assigning important attributes" do
expect(find_field('product_shipping_category_id').text).to eq(shipping_category.name)
select 'New supplier', from: 'product_supplier_id'
fill_in 'product_name', with: 'A new product !!!'
select "Weight (kg)", from: 'product_variant_unit_with_scale'
fill_in 'product_unit_value', with: 5
select taxon.name, from: "product_primary_taxon_id"
fill_in 'product_price', with: '19.99'
fill_in 'product_on_hand', with: 5
select 'Test Tax Category', from: 'product_tax_category_id'
fill_in_trix_editor 'product_description', with: 'A description...'
click_button 'Create'
expect(current_path).to eq spree.admin_products_path
expect(flash_message).to eq('Product "A new product !!!" has been successfully created!')
product = Spree::Product.find_by(name: 'A new product !!!')
variant = product.variants.first
expect(product.description).to eq("<div>A description...</div>")
expect(product.group_buy).to be_falsey
expect(variant.variant_unit).to eq('weight')
expect(variant.variant_unit_scale).to eq(1000)
expect(variant.unit_value).to eq(5000)
expect(variant.unit_description).to eq("")
expect(variant.variant_unit_name).to eq("")
expect(variant.primary_taxon_id).to eq(taxon.id)
expect(variant.price.to_s).to eq('19.99')
expect(variant.on_hand).to eq(5)
expect(variant.tax_category_id).to eq(tax_category.id)
expect(variant.shipping_category).to eq(shipping_category)
expect(variant.unit_presentation).to eq("5kg")
expect(variant.supplier).to eq(supplier)
end

@chahmedejaz chahmedejaz marked this pull request as ready for review December 10, 2024 22:30
@rioug rioug self-requested a review December 10, 2024 22:32
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.

Nice one 👍

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 solution 👍

@filipefurtad0 filipefurtad0 self-assigned this Dec 18, 2024
@filipefurtad0 filipefurtad0 added the pr-staged-fr staging.coopcircuits.fr label Dec 18, 2024
@filipefurtad0
Copy link
Contributor

Hey @chahmedejaz ,

Thanks for fixing this.

Before testing we can indeed verify in the DB, that editing the units from Items to Volume (or Weight) does not remove variant_unit_name:

image

After this PR, this clears this attribute:

image

Creating an items variant works as before.

I think its a good idea to test product import before merging, I'll continue at a later stage.

@RachL RachL removed the pr-staged-fr staging.coopcircuits.fr label Dec 18, 2024
@RachL
Copy link
Contributor

RachL commented Dec 18, 2024

@filipefurtad0 I'm stilling staging FR this afternoon, but I should be done when you are back online

@filipefurtad0 filipefurtad0 added the pr-staged-fr staging.coopcircuits.fr label Dec 20, 2024
@filipefurtad0
Copy link
Contributor

Ok @chahmedejaz,

Now tested product import of an variant which was changed from unit_type = item to weight.

After clearing the variant_unit_name attribute on the CSV file, it is possible to update the variant, without creating undesired new variants, as reported on #13026.

Merging, thanks!

@filipefurtad0 filipefurtad0 merged commit e2e2285 into openfoodfoundation:master Dec 20, 2024
55 checks passed
@filipefurtad0 filipefurtad0 removed the pr-staged-fr staging.coopcircuits.fr label Dec 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-s3 The bug is stopping a critical or non-critical feature but there is a usable workaround. technical changes only These pull requests do not contain user facing changes and are grouped in release notes
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Changing a variant unit scale from items to weight/volume does not remove variant unit name
5 participants