seed generator model name

This commit is contained in:
Thein Lin Kyaw
2020-09-01 12:52:04 +06:30
parent d4d27dfc1e
commit f8b56cf48a

View File

@@ -1,9 +1,6 @@
class SeedGenerator < ApplicationRecord
# Generate ID for Tables
def self.generate_id(model, prefix)
# model_name = self.get_model_name(model)
model_name = model
prefix ||= ''
prefix << '-' if prefix.present?
@@ -17,15 +14,12 @@ class SeedGenerator < ApplicationRecord
prefix << shop.shop_code
end
seed = self.update_seed(model_name)
seed = self.update_seed(model)
length = 16 - prefix.length
prefix + seed.to_s.rjust(length, '0')
end
def self.generate_ids(model, prefix, count = 1)
# model_name = self.get_model_name(model)
model_name = model
prefix ||= ''
prefix << '-' if prefix.present?
@@ -39,7 +33,7 @@ class SeedGenerator < ApplicationRecord
prefix << shop.shop_code
end
start = self.update_seed(model_name, count)
start = self.update_seed(model, count)
stop = start + count - 1
length = 16 - prefix.length
(start..stop).map { |c| prefix + c.to_s.rjust(length, '0') }
@@ -129,7 +123,8 @@ class SeedGenerator < ApplicationRecord
def self.update_seed(model, count = 1)
SeedGenerator.transaction do
seed = SeedGenerator.lock.find_by_model(model)
seed = SeedGenerator.lock.find_by_model(get_model_name(model)) ||
SeedGenerator.lock.find_by_model(model)
seed.next = seed.next + (count * seed.increase_by)
seed.current = seed.next - seed.increase_by
seed.save!