mirror of
https://github.com/internetee/registry.git
synced 2025-05-16 01:17:18 +02:00
Add activity type field #2691
This commit is contained in:
parent
fa4a2d2987
commit
d6a151b141
9 changed files with 45 additions and 67 deletions
|
@ -30,7 +30,7 @@ class Epp::DomainsController < EppController
|
||||||
|
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
if @domain.save # TODO: Maybe use validate: false here because we have already validated the domain?
|
if @domain.save # TODO: Maybe use validate: false here because we have already validated the domain?
|
||||||
current_user.registrar.debit!(@domain_price, "#{I18n.t('create')} #{@domain.name}")
|
current_user.registrar.debit!(@domain_price, "#{I18n.t('create')} #{@domain.name}", AccountActivity::CREATE)
|
||||||
render_epp_response '/epp/domains/create'
|
render_epp_response '/epp/domains/create'
|
||||||
else
|
else
|
||||||
handle_errors(@domain)
|
handle_errors(@domain)
|
||||||
|
@ -102,7 +102,7 @@ class Epp::DomainsController < EppController
|
||||||
fail ActiveRecord::Rollback
|
fail ActiveRecord::Rollback
|
||||||
end
|
end
|
||||||
|
|
||||||
current_user.registrar.debit!(@domain_price, "#{I18n.t('renew')} #{@domain.name}")
|
current_user.registrar.debit!(@domain_price, "#{I18n.t('renew')} #{@domain.name}", AccountActivity::RENEW)
|
||||||
render_epp_response '/epp/domains/renew'
|
render_epp_response '/epp/domains/renew'
|
||||||
else
|
else
|
||||||
handle_errors(@domain)
|
handle_errors(@domain)
|
||||||
|
|
|
@ -4,6 +4,10 @@ class AccountActivity < ActiveRecord::Base
|
||||||
belongs_to :bank_transaction
|
belongs_to :bank_transaction
|
||||||
belongs_to :invoice
|
belongs_to :invoice
|
||||||
|
|
||||||
|
CREATE = 'create'
|
||||||
|
RENEW = 'renew'
|
||||||
|
ADD_CREDIT = 'add_credit'
|
||||||
|
|
||||||
after_create :update_balance
|
after_create :update_balance
|
||||||
def update_balance
|
def update_balance
|
||||||
account.balance += sum
|
account.balance += sum
|
||||||
|
|
|
@ -79,7 +79,8 @@ class BankTransaction < ActiveRecord::Base
|
||||||
invoice: invoice,
|
invoice: invoice,
|
||||||
sum: invoice.sum_without_vat,
|
sum: invoice.sum_without_vat,
|
||||||
currency: currency,
|
currency: currency,
|
||||||
description: description
|
description: description,
|
||||||
|
activity_type: AccountActivity::ADD_CREDIT
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -123,19 +123,21 @@ class Registrar < ActiveRecord::Base
|
||||||
accounts.find_by(account_type: Account::CASH)
|
accounts.find_by(account_type: Account::CASH)
|
||||||
end
|
end
|
||||||
|
|
||||||
def debit!(sum, description)
|
def debit!(sum, description, type = nil)
|
||||||
cash_account.account_activities.create!(
|
cash_account.account_activities.create!(
|
||||||
sum: -sum,
|
sum: -sum,
|
||||||
currency: 'EUR',
|
currency: 'EUR',
|
||||||
description: description
|
description: description,
|
||||||
|
activity_type: type
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def credit!(sum, description)
|
def credit!(sum, description, type = nil)
|
||||||
cash_account.account_activities.create!(
|
cash_account.account_activities.create!(
|
||||||
sum: sum,
|
sum: sum,
|
||||||
currency: 'EUR',
|
currency: 'EUR',
|
||||||
description: description
|
description: description,
|
||||||
|
activity_type: type
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AddActivityTypeToAccountActivities < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :account_activities, :activity_type, :string
|
||||||
|
end
|
||||||
|
end
|
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20150703105159) do
|
ActiveRecord::Schema.define(version: 20150706091724) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
@ -27,6 +27,7 @@ ActiveRecord::Schema.define(version: 20150703105159) do
|
||||||
t.string "description"
|
t.string "description"
|
||||||
t.string "creator_str"
|
t.string "creator_str"
|
||||||
t.string "updator_str"
|
t.string "updator_str"
|
||||||
|
t.string "activity_type"
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "account_activities", ["account_id"], name: "index_account_activities_on_account_id", using: :btree
|
add_index "account_activities", ["account_id"], name: "index_account_activities_on_account_id", using: :btree
|
||||||
|
@ -932,14 +933,14 @@ ActiveRecord::Schema.define(version: 20150703105159) do
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "que_jobs", id: false, force: :cascade do |t|
|
create_table "que_jobs", id: false, force: :cascade do |t|
|
||||||
t.integer "priority", limit: 2, default: 100, null: false
|
t.integer "priority", limit: 2, default: 100, null: false
|
||||||
t.datetime "run_at", default: "now()", null: false
|
t.datetime "run_at", default: '2015-06-30 14:16:50', null: false
|
||||||
t.integer "job_id", limit: 8, default: "nextval('que_jobs_job_id_seq'::regclass)", null: false
|
t.integer "job_id", limit: 8, default: 0, null: false
|
||||||
t.text "job_class", null: false
|
t.text "job_class", null: false
|
||||||
t.json "args", default: [], null: false
|
t.json "args", default: [], null: false
|
||||||
t.integer "error_count", default: 0, null: false
|
t.integer "error_count", default: 0, null: false
|
||||||
t.text "last_error"
|
t.text "last_error"
|
||||||
t.text "queue", default: "", null: false
|
t.text "queue", default: "", null: false
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "registrant_verifications", force: :cascade do |t|
|
create_table "registrant_verifications", force: :cascade do |t|
|
||||||
|
|
|
@ -74,7 +74,7 @@ CREATE FUNCTION generate_zonefile(i_origin character varying) RETURNS text
|
||||||
SELECT concat(d.name_puny, '. IN NS ', ns.hostname, '.')
|
SELECT concat(d.name_puny, '. IN NS ', ns.hostname, '.')
|
||||||
FROM domains d
|
FROM domains d
|
||||||
JOIN nameservers ns ON ns.domain_id = d.id
|
JOIN nameservers ns ON ns.domain_id = d.id
|
||||||
WHERE d.name LIKE include_filter AND d.name NOT LIKE exclude_filter OR d.name = i_origin
|
WHERE d.name LIKE include_filter AND d.name NOT LIKE exclude_filter
|
||||||
ORDER BY d.name
|
ORDER BY d.name
|
||||||
),
|
),
|
||||||
chr(10)
|
chr(10)
|
||||||
|
@ -205,7 +205,8 @@ CREATE TABLE account_activities (
|
||||||
updated_at timestamp without time zone,
|
updated_at timestamp without time zone,
|
||||||
description character varying,
|
description character varying,
|
||||||
creator_str character varying,
|
creator_str character varying,
|
||||||
updator_str character varying
|
updator_str character varying,
|
||||||
|
activity_type character varying
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
@ -2404,8 +2405,8 @@ ALTER SEQUENCE pricelists_id_seq OWNED BY pricelists.id;
|
||||||
|
|
||||||
CREATE TABLE que_jobs (
|
CREATE TABLE que_jobs (
|
||||||
priority smallint DEFAULT 100 NOT NULL,
|
priority smallint DEFAULT 100 NOT NULL,
|
||||||
run_at timestamp with time zone DEFAULT now() NOT NULL,
|
run_at timestamp without time zone DEFAULT '2015-06-30 14:16:50.905537'::timestamp without time zone NOT NULL,
|
||||||
job_id bigint NOT NULL,
|
job_id bigint DEFAULT 0 NOT NULL,
|
||||||
job_class text NOT NULL,
|
job_class text NOT NULL,
|
||||||
args json DEFAULT '[]'::json NOT NULL,
|
args json DEFAULT '[]'::json NOT NULL,
|
||||||
error_count integer DEFAULT 0 NOT NULL,
|
error_count integer DEFAULT 0 NOT NULL,
|
||||||
|
@ -2414,32 +2415,6 @@ CREATE TABLE que_jobs (
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
--
|
|
||||||
-- Name: TABLE que_jobs; Type: COMMENT; Schema: public; Owner: -
|
|
||||||
--
|
|
||||||
|
|
||||||
COMMENT ON TABLE que_jobs IS '3';
|
|
||||||
|
|
||||||
|
|
||||||
--
|
|
||||||
-- Name: que_jobs_job_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
|
||||||
--
|
|
||||||
|
|
||||||
CREATE SEQUENCE que_jobs_job_id_seq
|
|
||||||
START WITH 1
|
|
||||||
INCREMENT BY 1
|
|
||||||
NO MINVALUE
|
|
||||||
NO MAXVALUE
|
|
||||||
CACHE 1;
|
|
||||||
|
|
||||||
|
|
||||||
--
|
|
||||||
-- Name: que_jobs_job_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
|
|
||||||
--
|
|
||||||
|
|
||||||
ALTER SEQUENCE que_jobs_job_id_seq OWNED BY que_jobs.job_id;
|
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Name: registrant_verifications; Type: TABLE; Schema: public; Owner: -; Tablespace:
|
-- Name: registrant_verifications; Type: TABLE; Schema: public; Owner: -; Tablespace:
|
||||||
--
|
--
|
||||||
|
@ -3195,13 +3170,6 @@ ALTER TABLE ONLY people ALTER COLUMN id SET DEFAULT nextval('people_id_seq'::reg
|
||||||
ALTER TABLE ONLY pricelists ALTER COLUMN id SET DEFAULT nextval('pricelists_id_seq'::regclass);
|
ALTER TABLE ONLY pricelists ALTER COLUMN id SET DEFAULT nextval('pricelists_id_seq'::regclass);
|
||||||
|
|
||||||
|
|
||||||
--
|
|
||||||
-- Name: job_id; Type: DEFAULT; Schema: public; Owner: -
|
|
||||||
--
|
|
||||||
|
|
||||||
ALTER TABLE ONLY que_jobs ALTER COLUMN job_id SET DEFAULT nextval('que_jobs_job_id_seq'::regclass);
|
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
|
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
|
||||||
--
|
--
|
||||||
|
@ -3721,14 +3689,6 @@ ALTER TABLE ONLY pricelists
|
||||||
ADD CONSTRAINT pricelists_pkey PRIMARY KEY (id);
|
ADD CONSTRAINT pricelists_pkey PRIMARY KEY (id);
|
||||||
|
|
||||||
|
|
||||||
--
|
|
||||||
-- Name: que_jobs_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
|
|
||||||
--
|
|
||||||
|
|
||||||
ALTER TABLE ONLY que_jobs
|
|
||||||
ADD CONSTRAINT que_jobs_pkey PRIMARY KEY (queue, priority, run_at, job_id);
|
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Name: registrant_verifications_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
|
-- Name: registrant_verifications_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
|
||||||
--
|
--
|
||||||
|
@ -4851,13 +4811,7 @@ INSERT INTO schema_migrations (version) VALUES ('20150612123111');
|
||||||
|
|
||||||
INSERT INTO schema_migrations (version) VALUES ('20150701074344');
|
INSERT INTO schema_migrations (version) VALUES ('20150701074344');
|
||||||
|
|
||||||
INSERT INTO schema_migrations (version) VALUES ('20150703074448');
|
|
||||||
|
|
||||||
INSERT INTO schema_migrations (version) VALUES ('20150703084632');
|
INSERT INTO schema_migrations (version) VALUES ('20150703084632');
|
||||||
|
|
||||||
INSERT INTO schema_migrations (version) VALUES ('20150703090039');
|
INSERT INTO schema_migrations (version) VALUES ('20150706091724');
|
||||||
|
|
||||||
INSERT INTO schema_migrations (version) VALUES ('20150703104149');
|
|
||||||
|
|
||||||
INSERT INTO schema_migrations (version) VALUES ('20150703105159');
|
|
||||||
|
|
||||||
|
|
|
@ -356,6 +356,7 @@ describe 'EPP Domain', epp: true do
|
||||||
a = @registrar1.cash_account.account_activities.last
|
a = @registrar1.cash_account.account_activities.last
|
||||||
a.description.should == "Create #{Domain.last.name}"
|
a.description.should == "Create #{Domain.last.name}"
|
||||||
a.sum.should == -BigDecimal.new('10.0')
|
a.sum.should == -BigDecimal.new('10.0')
|
||||||
|
a.activity_type = AccountActivity::CREATE
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'creates a domain with longer periods' do
|
it 'creates a domain with longer periods' do
|
||||||
|
@ -372,6 +373,7 @@ describe 'EPP Domain', epp: true do
|
||||||
a = @registrar1.cash_account.account_activities.last
|
a = @registrar1.cash_account.account_activities.last
|
||||||
a.description.should == "Create #{Domain.last.name}"
|
a.description.should == "Create #{Domain.last.name}"
|
||||||
a.sum.should == -BigDecimal.new('20.0')
|
a.sum.should == -BigDecimal.new('20.0')
|
||||||
|
a.activity_type = AccountActivity::CREATE
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'creates a domain with longer periods' do
|
it 'creates a domain with longer periods' do
|
||||||
|
@ -388,6 +390,7 @@ describe 'EPP Domain', epp: true do
|
||||||
a = @registrar1.cash_account.account_activities.last
|
a = @registrar1.cash_account.account_activities.last
|
||||||
a.description.should == "Create #{Domain.last.name}"
|
a.description.should == "Create #{Domain.last.name}"
|
||||||
a.sum.should == -BigDecimal.new('30.0')
|
a.sum.should == -BigDecimal.new('30.0')
|
||||||
|
a.activity_type = AccountActivity::CREATE
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not create a domain with invalid period' do
|
it 'does not create a domain with invalid period' do
|
||||||
|
@ -2059,6 +2062,7 @@ describe 'EPP Domain', epp: true do
|
||||||
a = @registrar1.cash_account.account_activities.last
|
a = @registrar1.cash_account.account_activities.last
|
||||||
a.description.should == "Renew #{Domain.last.name}"
|
a.description.should == "Renew #{Domain.last.name}"
|
||||||
a.sum.should == -BigDecimal.new('15.0')
|
a.sum.should == -BigDecimal.new('15.0')
|
||||||
|
a.activity_type = AccountActivity::RENEW
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'renews a domain with 2 year period' do
|
it 'renews a domain with 2 year period' do
|
||||||
|
@ -2089,6 +2093,7 @@ describe 'EPP Domain', epp: true do
|
||||||
a = @registrar1.cash_account.account_activities.last
|
a = @registrar1.cash_account.account_activities.last
|
||||||
a.description.should == "Renew #{Domain.last.name}"
|
a.description.should == "Renew #{Domain.last.name}"
|
||||||
a.sum.should == -BigDecimal.new('35.0')
|
a.sum.should == -BigDecimal.new('35.0')
|
||||||
|
a.activity_type = AccountActivity::CREATE
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'renews a domain with 3 year period' do
|
it 'renews a domain with 3 year period' do
|
||||||
|
@ -2119,6 +2124,7 @@ describe 'EPP Domain', epp: true do
|
||||||
a = @registrar1.cash_account.account_activities.last
|
a = @registrar1.cash_account.account_activities.last
|
||||||
a.description.should == "Renew #{Domain.last.name}"
|
a.description.should == "Renew #{Domain.last.name}"
|
||||||
a.sum.should == -BigDecimal.new('62.0')
|
a.sum.should == -BigDecimal.new('62.0')
|
||||||
|
a.activity_type = AccountActivity::CREATE
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not renew a domain if credit balance low' do
|
it 'does not renew a domain if credit balance low' do
|
||||||
|
|
|
@ -62,6 +62,11 @@ describe BankStatement do
|
||||||
|
|
||||||
AccountActivity.count.should == 1
|
AccountActivity.count.should == 1
|
||||||
|
|
||||||
|
a = AccountActivity.last
|
||||||
|
a.description.should == "Invoice no. #{invoice.number}"
|
||||||
|
a.sum.should == BigDecimal.new('200.0')
|
||||||
|
a.activity_type = AccountActivity::ADD_CREDIT
|
||||||
|
|
||||||
r.cash_account.balance.should == 200.0
|
r.cash_account.balance.should == 200.0
|
||||||
|
|
||||||
bs.bank_transactions.unbinded.count.should == 1
|
bs.bank_transactions.unbinded.count.should == 1
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue