Class: Unidom::Product::ProductAssociating

Inherits:
ApplicationRecord show all
Includes:
ProgneTapera::EnumCode, Common::Concerns::ModelExtension
Defined in:
app/models/unidom/product/product_associating.rb

Overview

Product Associating 表示产品之间的关联。常见的关联包括销售包装、产品换代等。source 是来源产品。如组合后的产品、被换代的产品、不兼容产品中的主产品。target 是目标产品。如参与组合的产品、替换其它产品的新产品、不兼容产品中的次要产品。product_association_code 是产品关联:

CPLM 是产品补充   complement: from, thru, reason
ICPT 是产品不兼容 incompatibility: from, thru, reason
OBSL 是产品废弃   obsolescence: on, reason
PCKG 是销售包装(行销组件)   package: quantity, usage
SBST 是产品替代   substitute: from, thru, quantity, comments

构成: from, thru, quantity, usage, comments

Class Method Summary collapse

Class Method Details

.associate!(source, with: target, due_to: 'PCKG', ordinal: 1, quantity: 1, at: Time.now) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/models/unidom/product/product_associating.rb', line 31

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