Sha256: c7adbf5b51016a6ca59d3c7744b17ae97f231ae24e3c3622d6595274fe311558
Contents?: true
Size: 691 Bytes
Versions: 92
Compression:
Stored size: 691 Bytes
Contents
module Comee module Core class InvoiceItem < ApplicationRecord before_save { self.total_price = unit_price * quantity } after_save :update_invoice_total belongs_to :sales_order_item belongs_to :invoice validates :quantity, :unit_price, presence: true, numericality: {greater_than: 0} validates :total_price, numericality: {greater_than_or_equal_to: 0, allow_nil: true} delegate(:product_code, to: :sales_order_item) delegate(:product_name, to: :sales_order_item) def update_invoice_total invoice.total_price = InvoiceItem.where(invoice: invoice).map(&:total_price).sum invoice.save! end end end end
Version data entries
92 entries across 92 versions & 1 rubygems