Sha256: 270850987d34e49dd0b8882d379dd98c1599e17b9d7a6ec961a8b8ab9e62ac98
Contents?: true
Size: 1.52 KB
Versions: 16
Compression:
Stored size: 1.52 KB
Contents
module Comee module Core class PurchaseOrder < ApplicationRecord before_validation :generate_po_number, if: proc { |po| po.po_number.nil? } before_save :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 calculate_total_price items = PurchaseOrderItem.where(purchase_order_id: id) self.total_price = items.sum(&:total_price).round(2) end def calculate_vat return unless supplier.tax_code == "Inland" items = PurchaseOrderItem.where(purchase_order_id: id) total_price = items.sum(&:total_price) self.vat = (total_price * 0.19).round(2) 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
16 entries across 16 versions & 1 rubygems