-
Notifications
You must be signed in to change notification settings - Fork 4
Manualni zavirani aukci #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: manual-closing
Are you sure you want to change the base?
Changes from all commits
852e003
6c8d86d
0efa80a
9ff1b1c
5672a5b
0608228
b77ba2f
1ec46e9
bb49255
b0f03c8
5289bcc
826a162
1bb71da
ba53d4b
2888446
aab2d4d
b81c906
b98102f
7536802
efb84af
9496ac1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ class Auction < Auctify::Sale::Base | |
| } | ||
|
|
||
| attr_accessor :winning_bid | ||
| attr_accessor :manually_closed_price_check | ||
|
|
||
| has_many :bidder_registrations, dependent: :destroy | ||
| has_many :bids, through: :bidder_registrations, dependent: :restrict_with_error # destroy them manually first | ||
|
|
@@ -23,11 +24,16 @@ class Auction < Auctify::Sale::Base | |
|
|
||
| belongs_to :winner, polymorphic: true, optional: true | ||
| belongs_to :current_winner, polymorphic: true, optional: true | ||
| belongs_to :manually_closed_by, polymorphic: true, optional: true | ||
| belongs_to :bidding_locked_by, polymorphic: true, optional: true | ||
|
|
||
| validates :ends_at, | ||
| presence: true | ||
|
|
||
| scope :where_current_winner_is, ->(bidder) { where(current_winner: bidder) } | ||
| scope :closable_automatically, -> do | ||
| where(must_be_closed_manually: false) | ||
| end | ||
|
|
||
| aasm do | ||
| state :offered, initial: true, color: "red" | ||
|
|
@@ -115,6 +121,8 @@ class Auction < Auctify::Sale::Base | |
|
|
||
| validate :buyer_vs_bidding_consistence | ||
| validate :forbidden_changes | ||
| validate :validate_manually_closed | ||
| validate :validate_bidding_locked | ||
|
|
||
| after_create :autoregister_bidders | ||
| after_save :create_jobs | ||
|
|
@@ -225,7 +233,13 @@ def current_max_price_for(bidder, bids_array: nil) | |
| end | ||
|
|
||
| def open_for_bids? | ||
| in_sale? && Time.current <= currently_ends_at | ||
| return false if bidding_locked_at? | ||
|
|
||
| if must_be_closed_manually? | ||
| !manually_closed_at && in_sale? | ||
| else | ||
| in_sale? && Time.current <= currently_ends_at | ||
| end | ||
| end | ||
|
|
||
| def opening_price | ||
|
|
@@ -249,6 +263,23 @@ def auction_prolonging_limit_in_seconds | |
| pack&.auction_prolonging_limit_in_seconds || Auctify.configuration.auction_prolonging_limit_in_seconds | ||
| end | ||
|
|
||
| def close_manually(by:, price_check:) | ||
| if manually_closed_at.nil? && update(manually_closed_at: Time.current, manually_closed_by: by, manually_closed_price_check: price_check) | ||
| Auctify::BiddingCloserJob.perform_later(auction_id: id) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tady mi přijde zbytečné to honit přes Job. Rovnou bych dal |
||
| true | ||
| else | ||
| false | ||
| end | ||
| end | ||
|
|
||
| def lock_bidding(by:) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tady budu potřebovat objasnit jaký je rozdíl/použití
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| !!update(bidding_locked_at: Time.current, bidding_locked_by: by) | ||
| end | ||
|
|
||
| def unlock_bidding(by:) | ||
| !!update(bidding_locked_at: nil, bidding_locked_by: nil) | ||
| end | ||
|
|
||
| private | ||
| def buyer_vs_bidding_consistence | ||
| return true if buyer.blank? && sold_price.blank? | ||
|
|
@@ -364,6 +395,38 @@ def create_jobs(force = false) | |
| end | ||
| end | ||
| end | ||
|
|
||
| def validate_manually_closed | ||
| return unless will_save_change_to_manually_closed_at? | ||
|
|
||
| if manually_closed_at | ||
| unless bidding_locked_at? | ||
| errors.add(:base, :need_to_lock_bidding_first) | ||
| end | ||
|
|
||
| if !manually_closed_price_check || manually_closed_price_check.to_i != current_price | ||
| errors.add(:base, :current_price_doesnt_match_closing) | ||
| end | ||
|
|
||
| unless must_be_closed_manually? | ||
| errors.add(:base, :sales_not_closed_manually) | ||
| end | ||
|
|
||
| unless manually_closed_by.is_a?(Folio::Account) | ||
| errors.add(:manually_closed_by, :not_allowed) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def validate_bidding_locked | ||
| return unless will_save_change_to_bidding_locked_at? | ||
|
|
||
| if bidding_locked_at? | ||
| unless bidding_locked_by.is_a?(Folio::Account) | ||
| errors.add(:bidding_locked_by, :not_allowed) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
@@ -376,16 +439,16 @@ def create_jobs(force = false) | |
| # seller_type :string | ||
| # seller_id :integer | ||
| # buyer_type :string | ||
| # buyer_id :integer | ||
| # item_id :integer not null | ||
| # buyer_id :bigint(8) | ||
| # item_id :bigint(8) not null | ||
| # created_at :datetime not null | ||
| # updated_at :datetime not null | ||
| # type :string default("Auctify::Sale::Base") | ||
| # aasm_state :string default("offered"), not null | ||
| # offered_price :decimal(, ) | ||
| # current_price :decimal(, ) | ||
| # sold_price :decimal(, ) | ||
| # bid_steps_ladder :json | ||
| # offered_price :decimal(12, 2) | ||
| # current_price :decimal(12, 2) | ||
| # sold_price :decimal(12, 2) | ||
| # bid_steps_ladder :jsonb | ||
| # reserve_price :decimal(, ) | ||
| # pack_id :bigint(8) | ||
| # ends_at :datetime | ||
|
|
@@ -404,12 +467,23 @@ def create_jobs(force = false) | |
| # current_winner_id :bigint(8) | ||
| # buyer_commission_in_percent :integer | ||
| # featured :integer | ||
| # manually_closed_at :datetime | ||
| # manually_closed_by_type :string | ||
| # manually_closed_by_id :bigint(8) | ||
| # must_be_closed_manually :boolean default(FALSE) | ||
| # bidding_locked_at :datetime | ||
| # bidding_locked_by_type :string | ||
| # bidding_locked_by_id :bigint(8) | ||
| # | ||
| # Indexes | ||
| # | ||
| # index_auctify_sales_on_aasm_state (aasm_state) | ||
| # index_auctify_sales_on_bidding_locked_by (bidding_locked_by_type,bidding_locked_by_id) | ||
| # index_auctify_sales_on_buyer_type_and_buyer_id (buyer_type,buyer_id) | ||
| # index_auctify_sales_on_currently_ends_at (currently_ends_at) | ||
| # index_auctify_sales_on_featured (featured) | ||
| # index_auctify_sales_on_manually_closed_by (manually_closed_by_type,manually_closed_by_id) | ||
| # index_auctify_sales_on_must_be_closed_manually (must_be_closed_manually) | ||
| # index_auctify_sales_on_pack_id (pack_id) | ||
| # index_auctify_sales_on_position (position) | ||
| # index_auctify_sales_on_published (published) | ||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.