solidus icon indicating copy to clipboard operation
solidus copied to clipboard

Prevent hard-errors when VatPriceGenerator is invoked without a defau…

Open firemind opened this issue 2 years ago • 2 comments

Guard against exceptions when calling Price#net_amount without a price.

Skip trying to calculate foreign prices in VatPriceGenerator when the default_price does not have an amount set.

Because the VatPriceGenerator is invoked in a before_validate hook when creating a product, this can lead to exceptions when an admin tries to create a product without specifying a price (and there are non-default countries for which a price needs to be calculated).

This PR allows the validations to run without raising exceptions so the admin can see the validation errors.

firemind avatar Aug 09 '23 13:08 firemind

Codecov Report

Merging #5324 (94820f8) into v3.4 (3ef8231) will increase coverage by 0.00%. The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             v3.4    #5324   +/-   ##
=======================================
  Coverage   86.64%   86.64%           
=======================================
  Files         580      580           
  Lines       14741    14743    +2     
=======================================
+ Hits        12772    12774    +2     
  Misses       1969     1969           
Files Changed Coverage Δ
core/app/models/spree/price.rb 97.72% <100.00%> (+0.05%) :arrow_up:
...re/app/models/spree/variant/vat_price_generator.rb 100.00% <100.00%> (ø)

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

codecov[bot] avatar Aug 09 '23 14:08 codecov[bot]

I labeled the PR as a breaking change, as it's changing a behavior some people could be relying on. It'll be merged in the next major.

waiting-for-dev avatar Aug 10 '23 03:08 waiting-for-dev