Sha256: 6337ecfb2951afd629a6ef36f49c121554d0ebdfa0c6ccf338e1846fccb5c7c1
Contents?: true
Size: 1.41 KB
Versions: 8
Compression:
Stored size: 1.41 KB
Contents
module Comee module Core class SalesOrder < ApplicationRecord belongs_to :client has_many :sales_order_items enum :status, {draft: 0, confirmed: 1, cancelled: 2} validates :order_number, presence: true, uniqueness: true validates :order_date, :expected_delivery_date, :delivery_address, :invoice_address, :status, presence: true validates :payment_no_of_days, :payment_discount, :payment_penalty, presence: true, numericality: {greater_than_or_equal_to: 0, less_than_or_equal_to: 100} delegate(:name, to: :client, prefix: true) def confirm raise(StandardError, "Sales order is already confirmed.") if SalesOrder.statuses[status] == SalesOrder.statuses[:confirmed] self.status = SalesOrder.statuses[:confirmed] save end def cancel raise(StandardError, "Sales order is already cancelled.") if SalesOrder.statuses[status] == SalesOrder.statuses[:cancelled] self.status = SalesOrder.statuses[:cancelled] save end def self.ransackable_attributes(auth_object = nil) [ "delivery_address", "expected_delivery_date", "invoice_address", "order_date", "order_number", "status", "client_id" ] end def self.ransackable_associations(auth_object = nil) [] end end end end
Version data entries
8 entries across 8 versions & 1 rubygems