Sha256: 792700787fa313d1295475c05a6788cad779903caa67cc0472a230851aec9a6d
Contents?: true
Size: 597 Bytes
Versions: 23
Compression:
Stored size: 597 Bytes
Contents
module Comee module Core class InvoiceItem < ApplicationRecord before_save { self.total_price = unit_price * quantity } after_save :update_invoice_price belongs_to :shipment_instruction_item belongs_to :invoice belongs_to :unit validates :quantity, :unit_price, presence: true, numericality: {greater_than: 0} validates :total_price, numericality: {greater_than_or_equal_to: 0, allow_nil: true} def update_invoice_price invoice.total_price = invoice.invoice_items.sum(:total_price) invoice.save! end end end end
Version data entries
23 entries across 23 versions & 1 rubygems