Class: PurchaseOrderVariant

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/purchase_order_variant.rb

Overview

Schema Information

Table name: purchase_order_variants

id                :integer(4)      not null, primary key
purchase_order_id :integer(4)      not null
variant_id        :integer(4)      not null
quantity          :integer(4)      not null
cost              :decimal(8, 2)   not null
is_received       :boolean(1)      default(FALSE)
created_at        :datetime
updated_at        :datetime

Instance Method Summary (collapse)

Instance Method Details

- (Object) receive!

This method will need a rescue method i assume.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/models/purchase_order_variant.rb', line 26

def receive!
  PurchaseOrderVariant.transaction do
    ###  Add to variant stock level
    self.variant.inventory.count_on_hand = self.variant.inventory.count_on_hand + quantity
    if self.variant.inventory.save!
      ### change is_received to true
      self.is_received = true
      self.save!
    end
    if 0 == PurchaseOrderVariant.where({ :purchase_order_variants =>
                                              { :purchase_order_id => purchase_order_id,
                                                :is_received       => false
                                              } }).count
      self.purchase_order.mark_as_complete
    end
  end
end

- (Boolean) receive_po

method used by forms to set if the PO is received or not

Parameters:

  • (none)

Returns:

  • (Boolean)


59
60
61
# File 'app/models/purchase_order_variant.rb', line 59

def receive_po
  is_received?
end

- (none) receive_po=(answer)

in the admin form this is the method called when the form is submitted,

The method receives the PO and handles the inventory

Parameters:

  • value (String)

    for set_keywords in a products form

Returns:

  • (none)


49
50
51
52
53
# File 'app/models/purchase_order_variant.rb', line 49

def receive_po=(answer)
  if (answer == 'true' || answer == '1') && !is_received?
    receive!
  end
end