1 Star 0 Fork 0

Unidom / Unidom Order

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Unidom Order 订单领域模型引擎

Documentation License

Gem Version Dependency Status

Unidom (UNIfied Domain Object Model) is a series of domain model engines. The Order domain model engine includes Order, Order Item, and Order Adjustment models. Unidom (统一领域对象模型)是一系列的领域模型引擎。订单领域模型引擎包括订单、订单项和订单调整的模型。

Recent Update

Check out the Road Map to find out what's the next. Check out the Change Log to find out what's new.

Usage in Gemfile

gem 'unidom-order'

Run the Database Migration

rake db:migrate

The migration versions start with 200206.

Call the Model

lady = Person.create name: 'Ann'
shop = Shop.create   name: 'WalMart'

order = Unidom::Order::Order.create(placer: lady,
  taker:       shop,
  number:      'ZBCDEFGHIJKL',
  instruction: 'Please mail to me as soon as possible.',
  description: 'gifts for my kids',
  opened_at:   Time.now)

game = Product.create name: 'World War II'
ball = Product.create name: 'Basketball'

order.items.create(ordered: game,
  placer:          lady,
  ordinal:         1,
  unit_price:      19.99,
  quantity:        1,
  purchase_amount: 19.99,
  subtotal_amount: 23.98,
  instruction:     'We need the 2nd version.',
  description:     'video game',
  opened_at:       Time.now)
order.items.create(ordered: ball,
  placer:          lady,
  ordinal:         2,
  unit_price:      35.00,
  quantity:        2,
  purchase_amount: 70.00,
  subtotal_amount: 70.00,
  instruction:     'We need 2 balls.',
  description:     'video game',
  opened_at:       Time.now)

order.adjustments.create(
  adjustment_factor_code: 'FRGT',
  calculation_code:       'AMNT',
  amount:                 5.00,
  instruction:            'arrive in 3 days',
  description:            'freight',
  opened_at:              Time.now)
order.items.first.create(
  adjustment_factor_code: 'TAXF',
  calculation_code:       'PCNT',
  amount:                 15.00,
  instruction:            'tax rate is 15%',
  description:            'tax',
  opened_at:              Time.now)

order.purchase_amount  = order.items.sum('purchase_amount')
order.aggregate_amount = order.items.sum('subtotal_amount')+order.adjustments.sum('amount')
order.save

order = Unidom::Order::Order.where(number: 'ZBCDEFGHIJKL').first
order.items       # Order Items
order.adjustments # Order Adjustments

Unidom::Order::OrderItem.order! product, of: order, unit_price: 1080.00, quantity: 2
# Add the given product into the given order

Unidom::Order::OrderAdjustment.adjust! order, amount: 20, due_to: 'DSCT', opened_at: Time.now
# Add the given adjustment into the given order

Include the Concerns

include Unidom::Order::AsAdjusted
include Unidom::Order::AsOrderPlacer
include Unidom::Order::AsOrderTaker

As Adjusted concern

The As Adjusted concern do the following tasks for the includer automatically:

  1. Define the has_many :adjustments macro as: has_many :adjustments, class_name: 'Unidom::Order::OrderAdjustment', as: :adjusted

  2. Define the #is_adjusted! method as: is_adjusted!(amount, due_to: 'FRGT', at: Time.now)

  3. Define the #is_adjusted? method as: is_adjusted?(due_to: 'FRGT', at: Time.now)

As Order Placer concern

The As Order Placer concern do the following tasks for the includer automatically:

  1. Define the has_many :placed_orders macro as: has_many :placed_orders, class_name: 'Unidom::Order::Order', as: :placer

As Order Taker concern

The As Order Taker concern do the following tasks for the includer automatically:

  1. Define the has_many :taken_orders macro as: has_many :taken_orders, class_name: 'Unidom::Order::Order', as: :taker

Enum codes

Adjustment Factor enum code 调整因素

Unidom::Order::AdjustmentFactor::DISCOUNT_ADJUSTMENT           # 折扣调整
Unidom::Order::AdjustmentFactor::SURCHARGE_ADJUSTMENT          # 额外费调整
Unidom::Order::AdjustmentFactor::SALES_TAX                     # 销售税
Unidom::Order::AdjustmentFactor::SHIPPING_AND_HANDLING_CHARGES # 装运和处理费
Unidom::Order::AdjustmentFactor::FEE                           # 手续费
Unidom::Order::AdjustmentFactor::MISCELLANEOUS_CHARGE          # 杂项收费

Disable the Model & Migration

If you only need the app components other than models, the migrations should be neglected, and the models should not be loaded.

# config/initializers/unidom.rb
Unidom::Common.configure do |options|

  options[:neglected_namespaces] = %w{
    Unidom::Order
  }

end

RSpec examples

RSpec example manifest (run automatically)

# spec/models/unidom_spec.rb
require 'unidom/order/models_rspec'

# spec/types/unidom_spec.rb
require 'unidom/order/types_rspec'

# spec/validators/unidom_spec.rb
require 'unidom/order/validators_rspec'

RSpec shared examples (to be integrated)

# lib/unidom.rb
Unidom::Party::Person.class_eval do

  include Unidom::Order::Concerns::AsOrderPlacer

end

Unidom::Party::Shop.class_eval do

  include Unidom::Order::Concerns::AsOrderTaker

end

# spec/support/unidom_rspec_shared_examples.rb
require 'unidom/order/rspec_shared_examples'

# spec/models/unidom/party/person_spec.rb
describe Unidom::Party::Person, type: :model do

  it_behaves_like 'Unidom::Order::Concerns::AsOrderPlacer', model_attributes

end

# spec/models/unidom/party/shop_spec.rb
describe Unidom::Party::Shop, type: :model do

  it_behaves_like 'Unidom::Order::Concerns::AsOrderTaker', model_attributes

end
Copyright 2015 Topbit Du Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

The Order domain model engine includes Order, Order Item, and Order Adjustment models. 订单领域模型引擎包括订单、订单项和订单调整的模型。 展开 收起
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/Unidom/unidom-order.git
git@gitee.com:Unidom/unidom-order.git
Unidom
unidom-order
Unidom Order
master

搜索帮助