rounding decimal to print_settings precision

This commit is contained in:
Thein Lin Kyaw
2019-11-06 17:34:42 +06:30
parent 33670b450e
commit 155cb0a9eb
11 changed files with 467 additions and 802 deletions

View File

@@ -5,6 +5,8 @@ class SaleTax < ApplicationRecord
before_create :generate_custom_id
belongs_to :sale
before_validation :round_to_precision
def self.sync_sale_tax_records(sale_taxes)
if !sale_taxes.nil?
sale_taxes.each do |t|
@@ -38,4 +40,13 @@ class SaleTax < ApplicationRecord
self.sale_tax_id = SeedGenerator.generate_id(self.class.name, "STI")
end
end
def round_to_precision
if self.tax_payable_amount != self.tax_payable_amount_was
if self.tax_payable_amount % 1 > 0
precision = PrintSetting.get_precision_delimiter().precision.to_i
self.tax_payable_amount = self.tax_payable_amount.round(precision)
end
end
end
end