Sha256: 4237b00a762099ae48db0268169086476937d3e3b65776099901faeac09a7899
Contents?: true
Size: 1.26 KB
Versions: 12
Compression:
Stored size: 1.26 KB
Contents
module Comee module Core class SalesOrder < ApplicationRecord before_save :total_price belongs_to :customer_order 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
12 entries across 12 versions & 1 rubygems