allow non-shared articles to be part of a shared supplier using a blank order number

This commit is contained in:
wvengen 2014-01-24 22:10:00 +01:00
parent c5cc714f9b
commit 49e563af89
3 changed files with 10 additions and 2 deletions

View file

@ -61,7 +61,7 @@ class Article < ActiveRecord::Base
# false will returned and self.shared_updated_on will be updated
def shared_article_changed?
# skip early if the timestamp hasn't changed
unless self.shared_updated_on == self.shared_article.updated_on
unless self.shared_article.nil? or self.shared_updated_on == self.shared_article.updated_on
# try to convert units
# convert supplier's price and unit_quantity into fc-size
@ -106,6 +106,7 @@ class Article < ActiveRecord::Base
# to get the correspondent shared article
def shared_article
self.order_number.blank? and return nil
@shared_article ||= self.supplier.shared_supplier.shared_articles.find_by_number(self.order_number) rescue nil
end

View file

@ -57,7 +57,9 @@ class Supplier < ActiveRecord::Base
}
updated_articles << [article, unequal_attributes]
end
else
# Articles with no order number can be used to put non-shared articles
# in a shared supplier, with sync keeping them.
elsif not article.order_number.blank?
# article isn't in external database anymore
outlisted_articles << article
end

View file

@ -105,5 +105,10 @@ describe Article do
expect(article.unit_quantity).to eq 5
expect(article.price).to be_within(1e-3).of(shared_article.price/5)
end
it 'does not synchronise when it has no order number' do
article.update_attributes :order_number => nil
expect(supplier.sync_all).to eq [[], []]
end
end
end