app/models/unidom/price/price.rb in unidom-price-1.3.2 vs app/models/unidom/price/price.rb in unidom-price-1.4
- old
+ new
@@ -1,19 +1,24 @@
# Price 是价格。
+# pricing: 基价(Base)、折扣成分、额外收费成分、厂商建议价。
+# charging: 一次性收费、重复性收费、使用率收费。
class Unidom::Price::Price < Unidom::Price::ApplicationRecord
self.table_name = 'unidom_prices'
include Unidom::Common::Concerns::ModelExtension
+ include ProgneTapera::EnumCode
validates :amount, presence: true, numericality: { less_than: 1000000000, greater_than: 0 }
belongs_to :priced, polymorphic: true
belongs_to :pricer, polymorphic: true
scope :priced_by, ->(pricer) { where pricer: pricer }
scope :priced_is, ->(priced) { where priced: priced }
+
+ code :calculation, Unidom::Price::Calculation
def self.price!(priced, amount: 0, pricer: nil, calculation_code: 'AMNT', pricing_code: 'BASE', charging_code: 'ONCE', opened_at: Time.now)
price = priced_is(priced).calculation_coded_as(calculation_code).pricing_coded_as(pricing_code).charging_coded_as(charging_code).valid_at.alive.first
if price.present?
price.amount = amount