Sha256: 276a47c7c6a3b11c0275a310225a168f02002e287dedae2baf4dea2380a39ca2
Contents?: true
Size: 1.42 KB
Versions: 16
Compression:
Stored size: 1.42 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) %w[ 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
16 entries across 16 versions & 1 rubygems