From a6393a5140a7b85a7f8b79174389c7e8de22f34d Mon Sep 17 00:00:00 2001 From: phyusin Date: Tue, 16 Oct 2018 17:38:33 +0630 Subject: [PATCH] seed generator fun: --- app/models/sale.rb | 11 +++++++---- app/models/seed_generator.rb | 3 +-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/models/sale.rb b/app/models/sale.rb index eab54645..a2a3263a 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -536,10 +536,13 @@ class Sale < ApplicationRecord shop = Shop.first #if tax is not apply create new record - SaleTax.where("sale_id='#{self.sale_id}'").find_each do |existing_tax| - #delete existing and create new - existing_tax.delete - end + # SaleTax.where("sale_id='#{self.sale_id}'").find_each do |existing_tax| + # #delete existing and create new + # existing_tax.delete + # end + + taxes = SaleTax.where("sale_id='#{self.sale_id}'").pluck(:sale_tax_id) + SaleTax.where("sale_tax_id IN (?)", taxes).destroy_all total_tax_amount = 0 tax_incl_exec = "exclusive" diff --git a/app/models/seed_generator.rb b/app/models/seed_generator.rb index 97f2083f..690a2c53 100755 --- a/app/models/seed_generator.rb +++ b/app/models/seed_generator.rb @@ -21,7 +21,6 @@ class SeedGenerator < ApplicationRecord seed.model = "sale" new_receipt_no = seed.next seed.save - else current_no = seed.next seed.next = seed.next @@ -85,7 +84,7 @@ class SeedGenerator < ApplicationRecord current = 0 nex = 0 - update_sql = "UPDATE seed_generators set current = current + 1, next = next + 1 WHERE model='#{model}';" + update_sql = "UPDATE seed_generators set current = next, next = next + 1 WHERE model='#{model}';" select_sql = "select * from seed_generators where model='#{model}';" update_result = ActiveRecord::Base.connection.execute(update_sql);