Sha256: 339ebb82040b8d54cd95788cec6bd09c60f105aab3c67f8e42f1764d32a362cc
Contents?: true
Size: 1.49 KB
Versions: 11
Compression:
Stored size: 1.49 KB
Contents
module Comee module Core class SalesOrder < ApplicationRecord before_save :total_price before_save :set_parent_client_name belongs_to :customer_order belongs_to :fulfillment_center, optional: true belongs_to :client has_many :sales_order_items has_many_attached :files has_one :customs_detail enum :status, {draft: 0, submitted: 1, confirmed: 2, accepted: 3, canceled: 4} validates :order_number, presence: true, uniqueness: true validates :order_date, :status, presence: true validates :payment_penalty, numericality: {greater_than_or_equal_to: 0, less_than_or_equal_to: 100}, allow_nil: true validates :amount_paid, presence: true, numericality: {greater_than_or_equal_to: 0}, allow_nil: true def total_price sales_order_items = SalesOrderItem.where(sales_order_id: id) self.total_price = sales_order_items.sum(&:total_price) end def set_parent_client_name self.parent_client_name = client.parent&.name end def self.ransackable_attributes(_auth_object = nil) %w[ id order_number status customer_order_id ] end def self.ransackable_associations(_auth_object = nil) [] end def files_url files.attached? ? files.map { |file| Rails.application.routes.url_helpers.rails_blob_url(file, only_path: false) } : [] end end end end
Version data entries
11 entries across 11 versions & 1 rubygems