end of day commit
This commit is contained in:
@@ -44,6 +44,12 @@ class List
|
||||
}
|
||||
}|, reduce_function: '_sum'
|
||||
|
||||
view :active_for_supplier_and_section_view, type: :custom, map_function: %[function(doc){
|
||||
if(doc.ruby_class == 'List' && doc.state == 'active'){
|
||||
emit([doc.supplier_id, doc.section_id], 1);
|
||||
}
|
||||
}], reduce_function: '_sum'
|
||||
|
||||
view :for_user_view, type: :custom, map_function: %|function(doc){
|
||||
if(doc.ruby_class == 'List' && doc.user_ids && doc.user_ids.length){
|
||||
doc.user_ids.forEach(function(uid){
|
||||
@@ -77,6 +83,11 @@ class List
|
||||
database.view(active_by_section_id_view(key: section_id, reduce: false, include_docs: true))
|
||||
end
|
||||
|
||||
# Return all currently active orders for a given section
|
||||
def self.active_for_supplier_and_section(supplier, section_id, options = {})
|
||||
database.view(active_for_supplier_and_section_view(key: [supplier.id, section_id], reduce: false, include_docs: true))
|
||||
end
|
||||
|
||||
def self.active_for_table(table_id, options = {})
|
||||
database.view(active_by_table_id_view(options.reverse_merge(key: table_id, reduce: false, include_docs: true)))
|
||||
end
|
||||
|
||||
@@ -15,6 +15,7 @@ class Product
|
||||
validates :name, presence: true
|
||||
validates :supplier_id, presence: true
|
||||
validates :price, presence: true, numericality: true
|
||||
view :by_supplier_id_and_id, key: [:supplier_id, :_id]
|
||||
|
||||
after_save :persist_product_category_ids
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ class Supplier
|
||||
|
||||
def active_lists(options = {})
|
||||
return @active_lists if @active_lists.present?
|
||||
@active_lists = List.active_for_supplier(id)
|
||||
@active_lists = options[:section_id].present? ? List.active_for_supplier_and_section(self, options[:section_id]) : List.active_for_supplier(id)
|
||||
@active_lists.include_relations(table: :section, orders: {product_orders: :product})
|
||||
@active_lists
|
||||
end
|
||||
|
||||
@@ -14,6 +14,7 @@ class Table
|
||||
validates :supplier_id, presence: true
|
||||
#validates :list_id, presence: true
|
||||
validates :number, numericality: {greater_than: 0}
|
||||
view :by_supplier_id_and_id, key: [:supplier_id, :_id]
|
||||
|
||||
#validates_uniqueness_of :number
|
||||
#view :by_number, key: :number # For uniqueness validation
|
||||
|
||||
Reference in New Issue
Block a user