{"action":"opened","issue":{"url":"https://api.github.com/repos/anyroadcom/pricing_definition/issues/4","labels_url":"https://api.github.com/repos/anyroadcom/pricing_definition/issues/4/labels{/name}","comments_url":"https://api.github.com/repos/anyroadcom/pricing_definition/issues/4/comments","events_url":"https://api.github.com/repos/anyroadcom/pricing_definition/issues/4/events","html_url":"https://github.com/anyroadcom/pricing_definition/issues/4","id":57926882,"number":4,"title":"Price Modifier: 'priceable_modifier' behavior","user":{"login":"valer-cara","id":2016345,"avatar_url":"https://avatars.githubusercontent.com/u/2016345?v=3","gravatar_id":"","url":"https://api.github.com/users/valer-cara","html_url":"https://github.com/valer-cara","followers_url":"https://api.github.com/users/valer-cara/followers","following_url":"https://api.github.com/users/valer-cara/following{/other_user}","gists_url":"https://api.github.com/users/valer-cara/gists{/gist_id}","starred_url":"https://api.github.com/users/valer-cara/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/valer-cara/subscriptions","organizations_url":"https://api.github.com/users/valer-cara/orgs","repos_url":"https://api.github.com/users/valer-cara/repos","events_url":"https://api.github.com/users/valer-cara/events{/privacy}","received_events_url":"https://api.github.com/users/valer-cara/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/anyroadcom/pricing_definition/labels/feature","name":"feature","color":"fbca04"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-02-17T13:57:08Z","updated_at":"2015-02-17T13:57:08Z","closed_at":null,"body":"> This spec attempts to clarify and further detail the initial draft of the `priceable_modifier` behavior defined in https://github.com/anyroadcom/anyroad/issues/657\r\n\r\n# Definition\r\n\r\nModels that act as `priceable_modifier` __must__ have the following attributes defined:\r\n\r\n| Attribute | Type | Description |\r\n|-------------|--------| ----------------|\r\n| `modifier_type` | string | \"fixed\" or \"percentage\"\r\n| `fixed_amount` | integer | absolute value for the modifier, in cents\r\n| `fixed_currency` | string | currency in which the modifier is applied\r\n| `percentage` | integer | percentage of the price\r\n| `additive` | boolean | indicates the operation type: `true` if modifier adds to the price, `false` otherwise\r\n\r\nA `priceable_modifier` model __must__ also define a `WEIGHT` which will determine the order in which it is applied, when multiple modifiers are being used in the calculation.\r\n\r\n# Declaration\r\n\r\nTo use the `priceable_modifier` functionality in a model, you need to include the `PricingDefinition::Behaviors::PriceableModifier` and declare it as such, while specifying it's configuration options:\r\n\r\n```ruby\r\n```\r\n\r\n# Validations\r\n\r\nWhen applied inside a host model, the `priceable_modifier` behaviour will trigger the following validations: \r\n\r\n* All the required attributes are defined\r\n* `WEIGHT` is defined\r\n\r\n# Serialization\r\nThe behaviour adds the `serialize_modifier` method to the host model. The output will be a `Hash` that includes all the attributes in the definition.\r\n\r\n##### Subtractive\r\n```javascript\r\n{\r\n  label: \"10+ Participants Discount\",\r\n  description: \"Up to 100$ discount on bookings with over 10 participants\",\r\n  modifier_type: \"fixed\",\r\n  fixed_amount: 100,\r\n  fixed_currency: \"usd\",\r\n  percentage: null,\r\n  additive: false\r\n}\r\n```\r\n\r\n##### Aditive\r\n```javascript\r\n{\r\n  label: \"16% VAT\",\r\n  description: \"16% VAT, as the name implies\",\r\n  modifier_type: \"percentage\",\r\n  fixed_amount: null,\r\n  fixed_currency: null,\r\n  percentage: 16,\r\n  additive: true\r\n}\r\n```\r\n\t\r\n\r\n# Example Usage\r\n\r\n```ruby\r\nclass Discount < ActiveRecord::Base\r\n  # attr :modifier_type, :string # ENUM(fixed, percentage)\r\n  # attr :additive, :boolean # false\r\n  # attr :amount, :integer # 40 (%), 10000 (cents)\r\n  WEIGHT = 10\r\n  \r\n  include PricingDefinition::Behaviours::PriceableModifier\r\n  priceable_modifier for: :tour, label: :code, description: :message_to_tourist\r\nend\r\n\r\nclass Tax < ActiveRecord::Base\r\n  # attr :modifier_type, :string # ENUM(fixed, percentage)\r\n  # attr :additive, :boolean # true\r\n  # attr :amount, :integer # 40 (%), 10000 (cents)\r\n  WEIGHT = 5\r\n  \r\n  include PricingDefinition::Behaviours::PriceableModifier\r\n  priceable_modifier for: :tour, label: 'VAT (25%)', description: :legal_notice\r\nend\r\n```\r\n"}}