diff --git a/app/models/price_detail.rb b/app/models/price_detail.rb
index d6a7038..f24fc58 100644
--- a/app/models/price_detail.rb
+++ b/app/models/price_detail.rb
@@ -4,11 +4,11 @@ class PriceDetail < ActiveRecord::Base
validates_presence_of :product_id
belongs_to :production_cost
- validates_presence_of :production_cost
+ # Do not validates_presence_of production_cost. We may have undefined other costs.
validates_uniqueness_of :production_cost_id, :scope => :product_id
def name
- production_cost.name
+ production_cost.nil? ? _('other costs') : production_cost.name
end
def price
diff --git a/app/models/product.rb b/app/models/product.rb
index 4c6bdee..d2f0606 100644
--- a/app/models/product.rb
+++ b/app/models/product.rb
@@ -191,11 +191,13 @@ class Product < ActiveRecord::Base
(price - total_production_cost.to_f).zero?
end
- def update_price_details(price_details)
- self.price_details.destroy_all
- price_details.each do |price_detail|
- self.price_details.create(price_detail)
+ def update_price_details(new_price_details)
+ price_details.destroy_all
+ new_price_details.each do |detail|
+ price_details.create(detail)
end
+ reload # to remove temporary duplicated price_details
+ price_details
end
def price_description_percentage
diff --git a/app/views/manage_products/_display_price_details.rhtml b/app/views/manage_products/_display_price_details.rhtml
index a65b18b..47f81c6 100644
--- a/app/views/manage_products/_display_price_details.rhtml
+++ b/app/views/manage_products/_display_price_details.rhtml
@@ -10,7 +10,7 @@
<% @product.price_details.each do |price_detail| %>
<%= select_production_cost(@product, price_detail.production_cost_id) %> |
- <%= labelled_form_field(environment.currency_unit, text_field_tag('price_details[][price]', price_detail.formatted_value(:price), :class => 'numbers-only price-details-price')) %> |
+ <%= labelled_form_field(environment.currency_unit, text_field_tag('price_details[][price]', price_detail.formatted_value(:price), :class => 'numbers-only price-details-price', :size => 6)) %> |
<%= link_to_remote(_('Remove'),
:update => "price-detail-#{price_detail.id}",
diff --git a/app/views/manage_products/_manage_product_details.rhtml b/app/views/manage_products/_manage_product_details.rhtml
index a588e9d..de7bdfb 100644
--- a/app/views/manage_products/_manage_product_details.rhtml
+++ b/app/views/manage_products/_manage_product_details.rhtml
@@ -34,7 +34,7 @@
<%= select_production_cost(@product) %> |
- <%= labelled_form_field(environment.currency_unit, text_field_tag('price_details[][price]', nil, :class => 'numbers-only price-details-price')) %> |
+ <%= labelled_form_field(environment.currency_unit, text_field_tag('price_details[][price]', nil, :class => 'numbers-only price-details-price', :size => 6)) %> |
<%= link_to(_('Cancel'), '#', {:class => 'cancel-new-cost'}) %> |
diff --git a/public/javascripts/manage-products.js b/public/javascripts/manage-products.js
index 9b16c03..919af6b 100644
--- a/public/javascripts/manage-products.js
+++ b/public/javascripts/manage-products.js
@@ -23,13 +23,24 @@
return false;
});
- $("#manage-product-details-form").live('submit', function(data) {
+ $('#manage-product-details-form').live('submit', function(data) {
var form = this;
$(form).find('.loading-area').addClass('small-loading');
$(form).css('cursor', 'progress');
- $.post(form.action, $(form).serialize(), function(data) {
- $("#display-manage-price-details").html(data);
- $("#manage-product-details-button").show();
+ var request = $.ajax(form.action, {
+ type: 'POST',
+ dataType: 'html',
+ data: $(form).serialize()
+ });
+ request.done(function(data, textStatus, jqXHR) {
+ $('#display-manage-price-details').html(data);
+ $('#manage-product-details-button').show();
+ });
+ request.fail(function(jqXHR, textStatus, errorThrown) {
+ log.error('manage_product_details', 'Request failed', errorThrown);
+ alert('manage_product_details\nRequest failed: '+ errorThrown +
+ '\n\nPlease, contact the site administrator.');
+ $('#display-manage-price-details .loading-area').hide();
});
if ($('#progressbar-icon').hasClass('ui-icon-check')) {
display_notice($('#progressbar-icon').attr('data-price-described-notice'));
diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css
index a009fe5..07d075b 100644
--- a/public/stylesheets/application.css
+++ b/public/stylesheets/application.css
@@ -3003,6 +3003,10 @@ div#activation_enterprise label, div#activation_enterprise input, div#activation
display: inline-block;
}
+#manage-product-details-form .formfieldline {
+ white-space: nowrap;
+}
+
#manage-product-details-form .formlabel,
#manage-product-details-form .formfield {
display: inline-block;
diff --git a/test/unit/price_detail_test.rb b/test/unit/price_detail_test.rb
index 81ee5d8..6920c06 100644
--- a/test/unit/price_detail_test.rb
+++ b/test/unit/price_detail_test.rb
@@ -50,14 +50,14 @@ class PriceDetailTest < ActiveSupport::TestCase
assert_equal cost, PriceDetail.find(detail.id).production_cost
end
- should 'production cost be mandatory' do
- p = PriceDetail.new
- p.valid?
-
- assert p.errors.invalid?(:production_cost)
+ should 'production cost not be mandatory' do
+ product = fast_create(Product)
+ price = PriceDetail.new :product=>product
+ price.valid?
+ assert price.errors.empty?
end
- should 'th production cost be unique on scope of product' do
+ should 'the production cost be unique on scope of product' do
product = fast_create(Product)
cost = fast_create(ProductionCost, :owner_id => Environment.default.id, :owner_type => 'environment')
--
libgit2 0.21.2 |