Class: Products::Handlers::CreateOrUpdate

Inherits:
Object
  • Object
show all
Defined in:
app/models/products/handlers/create_or_update.rb

Constant Summary collapse

COMPANY_CODE =
Rails.application.config.company_code
DEFAULT_PRODUCT_FAMILY_ID =
1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(product_code:, description_english:, brand_description:, brand_category_description:, group_description:, subgroup_description:, production_specs_header_id:, production_specs_description_english:, package_specs_header_id:, default_storage_uom_description:, default_sales_uom_description:, default_purchase_uom_description:, initiated_by_company:, approved_to_sell:, approved_to_sell_online:, approved_to_purchase:, active:, product_category_description:, season_description:, memo:, system_date:, system_user:, product_id: 0, description_french: nil, product_type: nil, sales_order_multiplier: 1, alternate_description: nil, warranty_days: nil, product_image_filepath: nil) ⇒ CreateOrUpdate

Returns a new instance of CreateOrUpdate.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/models/products/handlers/create_or_update.rb', line 39

def initialize(
  product_code:, description_english:, brand_description:, brand_category_description:, group_description:, subgroup_description:, production_specs_header_id:, production_specs_description_english:, package_specs_header_id:, default_storage_uom_description:, default_sales_uom_description:, default_purchase_uom_description:, initiated_by_company:, approved_to_sell:, approved_to_sell_online:, approved_to_purchase:, active:, product_category_description:, season_description:, memo:, system_date:, system_user:, product_id: 0,
  description_french: nil,
  product_type: nil,
  sales_order_multiplier: 1,
  alternate_description: nil,
  warranty_days: nil,
  product_image_filepath: nil
)
  @product_id = product_id
  @product_code = product_code
  @description_english = description_english
  @description_french = description_french
  @brand_description = brand_description
  @brand_category_description = brand_category_description
  @group_description = group_description
  @subgroup_description = subgroup_description
  @production_specs_header_id = production_specs_header_id
  @production_specs_description_english = production_specs_description_english
  @package_specs_header_id = package_specs_header_id
  @default_storage_uom_description = default_storage_uom_description
  @default_sales_uom_description = default_sales_uom_description
  @default_purchase_uom_description = default_purchase_uom_description
  @initiated_by_company = initiated_by_company
  @product_type = product_type
  @approved_to_sell = approved_to_sell
  @approved_to_sell_online = approved_to_sell_online
  @approved_to_purchase = approved_to_purchase
  @active = active
  @sales_order_multiplier = sales_order_multiplier
  @product_category_description = product_category_description
  @season_description = season_description
  @alternate_description = alternate_description
  @warranty_days = warranty_days
  @memo = memo
  @system_date = system_date
  @system_user = system_user
end

Instance Attribute Details

#activeObject (readonly)

Returns the value of attribute active.



7
8
9
# File 'app/models/products/handlers/create_or_update.rb', line 7

def active
  @active
end

#alternate_descriptionObject (readonly)

Returns the value of attribute alternate_description.



7
8
9
# File 'app/models/products/handlers/create_or_update.rb', line 7

def alternate_description
  @alternate_description
end

#approved_to_purchaseObject (readonly)

Returns the value of attribute approved_to_purchase.



7
8
9
# File 'app/models/products/handlers/create_or_update.rb', line 7

def approved_to_purchase
  @approved_to_purchase
end

#approved_to_sellObject (readonly)

Returns the value of attribute approved_to_sell.



7
8
9
# File 'app/models/products/handlers/create_or_update.rb', line 7

def approved_to_sell
  @approved_to_sell
end

#approved_to_sell_onlineObject (readonly)

Returns the value of attribute approved_to_sell_online.



7
8
9
# File 'app/models/products/handlers/create_or_update.rb', line 7

def approved_to_sell_online
  @approved_to_sell_online
end

#brand_category_descriptionObject (readonly)

Returns the value of attribute brand_category_description.



7
8
9
# File 'app/models/products/handlers/create_or_update.rb', line 7

def brand_category_description
  @brand_category_description
end

#brand_descriptionObject (readonly)

Returns the value of attribute brand_description.



7
8
9
# File 'app/models/products/handlers/create_or_update.rb', line 7

def brand_description
  @brand_description
end

#default_purchase_uom_descriptionObject (readonly)

Returns the value of attribute default_purchase_uom_description.



7
8
9
# File 'app/models/products/handlers/create_or_update.rb', line 7

def default_purchase_uom_description
  @default_purchase_uom_description
end

#default_sales_uom_descriptionObject (readonly)

Returns the value of attribute default_sales_uom_description.



7
8
9
# File 'app/models/products/handlers/create_or_update.rb', line 7

def default_sales_uom_description
  @default_sales_uom_description
end

#default_storage_uom_descriptionObject (readonly)

Returns the value of attribute default_storage_uom_description.



7
8
9
# File 'app/models/products/handlers/create_or_update.rb', line 7

def default_storage_uom_description
  @default_storage_uom_description
end

#description_englishObject (readonly)

Returns the value of attribute description_english.



7
8
9
# File 'app/models/products/handlers/create_or_update.rb', line 7

def description_english
  @description_english
end

#description_frenchObject (readonly)

Returns the value of attribute description_french.



7
8
9
# File 'app/models/products/handlers/create_or_update.rb', line 7

def description_french
  @description_french
end

#group_descriptionObject (readonly)

Returns the value of attribute group_description.



7
8
9
# File 'app/models/products/handlers/create_or_update.rb', line 7

def group_description
  @group_description
end

#initiated_by_companyObject (readonly)

Returns the value of attribute initiated_by_company.



7
8
9
# File 'app/models/products/handlers/create_or_update.rb', line 7

def initiated_by_company
  @initiated_by_company
end

#memoObject (readonly)

Returns the value of attribute memo.



7
8
9
# File 'app/models/products/handlers/create_or_update.rb', line 7

def memo
  @memo
end

#package_specs_header_idObject (readonly)

Returns the value of attribute package_specs_header_id.



7
8
9
# File 'app/models/products/handlers/create_or_update.rb', line 7

def package_specs_header_id
  @package_specs_header_id
end

#product_category_descriptionObject (readonly)

Returns the value of attribute product_category_description.



7
8
9
# File 'app/models/products/handlers/create_or_update.rb', line 7

def product_category_description
  @product_category_description
end

#product_codeObject (readonly)

Returns the value of attribute product_code.



7
8
9
# File 'app/models/products/handlers/create_or_update.rb', line 7

def product_code
  @product_code
end

#product_idObject (readonly)

Returns the value of attribute product_id.



7
8
9
# File 'app/models/products/handlers/create_or_update.rb', line 7

def product_id
  @product_id
end

#product_image_filepathObject (readonly)

Returns the value of attribute product_image_filepath.



7
8
9
# File 'app/models/products/handlers/create_or_update.rb', line 7

def product_image_filepath
  @product_image_filepath
end

#product_typeObject (readonly)

Returns the value of attribute product_type.



7
8
9
# File 'app/models/products/handlers/create_or_update.rb', line 7

def product_type
  @product_type
end

#production_specs_description_englishObject (readonly)

Returns the value of attribute production_specs_description_english.



7
8
9
# File 'app/models/products/handlers/create_or_update.rb', line 7

def production_specs_description_english
  @production_specs_description_english
end

#production_specs_header_idObject (readonly)

Returns the value of attribute production_specs_header_id.



7
8
9
# File 'app/models/products/handlers/create_or_update.rb', line 7

def production_specs_header_id
  @production_specs_header_id
end

#sales_order_multiplierObject (readonly)

Returns the value of attribute sales_order_multiplier.



7
8
9
# File 'app/models/products/handlers/create_or_update.rb', line 7

def sales_order_multiplier
  @sales_order_multiplier
end

#season_descriptionObject (readonly)

Returns the value of attribute season_description.



7
8
9
# File 'app/models/products/handlers/create_or_update.rb', line 7

def season_description
  @season_description
end

#subgroup_descriptionObject (readonly)

Returns the value of attribute subgroup_description.



7
8
9
# File 'app/models/products/handlers/create_or_update.rb', line 7

def subgroup_description
  @subgroup_description
end

#system_dateObject (readonly)

Returns the value of attribute system_date.



7
8
9
# File 'app/models/products/handlers/create_or_update.rb', line 7

def system_date
  @system_date
end

#system_userObject (readonly)

Returns the value of attribute system_user.



7
8
9
# File 'app/models/products/handlers/create_or_update.rb', line 7

def system_user
  @system_user
end

#warranty_daysObject (readonly)

Returns the value of attribute warranty_days.



7
8
9
# File 'app/models/products/handlers/create_or_update.rb', line 7

def warranty_days
  @warranty_days
end

Instance Method Details

#callObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'app/models/products/handlers/create_or_update.rb', line 78

def call
  Product.create_or_update(
    product_id: product_id,
    product_code: product_code,
    description_english: description_english,
    description_french: description_french || description_english,
    alternate_description: alternate_description,
    product_family_id: DEFAULT_PRODUCT_FAMILY_ID,
    brand_id: Brand.find_by(description: brand_description)&.id || '',
    brand_category_id: BrandCategory.find_by(description_english: brand_category_description)&.id || '',
    group_id: Group.find_by(description: group_description)&.id || '',
    sub_group_id: SubGroup.find_by(description: subgroup_description)&.id || '',
    season_id: Season.find_by(description: season_description)&.id || '',
    royalty_id: '',
    production_specs_header_id: production_specs_header_id || '',
    package_specs_header_id: package_specs_header_id || '',
    default_storage_uom_id: UnitOfMeasurement.find_by(description: default_storage_uom_description)&.id || '',
    default_purchase_uom_id: UnitOfMeasurement.find_by(description: default_purchase_uom_description)&.id || '',
    default_sales_uom_id: UnitOfMeasurement.find_by(description: default_sales_uom_description)&.id || '',
    initiated_by_company: COMPANY_CODE,
    product_category_id: ProductCategory.find_by(description_english: product_category_description)&.id,
    approved_to_sell: approved_to_sell,
    approved_to_sell_online: approved_to_sell_online,
    approved_to_purchase: approved_to_purchase,
    product_image_filepath: product_image_filepath,
    memo: memo,
    active: active,
    city_id: '',
    warranty_days: warranty_days,
    sales_order_multiplier: sales_order_multiplier,
    product_type: product_type,
    system_date: system_date,
    system_user: system_user
  )
end