Make sync work when unit has no name
(closes foodcoops#337) Conflicts: app/models/article.rb
This commit is contained in:
parent
cec5a93c82
commit
1b9b81fa75
1 changed files with 3 additions and 3 deletions
|
@ -173,9 +173,9 @@ class Article < ActiveRecord::Base
|
||||||
fc_unit = (::Unit.new(unit) rescue nil)
|
fc_unit = (::Unit.new(unit) rescue nil)
|
||||||
supplier_unit = (::Unit.new(shared_article.unit) rescue nil)
|
supplier_unit = (::Unit.new(shared_article.unit) rescue nil)
|
||||||
if fc_unit and supplier_unit and fc_unit =~ supplier_unit
|
if fc_unit and supplier_unit and fc_unit =~ supplier_unit
|
||||||
conversion_factor = (fc_unit.convert_to(supplier_unit.units) / supplier_unit).scalar
|
conversion_factor = (supplier_unit / fc_unit).to_base.to_r
|
||||||
new_price = shared_article.price * conversion_factor
|
new_price = shared_article.price / conversion_factor
|
||||||
new_unit_quantity = shared_article.unit_quantity / conversion_factor
|
new_unit_quantity = shared_article.unit_quantity * conversion_factor
|
||||||
[new_price, new_unit_quantity]
|
[new_price, new_unit_quantity]
|
||||||
else
|
else
|
||||||
false
|
false
|
||||||
|
|
Loading…
Reference in a new issue