fix: add null checks for articles convert_units
Prevents division by zero exception because of a unit beeing 0.
A Unit becomes also zero e.g. when a comma symbol is used Unit.new("0,9kg") == 0
fixes #1014
This commit is contained in:
parent
45e2668cea
commit
33034e66b8
2 changed files with 13 additions and 1 deletions
|
|
@ -211,7 +211,7 @@ class Article < ApplicationRecord
|
|||
rescue StandardError
|
||||
nil
|
||||
end
|
||||
if fc_unit && supplier_unit && fc_unit =~ supplier_unit
|
||||
if fc_unit != 0 && supplier_unit != 0 && fc_unit && supplier_unit && fc_unit =~ supplier_unit
|
||||
conversion_factor = (supplier_unit / fc_unit).to_base.to_r
|
||||
new_price = new_article.price / conversion_factor
|
||||
new_unit_quantity = new_article.unit_quantity * conversion_factor
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue