Add payment structure
This commit is contained in:
@@ -44,11 +44,12 @@ class Employee
|
|||||||
end
|
end
|
||||||
alias_method :settings=, :enrich_with_settings
|
alias_method :settings=, :enrich_with_settings
|
||||||
|
|
||||||
alias_method :orig_save, :save
|
#alias_method :orig_save, :save
|
||||||
def save(*args)
|
#def save(*args)
|
||||||
settings.persist!
|
#settings.persist!
|
||||||
orig_save(*args)
|
#orig_save(*args)
|
||||||
end
|
#end
|
||||||
|
before_validation(on: :save){ settings.persist! }
|
||||||
|
|
||||||
def settings
|
def settings
|
||||||
@settings || SupplierEmployeesSettings.new(Supplier.new).for_employee(self)
|
@settings || SupplierEmployeesSettings.new(Supplier.new).for_employee(self)
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ class List
|
|||||||
belongs_to :table
|
belongs_to :table
|
||||||
belongs_to :supplier
|
belongs_to :supplier
|
||||||
belongs_to :section
|
belongs_to :section
|
||||||
|
has_many :list_payments
|
||||||
has_and_belongs_to_many :users, storing_keys: true
|
has_and_belongs_to_many :users, storing_keys: true
|
||||||
has_and_belongs_to_many :employees, storing_keys: true
|
has_and_belongs_to_many :employees, storing_keys: true
|
||||||
|
|
||||||
@@ -274,6 +275,10 @@ class List
|
|||||||
state == 'active'
|
state == 'active'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def closed?
|
||||||
|
state == 'closed'
|
||||||
|
end
|
||||||
|
|
||||||
def place_order(product_orders: [], user: nil, employee: nil)
|
def place_order(product_orders: [], user: nil, employee: nil)
|
||||||
return false unless product_orders.any?
|
return false unless product_orders.any?
|
||||||
order = Order.create list: self, supplier: supplier, user: user, employee: employee, section_id: section_id, table_id: table_id
|
order = Order.create list: self, supplier: supplier, user: user, employee: employee, section_id: section_id, table_id: table_id
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
class ListPayment
|
||||||
|
include SimplyStored::Couch
|
||||||
|
include ActiveModel::SerializerSupport
|
||||||
|
property :amount
|
||||||
|
property :source # bitcoin, apple_pay, etc...
|
||||||
|
belongs_to :list
|
||||||
|
belongs_to :user
|
||||||
|
|
||||||
|
after_save :close_list_when_is_paid
|
||||||
|
validates :list_id, presence: true
|
||||||
|
|
||||||
|
def close_list_when_is_paid
|
||||||
|
amount_paid = list.list_payments.inject(0.0){|sum, payment| sum + payment.amount}
|
||||||
|
list.close! if amount_paid >= list.price
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -20,6 +20,10 @@ class Supplier
|
|||||||
property :week_starts_on_monday, type: :boolean, default: true
|
property :week_starts_on_monday, type: :boolean, default: true
|
||||||
property :employee_settings_storage
|
property :employee_settings_storage
|
||||||
|
|
||||||
|
# PAYMENT
|
||||||
|
property :accept_bitpay, type: :boolean, default: false
|
||||||
|
property :bitpay_number
|
||||||
|
|
||||||
#LOCATION
|
#LOCATION
|
||||||
property :lat, type: Float #, default: 52.08062426379751
|
property :lat, type: Float #, default: 52.08062426379751
|
||||||
property :lng, type: Float #, default: 4.312562942504883
|
property :lng, type: Float #, default: 4.312562942504883
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ class User
|
|||||||
|
|
||||||
has_and_belongs_to_many :lists, storing_keys: false
|
has_and_belongs_to_many :lists, storing_keys: false
|
||||||
has_many :orders
|
has_many :orders
|
||||||
|
has_many :list_payments
|
||||||
|
|
||||||
validates_uniqueness_of :email
|
validates_uniqueness_of :email
|
||||||
before_save :ensure_authentication_token
|
before_save :ensure_authentication_token
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
FactoryGirl.define do
|
||||||
|
factory :list_payment do
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe ListPayment do
|
||||||
|
it "does completes a list if amount is equal to the list amount" do
|
||||||
|
list = create :list, price: 10.22
|
||||||
|
create :list_payment, amount: 10.22, list: list
|
||||||
|
list.should be_closed
|
||||||
|
end
|
||||||
|
it "does completes a list if amount is greater than the list amount" do
|
||||||
|
list = create :list, price: 10.22
|
||||||
|
create :list_payment, amount: 12, list: list
|
||||||
|
list.should be_closed
|
||||||
|
end
|
||||||
|
it "does completes a list if amount is less than the list amount, but total payments on list bigger" do
|
||||||
|
list = create :list, price: 10.22
|
||||||
|
create :list_payment, amount: 7, list: list
|
||||||
|
list.should be_active
|
||||||
|
create :list_payment, amount: 7, list: list
|
||||||
|
list.should be_closed
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -106,6 +106,7 @@ RSpec.configure do |config|
|
|||||||
config.infer_base_class_for_anonymous_controllers = true
|
config.infer_base_class_for_anonymous_controllers = true
|
||||||
config.filter_run_excluding broken: true
|
config.filter_run_excluding broken: true
|
||||||
config.render_views = true
|
config.render_views = true
|
||||||
|
config.expect_with(:rspec) { |c| c.syntax = [:expect, :should] }
|
||||||
|
|
||||||
OmniAuth.config.test_mode = true
|
OmniAuth.config.test_mode = true
|
||||||
OmniAuth.config.add_mock :facebook, {
|
OmniAuth.config.add_mock :facebook, {
|
||||||
|
|||||||
Reference in New Issue
Block a user