Sha256: d7538a43b2c2d2342629fa0f44e9fd806be6304dd47663072ff32be68197ac01
Contents?: true
Size: 1.32 KB
Versions: 16
Compression:
Stored size: 1.32 KB
Contents
module Comee module Core class SalesOrder < ApplicationRecord before_save :total_price belongs_to :customer_order belongs_to :fulfillment_center, optional: true has_many :sales_order_items has_many_attached :files enum :status, {draft: 0, submitted: 1, confirmed: 2, canceled: 3} validates :order_number, presence: true, uniqueness: true validates :status, presence: true validates :payment_penalty, presence: true, numericality: {greater_than_or_equal_to: 0, less_than_or_equal_to: 100} validates :total_price, :amount_paid, presence: true, numericality: {greater_than_or_equal_to: 0} def total_price sales_order_items = SalesOrderItem.where(sales_order_id: id) total_price = sales_order_items.sum(&:price) self.total_price = total_price end def self.ransackable_attributes(_auth_object = nil) %w[ 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
16 entries across 16 versions & 1 rubygems