diff --git a/app/controllers/articles_controller.rb b/app/controllers/articles_controller.rb index c9dd1362..3c3de22a 100644 --- a/app/controllers/articles_controller.rb +++ b/app/controllers/articles_controller.rb @@ -227,6 +227,7 @@ class ArticlesController < ApplicationController if @updated_articles.empty? && @outlisted_articles.empty? redirect_to supplier_articles_path(@supplier), :notice => I18n.t('articles.controller.sync.notice') end + @ignored_article_count = @supplier.articles.where(order_number: [nil, '']).count end # Updates, deletes articles when sync form is submitted diff --git a/app/models/article.rb b/app/models/article.rb index 82fc0b1f..3132f5d0 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -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 diff --git a/app/models/supplier.rb b/app/models/supplier.rb index 0dba2a1e..838c9607 100644 --- a/app/models/supplier.rb +++ b/app/models/supplier.rb @@ -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 diff --git a/app/views/articles/sync.html.haml b/app/views/articles/sync.html.haml index 7a990413..a65878f1 100644 --- a/app/views/articles/sync.html.haml +++ b/app/views/articles/sync.html.haml @@ -14,6 +14,8 @@ .alert= t '.outlist.alert_used', article: article.name - else %i= t '.outlist.body_skip' + - if @ignored_article_count > 0 + %i= t '.outlist.body_ignored', count: @ignored_article_count %hr/ %h2= t '.update.title' %p diff --git a/config/locales/en.yml b/config/locales/en.yml index 54a409a9..7403cbaf 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -377,6 +377,9 @@ en: outlist: alert_used: Warning, %{article} is used in an open order. Please remove it from the order first. body: ! 'The following articles were removed from the list and will be deleted:' + body_ignored: + one: One article without order number was skipped. + other: ! '%{count} articles without order number were skipped.' body_skip: No articles to delete. title: Remove from list ... price_short: Price diff --git a/spec/models/article_spec.rb b/spec/models/article_spec.rb index bd0d991c..0f63b88e 100644 --- a/spec/models/article_spec.rb +++ b/spec/models/article_spec.rb @@ -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