mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-19 13:54:25 +01:00
coupons usages are counted with invoices
This commit is contained in:
parent
84a7e81813
commit
ce31c1412b
@ -1,5 +1,5 @@
|
||||
class Coupon < ActiveRecord::Base
|
||||
has_many :invoice
|
||||
has_many :invoices
|
||||
|
||||
validates :code, presence: true
|
||||
validates :code, format: { with: /[A-Z0-9]+/ ,message: 'only caps letters and numbers'}
|
||||
|
@ -1 +1,2 @@
|
||||
json.extract! coupon, :id, :name, :code, :percent_off, :valid_until, :max_usages, :active, :created_at
|
||||
json.extract! coupon, :id, :name, :code, :percent_off, :valid_until, :max_usages, :active, :created_at
|
||||
json.usages @coupon.invoices.count
|
5
app/views/api/coupons/index.json.jbuilder
Normal file
5
app/views/api/coupons/index.json.jbuilder
Normal file
@ -0,0 +1,5 @@
|
||||
json.cache! [@coupons] do
|
||||
json.array!(@coupons) do |coupon|
|
||||
json.partial! 'api/coupons/coupon', coupon: coupon
|
||||
end
|
||||
end
|
5
db/migrate/20160804073558_remove_usages_from_coupons.rb
Normal file
5
db/migrate/20160804073558_remove_usages_from_coupons.rb
Normal file
@ -0,0 +1,5 @@
|
||||
class RemoveUsagesFromCoupons < ActiveRecord::Migration
|
||||
def change
|
||||
remove_column :coupons, :usages, :integer
|
||||
end
|
||||
end
|
@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20160803104701) do
|
||||
ActiveRecord::Schema.define(version: 20160804073558) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@ -110,7 +110,6 @@ ActiveRecord::Schema.define(version: 20160803104701) do
|
||||
t.integer "percent_off"
|
||||
t.datetime "valid_until"
|
||||
t.integer "max_usages"
|
||||
t.integer "usages"
|
||||
t.boolean "active"
|
||||
t.string "stp_coupon_id"
|
||||
t.datetime "created_at", null: false
|
||||
|
Loading…
x
Reference in New Issue
Block a user