module Comee module Core class AdditionalItem < ApplicationRecord before_save { self.total_price = unit_price * quantity } after_save :update_invoice after_destroy :update_invoice belongs_to :invoice validates :description, presence: true validates :quantity, :unit_price, presence: true, numericality: {greater_than: 0} def update_invoice invoice.calculate_total_price invoice.calculate_vat invoice.save! end end end end