Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
shotengai
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
shotengai
Commits
02d394bb
Commit
02d394bb
authored
Sep 15, 2017
by
ivan Lan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update order about seq & amount
parent
736c4a68
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
12 deletions
+41
-12
1_create_shotengai_products_and_orders.rb
db/migrate/1_create_shotengai_products_and_orders.rb
+3
-2
order.rb
lib/shotengai/order.rb
+19
-5
shotengai_orders.rb
spec/factories/shotengai_orders.rb
+8
-2
models_spec.rb
spec/shotengai/models_spec.rb
+11
-3
No files found.
db/migrate/1_create_shotengai_products_and_orders.rb
View file @
02d394bb
...
...
@@ -51,13 +51,14 @@ class CreateShotengaiProductsAndOrders < ActiveRecord::Migration[5.1]
def
create_order
create_table
:shotengai_orders
do
|
t
|
t
.
integer
:seq
t
.
string
:seq
t
.
string
:address
t
.
decimal
:amount
,
precision:
9
,
scale:
2
t
.
datetime
:pay_time
t
.
datetime
:delivery_time
t
.
datetime
:receipt_time
t
.
string
:delivery_way
t
.
integer
:delivery_cost
t
.
integer
:delivery_cost
,
default:
0
t
.
text
:merchant_remark
t
.
string
:mark
# merchant mark, like red, blue ..
t
.
text
:customer_remark
...
...
lib/shotengai/order.rb
View file @
02d394bb
...
...
@@ -4,13 +4,14 @@ module Shotengai
# Table name: shotengai_orders
#
# id :integer not null, primary key
# seq :
integer
# seq :
string(255)
# address :string(255)
# amount :decimal(9, 2)
# pay_time :datetime
# delivery_time :datetime
# receipt_time :datetime
# delivery_way :string(255)
# delivery_cost :
string(255
)
# delivery_cost :
integer default(0
)
# merchant_remark :text(65535)
# mark :string(255)
# customer_remark :text(65535)
...
...
@@ -35,12 +36,14 @@ module Shotengai
default_scope
{
where
.
not
(
status:
'cart'
)
}
scope
:status_is
,
->
(
status
)
{
where
(
status
.
blank?
.!
&&
{
status:
status
})
}
after_create
:set_seq
include
AASM_DLC
aasm
column: :status
do
state
:unpaid
,
initial:
true
state
:paid
,
:delivering
,
:received
,
:canceled
,
:evaluated
event
:pay
,
before:
[
:fill_snapshot
,
:cut_stock
,
:set_pay_time
]
do
event
:pay
,
before:
[
:
set_amount
,
:
fill_snapshot
,
:cut_stock
,
:set_pay_time
]
do
transitions
from: :unpaid
,
to: :paid
end
...
...
@@ -95,11 +98,22 @@ module Shotengai
update!
(
receipt_time:
Time
.
now
)
end
def
total_price
def
set_amount
self
.
update!
(
amount:
product_amount
+
delivery_cost
)
end
def
set_seq
timestamp
=
Time
.
now
.
strftime
(
"%Y%m%d-%H%M"
)
no_length
=
4
no
=
(
"%0
#{
no_length
}
d"
%
id
).
last
no_length
self
.
update!
(
seq:
"
#{
timestamp
}
-
#{
no
}
}"
)
end
def
product_amount
snapshots
.
sum
(
&
:total_price
)
end
def
total_original_price
def
product_original_amount
snapshots
.
sum
(
&
:total_original_price
)
end
...
...
spec/factories/shotengai_orders.rb
View file @
02d394bb
...
...
@@ -3,13 +3,14 @@
# Table name: shotengai_orders
#
# id :integer not null, primary key
# seq :
integer
# seq :
string(255)
# address :string(255)
# amount :decimal(9, 2)
# pay_time :datetime
# delivery_time :datetime
# receipt_time :datetime
# delivery_way :string(255)
# delivery_cost :
string(255
)
# delivery_cost :
integer default(0
)
# merchant_remark :text(65535)
# mark :string(255)
# customer_remark :text(65535)
...
...
@@ -21,6 +22,11 @@
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_shotengai_orders_on_buyer_id_and_buyer_type (buyer_id,buyer_type)
# index_shotengai_orders_on_type (type)
#
FactoryGirl
.
define
do
factory
:shotengai_order
do
...
...
spec/shotengai/models_spec.rb
View file @
02d394bb
...
...
@@ -176,16 +176,24 @@ RSpec.describe 'Shotengai Models' do
it
'Methods'
do
# total_price
expect
(
@order
.
total_price
).
to
eq
(
@snapshot_1
.
total_price
+
@snapshot_2
.
total_price
)
expect
(
@order
.
total_original_price
).
to
eq
(
@snapshot_1
.
total_original_price
+
@snapshot_2
.
total_original_price
)
expect
(
@order
.
product_amount
).
to
eq
(
@snapshot_1
.
total_price
+
@snapshot_2
.
total_price
)
expect
(
@order
.
product_original_amount
).
to
eq
(
@snapshot_1
.
total_original_price
+
@snapshot_2
.
total_original_price
)
end
it
'About state machine'
do
expect
(
@snapshot_1
.
reload
.
attributes
.
values
.
include?
(
nil
)).
to
eq
(
true
)
@order
.
pay!
expect
(
@order
.
seq
).
not_to
be_nil
expect
(
@order
.
reload
.
pay_time
).
not_to
be_nil
# set amount
expect
(
@order
.
reload
.
amount
).
to
eq
(
@order
.
snapshots
.
map
(
&
:total_price
).
reduce
(:
+
)
+
@order
.
delivery_cost
)
# cannot edit or destroy snapshot unless the order is unpaid
# TODO:
# expect {
# @order.snapshots.first.destroy!
# }.to raise_error(ActiveRecord::RecordInvalid)
# copy snapshot info from series
expect
(
@snapshot_1
.
reload
.
attributes
.
values
.
-
([
:revised_amount
])
.
include?
(
nil
)).
to
eq
(
false
)
expect
(
@snapshot_1
.
reload
.
attributes
.
except
(
'revised_amount'
).
values
.
include?
(
nil
)).
to
eq
(
false
)
@order
.
send_out!
# set delivery_time
expect
(
@order
.
reload
.
delivery_time
).
not_to
be_nil
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment