rounding decimal to print_settings precision
This commit is contained in:
@@ -11,6 +11,7 @@ class SaleItem < ApplicationRecord
|
||||
def compute_item
|
||||
end
|
||||
|
||||
before_validation :round_to_precision
|
||||
after_update :update_stock_journal
|
||||
|
||||
# Add Sale Items
|
||||
@@ -231,6 +232,24 @@ class SaleItem < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def round_to_precision
|
||||
unit_price_fraction = self.unit_price % 1
|
||||
price_fraction = self.unit_price % 1
|
||||
# is_dining_charge = self.menu_category_code == 'DingingCharge'
|
||||
|
||||
if self.unit_price != self.unit_price_was || self.price != self.price_was
|
||||
if unit_price_fraction > 0 || price_fraction > 0
|
||||
if ['Discount', 'promotion'].include?(self.status)
|
||||
precision = PrintSetting.get_precision_delimiter().precision.to_i
|
||||
|
||||
self.unit_price = self.unit_price.round(precision)
|
||||
self.price = (self.unit_price * self.qty).round(precision)
|
||||
self.taxable_price = self.price
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def update_stock_journal
|
||||
is_void = self.status == "void" && self.status_before_last_save != "void"
|
||||
cancel_void = self.status_before_last_save == "void" && self.status.nil?
|
||||
|
||||
Reference in New Issue
Block a user