Sha256: 23ec1807dc005be1095a808b2c55a2ebcce6ba0ffca2f3bc98a0c07157c0de1b
Contents?: true
Size: 1.87 KB
Versions: 2
Compression:
Stored size: 1.87 KB
Contents
# Product Associating 表示产品之间的关联。常见的关联包括销售包装、产品换代等。 # source 是来源产品。如组合后的产品、被换代的产品、不兼容产品中的主产品。 # target 是目标产品。如参与组合的产品、替换其它产品的新产品、不兼容产品中的次要产品。 # product_association_code 是产品关联: # CPLM 是产品补充 complement # ICPT 是产品不兼容 incompatibility # OBSL 是产品废弃 obsolescence # PCKG 是销售包装 package # SBST 是产品替代 substitute class Unidom::Product::ProductAssociating < Unidom::Product::ApplicationRecord self.table_name = 'unidom_product_associatings' include Unidom::Common::Concerns::ModelExtension validates :quantity, presence: true, numericality: { greater_than_or_equal_to: 0 } belongs_to :source, class_name: 'Unidom::Product::Product' belongs_to :target, class_name: 'Unidom::Product::Product' scope :source_is, ->(product) { where source_id: to_id(product) } scope :target_is, ->(product) { where target_id: to_id(product) } def self.associate!(source, with: target, due_to: 'PCKG', ordinal: 1, quantity: 1, at: Time.now) associating = source_is(source).target_is(with).product_association_coded_as(due_to).valid_at.alive.first associating.soft_destroy if associating.present? #if associating.present? # associating.attributes = { ordinal: ordinal, quantity: quantity, opened_at: opened_at } # associating.save! #else # associating = create! source_id: to_id(source), target_id: to_id(target), product_association_code: product_association_code, ordinal: ordinal, quantity: quantity, opened_at: opened_at #end #associating create! source_id: to_id(source), target_id: to_id(with), product_association_code: due_to, ordinal: ordinal, quantity: quantity, opened_at: at end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
unidom-product-1.4.2 | app/models/unidom/product/product_associating.rb |
unidom-product-1.4.1 | app/models/unidom/product/product_associating.rb |