unidom-price 0.2 → 0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +34 -1
- data/app/assets/javascripts/unidom/price/application.js +1 -1
- data/app/assets/stylesheets/unidom/price/application.css +0 -1
- data/app/models/unidom/price/price.rb +23 -1
- data/app/views/layouts/unidom/price/application.html.erb +3 -2
- data/lib/unidom/price/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a7422b3380bb3fa170c26e2001ba508c80f0cae8
|
|
4
|
+
data.tar.gz: 9f885c54e377a75b55349076a35ccc609e495576
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ffa0e8904aa5687e5c4faa4aa2c6915ae8c90a15a3baac070d22ecf667917b602e4df794c2615a2cb9453577364e5519a3f42139d310c68b82f18dc7c75fae5d
|
|
7
|
+
data.tar.gz: 2f1e37d460c02356f5e15aabb2cd8ff7eda7614e9d25058ead43e84d3102305211311d04d69e4a5f4cca8fbca76000e87f415d086f64a03d962c75d56a391602
|
data/README.md
CHANGED
|
@@ -6,6 +6,10 @@
|
|
|
6
6
|
Unidom (UNIfied Domain Object Model) is a series of domain model engines. The Price domain model engine includes Pricing and its relative models.
|
|
7
7
|
Unidom (统一领域对象模型)是一系列的领域模型引擎。价格领域模型引擎包括定价及其相关的模型。
|
|
8
8
|
|
|
9
|
+
## Recent Update
|
|
10
|
+
Check out the [Road Map](ROADMAP.md) to find out what's the next.
|
|
11
|
+
Check out the [Change Log](CHANGELOG.md) to find out what's new.
|
|
12
|
+
|
|
9
13
|
## Usage in Gemfile
|
|
10
14
|
```ruby
|
|
11
15
|
gem 'unidom-price'
|
|
@@ -15,8 +19,37 @@ gem 'unidom-price'
|
|
|
15
19
|
```shell
|
|
16
20
|
rake db:migrate
|
|
17
21
|
```
|
|
22
|
+
The migration versions start with 200203.
|
|
18
23
|
|
|
19
24
|
## Call the Model
|
|
20
25
|
```ruby
|
|
21
|
-
|
|
26
|
+
# Create 2 Prices for the same product
|
|
27
|
+
product = Product.create name: 'iPhone 6S'
|
|
28
|
+
pricer = Person.create name: 'John'
|
|
29
|
+
price = Unidom::Price::Price.create(priced: product,
|
|
30
|
+
pricer: pricer,
|
|
31
|
+
calculation_code: 'AMNT',
|
|
32
|
+
pricing_code: 'BASE',
|
|
33
|
+
charging_code: 'ONCE',
|
|
34
|
+
currency_code: 'RMB',
|
|
35
|
+
amount: 20.00,
|
|
36
|
+
description: 'the normal price',
|
|
37
|
+
instruction: 'Here is a promotion coming soon.',
|
|
38
|
+
opened_at: Time.now)
|
|
39
|
+
promotion_price = Unidom::Price::Price.create(priced: product,
|
|
40
|
+
pricer: pricer,
|
|
41
|
+
calculation_code: 'PCNT',
|
|
42
|
+
pricing_code: 'DSCT',
|
|
43
|
+
charging_code: 'ONCE',
|
|
44
|
+
currency_code: 'RMB',
|
|
45
|
+
amount: 15.00,
|
|
46
|
+
description: 'the promotion price',
|
|
47
|
+
instruction: 'Here is a promotion coming 1 week later.',
|
|
48
|
+
opened_at: Time.now+7.days)
|
|
49
|
+
|
|
50
|
+
# Find the prices.
|
|
51
|
+
prices = Unidom::Price::Price.priced_is(product).priced_by(pricer).charging_coded_as('ONCE').currency_coded_as('RMB').valid_at.alive.first
|
|
52
|
+
|
|
53
|
+
# Price a product
|
|
54
|
+
Unidom::Price::Price.price! product, amount
|
|
22
55
|
```
|
|
@@ -4,6 +4,8 @@ class Unidom::Price::Price < ActiveRecord::Base
|
|
|
4
4
|
|
|
5
5
|
self.table_name = 'unidom_prices'
|
|
6
6
|
|
|
7
|
+
include Unidom::Common::Concerns::ModelExtension
|
|
8
|
+
|
|
7
9
|
validates :amount, presence: true, numericality: { less_than: 1000000000, greater_than: 0 }
|
|
8
10
|
|
|
9
11
|
belongs_to :priced, polymorphic: true
|
|
@@ -12,6 +14,26 @@ class Unidom::Price::Price < ActiveRecord::Base
|
|
|
12
14
|
scope :priced_by, ->(pricer) { where pricer: pricer }
|
|
13
15
|
scope :priced_is, ->(priced) { where priced: priced }
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
def self.price!(priced, amount, pricer = nil, calculation_code = 'AMNT', pricing_code = 'BASE', charging_code = 'ONCE', opened_at = Time.now)
|
|
18
|
+
price = priced_is(priced).calculation_coded_as(calculation_code).pricing_coded_as(pricing_code).charging_coded_as(charging_code).valid_at.alive.first
|
|
19
|
+
if price.present?
|
|
20
|
+
price.amount = amount
|
|
21
|
+
if pricer.present?
|
|
22
|
+
price.pricer = pricer
|
|
23
|
+
else
|
|
24
|
+
price.pricer_id = Unidom::Common::NULL_UUID
|
|
25
|
+
price.pricer_type = ''
|
|
26
|
+
end
|
|
27
|
+
else
|
|
28
|
+
attributes = { priced: priced, amount: amount, calculation_code: calculation_code, pricing_code: pricing_code, charging_code: charging_code, opened_at: opened_at }
|
|
29
|
+
if pricer.present?
|
|
30
|
+
attributes[:pricer] = pricer
|
|
31
|
+
else
|
|
32
|
+
attributes[:pricer_id] = Unidom::Common::NULL_UUID
|
|
33
|
+
attributes[:pricer_type] = ''
|
|
34
|
+
end
|
|
35
|
+
create! attributes
|
|
36
|
+
end
|
|
37
|
+
end
|
|
16
38
|
|
|
17
39
|
end
|
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
<html>
|
|
3
3
|
<head>
|
|
4
4
|
<title>Price</title>
|
|
5
|
-
<%= stylesheet_link_tag
|
|
6
|
-
<%= javascript_include_tag "price/application" %>
|
|
5
|
+
<%= stylesheet_link_tag "price/application", media: "all" %>
|
|
7
6
|
<%= csrf_meta_tags %>
|
|
8
7
|
</head>
|
|
9
8
|
<body>
|
|
10
9
|
|
|
11
10
|
<%= yield %>
|
|
12
11
|
|
|
12
|
+
<%= javascript_include_tag 'price/application' %>
|
|
13
|
+
|
|
13
14
|
</body>
|
|
14
15
|
</html>
|
data/lib/unidom/price/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: unidom-price
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: '0.
|
|
4
|
+
version: '0.3'
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Topbit Du
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-
|
|
11
|
+
date: 2016-07-21 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: unidom-common
|
|
@@ -16,14 +16,14 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '0.
|
|
19
|
+
version: '0.9'
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '0.
|
|
26
|
+
version: '0.9'
|
|
27
27
|
description: Unidom (UNIfied Domain Object Model) is a series of domain model engines.
|
|
28
28
|
The Price domain model engine includes Pricing and its relative models. Unidom (统一领域对象模型)是一系列的领域模型引擎。价格领域模型引擎包括定价及其相关的模型。
|
|
29
29
|
email:
|
|
@@ -67,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
67
67
|
version: '0'
|
|
68
68
|
requirements: []
|
|
69
69
|
rubyforge_project:
|
|
70
|
-
rubygems_version: 2.4
|
|
70
|
+
rubygems_version: 2.6.4
|
|
71
71
|
signing_key:
|
|
72
72
|
specification_version: 4
|
|
73
73
|
summary: Unidom Price Domain Model Engine 价格领域模型引擎
|