Sha256: aabea7cf61440b7ca583720a749a64b7264d1642cc2e4d50905589bf76d33ab8
Contents?: true
Size: 1.27 KB
Versions: 36
Compression:
Stored size: 1.27 KB
Contents
module Comee module Core class PurchaseOrder < ApplicationRecord before_validation :generate_po_number, if: proc { |po| po.po_number.nil? } before_save :total_price, :set_terms belongs_to :supplier has_many :purchase_order_items validates :po_number, uniqueness: true validates :order_date, :delivery_address, :status, :delivery_date, presence: true enum status: { draft: 0, submitted: 1, approved: 2, confirmed: 3, accepted: 4, canceled: 5 } def total_price items = PurchaseOrderItem.where(purchase_order_id: id) self.total_price = items.sum(&:total_price) end def self.ransackable_attributes(_auth_object = nil) %w[ id po_number supplier_id unit_id order_date status delivery_address delivery_date order_reference ] end def generate_po_number self.po_number = Util.generate_number("PurchaseOrder", "po_number") end def self.ransackable_associations(_auth_object = nil) %w[supplier unit] end def set_terms return if terms self.terms = supplier.payment_terms end end end end
Version data entries
36 entries across 36 versions & 1 rubygems