Class: Comee::Core::MasterPrice
- Inherits:
-
Price
show all
- Defined in:
- app/models/comee/core/master_price.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Price
#approve, #approved?, #compute_status, #current?, #draft?, #future?, #past?, #validate_price_validity_dates
Class Method Details
.product_price(product_id) ⇒ Object
22
23
24
25
26
27
28
|
# File 'app/models/comee/core/master_price.rb', line 22
def self.product_price(product_id)
MasterPrice.find_by(
product_id: product_id,
primary: true,
status: Price.statuses[:current]
)
end
|
.ransackable_associations(_auth_object = nil) ⇒ Object
70
71
72
|
# File 'app/models/comee/core/master_price.rb', line 70
def self.ransackable_associations(_auth_object = nil)
%w[product supplier product_lookup]
end
|
.ransackable_attributes(_auth_object = nil) ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'app/models/comee/core/master_price.rb', line 55
def self.ransackable_attributes(_auth_object = nil)
%w[
id
valid_from
valid_to
purchase_price
selling_price
status
product_id
supplier_id
previous_price_id
next_price_id
]
end
|
Instance Method Details
#set_default_currency ⇒ Object
49
50
51
52
53
|
# File 'app/models/comee/core/master_price.rb', line 49
def set_default_currency
return if currency
self.currency = Comee::Core::Currency.find_by(code: "EUR")
end
|
#validate_primary_price ⇒ Object
30
31
32
33
34
35
36
37
|
# File 'app/models/comee/core/master_price.rb', line 30
def validate_primary_price
return unless product && primary
price = MasterPrice.find_by(product: product, primary: true, status: Price.statuses[:current])
return unless price && price.id != id && status == price.status
errors.add(:base, "There is already a primary price entry for item '#{product.code}'")
end
|
#validate_product_lookup ⇒ Object
39
40
41
42
43
44
45
46
47
|
# File 'app/models/comee/core/master_price.rb', line 39
def validate_product_lookup
return unless product_lookup && product && supplier
if product_lookup.itemable_id != supplier_id ||
product_lookup.itemable_type != "Comee::Core::Supplier" ||
product_lookup.product_id != product_id
errors.add(:product_lookup, "contains wrong supplier or product.")
end
end
|