1
0
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:
Sylvain 2016-08-04 09:45:00 +02:00
parent 84a7e81813
commit ce31c1412b
5 changed files with 14 additions and 4 deletions

View File

@ -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'}

View File

@ -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

View File

@ -0,0 +1,5 @@
json.cache! [@coupons] do
json.array!(@coupons) do |coupon|
json.partial! 'api/coupons/coupon', coupon: coupon
end
end

View File

@ -0,0 +1,5 @@
class RemoveUsagesFromCoupons < ActiveRecord::Migration
def change
remove_column :coupons, :usages, :integer
end
end

View File

@ -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