Fixed deletion of quantity formula
This commit is contained in:
parent
008cfdcd26
commit
ba634eb516
@ -113,9 +113,11 @@ class QuantitiesController < ApplicationController
|
|||||||
:description,
|
:description,
|
||||||
formula_attributes:
|
formula_attributes:
|
||||||
[
|
[
|
||||||
|
:id,
|
||||||
:code,
|
:code,
|
||||||
:zero_nil,
|
:zero_nil,
|
||||||
:unit_id
|
:unit_id,
|
||||||
|
:_destroy
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
@ -14,7 +14,10 @@ class Quantity < ActiveRecord::Base
|
|||||||
|
|
||||||
has_one :formula, inverse_of: :quantity, dependent: :destroy, validate: true
|
has_one :formula, inverse_of: :quantity, dependent: :destroy, validate: true
|
||||||
accepts_nested_attributes_for :formula, allow_destroy: true,
|
accepts_nested_attributes_for :formula, allow_destroy: true,
|
||||||
reject_if: proc { |attrs| attrs['code'].blank? }
|
reject_if: proc { |attrs| attrs['id'].blank? && attrs['code'].blank? }
|
||||||
|
before_validation do
|
||||||
|
formula.mark_for_destruction if formula.present? && formula.code.blank?
|
||||||
|
end
|
||||||
|
|
||||||
validates :name, presence: true
|
validates :name, presence: true
|
||||||
# Quantity :name uniqueness relaxed to formulas unambiguity
|
# Quantity :name uniqueness relaxed to formulas unambiguity
|
||||||
|
Reference in New Issue
Block a user