{"action":"opened","number":4,"pull_request":{"url":"https://api.github.com/repos/anyroadcom/pricing_definition/pulls/4","id":29688517,"html_url":"https://github.com/anyroadcom/pricing_definition/pull/4","diff_url":"https://github.com/anyroadcom/pricing_definition/pull/4.diff","patch_url":"https://github.com/anyroadcom/pricing_definition/pull/4.patch","issue_url":"https://api.github.com/repos/anyroadcom/pricing_definition/issues/4","number":4,"state":"open","locked":false,"title":"Price Modifier: 'priceable_modifier' behavior","user":{"login":"mentos","id":43371,"avatar_url":"https://avatars.githubusercontent.com/u/43371?v=3","gravatar_id":"","url":"https://api.github.com/users/mentos","html_url":"https://github.com/mentos","followers_url":"https://api.github.com/users/mentos/followers","following_url":"https://api.github.com/users/mentos/following{/other_user}","gists_url":"https://api.github.com/users/mentos/gists{/gist_id}","starred_url":"https://api.github.com/users/mentos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mentos/subscriptions","organizations_url":"https://api.github.com/users/mentos/orgs","repos_url":"https://api.github.com/users/mentos/repos","events_url":"https://api.github.com/users/mentos/events{/privacy}","received_events_url":"https://api.github.com/users/mentos/received_events","type":"User","site_admin":false},"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| `fixed` | boolean | `true` if modifier is used for fixed amount, `false` if used for percentage\r\n| `amount` | integer | absolute value for the modifier, in cents if type is `fixed` or percents if `percentage`\r\n| `currency` | string | currency in which the modifier is applied. Used only when type is `fixed`\r\n| `additive` | boolean | indicates the operation type: `true` if modifier adds to the price, `false` otherwise\r\n\r\n# Configuration\r\nWhen declaring the `priceable_modifier` behaviour on a model, the following configuration options are available:\r\n\r\n* `label` - String or Symbol. If string, use that as the label for the modifier. If symbol, delegate to the indicated method to retrieve the value\r\n* `description` - Same as above, for description\r\n* `for` - Symbol or Array. Indicate the base priceable(s) that the modifier applies to.\r\n* `weight` - Integer which will determine the order in which it is applied, when multiple modifiers are being used in the calculation.\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##### Structural validations\r\n* All the required attributes are defined\r\n* `label`, `description` & `weight` options are always is defined\r\n\r\n##### Instance validations\r\n* `amount` between 0 and 100 if `type = \"percentage\"`\r\n* `amount` greater than 0 if `type = \"fixed\"`\r\n* `currency` not empty if `type = \"fixed\"`\r\n* `label`, `description`, `additive` not null\r\n* `label` and `description` - check that method exists if symbols were provided in the config\r\n\r\n# Serialization\r\nThe behaviour adds the `for_calculator` method to the host model. The output will be a `Hash` (or `HashWithIndifferentAccess`) 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  fixed: true,\r\n  amount: 100,\r\n  currency: \"usd\",\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  fixed: false,\r\n  amount: 16,\r\n  currency: null,\r\n  additive: true\r\n}\r\n```\r\n\r\n# Usage\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  include PricingDefinition::Behaviours::PriceableModifier\r\n  priceable_modifier for: :tour, label: :code, description: :message_to_tourist\r\n```\r\n\r\n# Example\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```","created_at":"2015-02-20T11:20:50Z","updated_at":"2015-02-20T11:20:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"dd832d634d1599b7e8e4354677710c0e3688dc1d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/anyroadcom/pricing_definition/pulls/4/commits","review_comments_url":"https://api.github.com/repos/anyroadcom/pricing_definition/pulls/4/comments","review_comment_url":"https://api.github.com/repos/anyroadcom/pricing_definition/pulls/comments/{number}","comments_url":"https://api.github.com/repos/anyroadcom/pricing_definition/issues/4/comments","statuses_url":"https://api.github.com/repos/anyroadcom/pricing_definition/statuses/1dffa235f83967ec4af3c191e73eedef3a55ca0a","head":{"label":"4-priceable-modifiers-behaviour","ref":"4-priceable-modifiers-behaviour","sha":"1dffa235f83967ec4af3c191e73eedef3a55ca0a","user":{"login":"anyroadcom","id":7911613,"avatar_url":"https://avatars.githubusercontent.com/u/7911613?v=3","gravatar_id":"","url":"https://api.github.com/users/anyroadcom","html_url":"https://github.com/anyroadcom","followers_url":"https://api.github.com/users/anyroadcom/followers","following_url":"https://api.github.com/users/anyroadcom/following{/other_user}","gists_url":"https://api.github.com/users/anyroadcom/gists{/gist_id}","starred_url":"https://api.github.com/users/anyroadcom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anyroadcom/subscriptions","organizations_url":"https://api.github.com/users/anyroadcom/orgs","repos_url":"https://api.github.com/users/anyroadcom/repos","events_url":"https://api.github.com/users/anyroadcom/events{/privacy}","received_events_url":"https://api.github.com/users/anyroadcom/received_events","type":"Organization","site_admin":false},"repo":{"id":30598056,"name":"pricing_definition","full_name":"anyroadcom/pricing_definition","owner":{"login":"anyroadcom","id":7911613,"avatar_url":"https://avatars.githubusercontent.com/u/7911613?v=3","gravatar_id":"","url":"https://api.github.com/users/anyroadcom","html_url":"https://github.com/anyroadcom","followers_url":"https://api.github.com/users/anyroadcom/followers","following_url":"https://api.github.com/users/anyroadcom/following{/other_user}","gists_url":"https://api.github.com/users/anyroadcom/gists{/gist_id}","starred_url":"https://api.github.com/users/anyroadcom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anyroadcom/subscriptions","organizations_url":"https://api.github.com/users/anyroadcom/orgs","repos_url":"https://api.github.com/users/anyroadcom/repos","events_url":"https://api.github.com/users/anyroadcom/events{/privacy}","received_events_url":"https://api.github.com/users/anyroadcom/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/anyroadcom/pricing_definition","description":"Waka waka... money","fork":false,"url":"https://api.github.com/repos/anyroadcom/pricing_definition","forks_url":"https://api.github.com/repos/anyroadcom/pricing_definition/forks","keys_url":"https://api.github.com/repos/anyroadcom/pricing_definition/keys{/key_id}","collaborators_url":"https://api.github.com/repos/anyroadcom/pricing_definition/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/anyroadcom/pricing_definition/teams","hooks_url":"https://api.github.com/repos/anyroadcom/pricing_definition/hooks","issue_events_url":"https://api.github.com/repos/anyroadcom/pricing_definition/issues/events{/number}","events_url":"https://api.github.com/repos/anyroadcom/pricing_definition/events","assignees_url":"https://api.github.com/repos/anyroadcom/pricing_definition/assignees{/user}","branches_url":"https://api.github.com/repos/anyroadcom/pricing_definition/branches{/branch}","tags_url":"https://api.github.com/repos/anyroadcom/pricing_definition/tags","blobs_url":"https://api.github.com/repos/anyroadcom/pricing_definition/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/anyroadcom/pricing_definition/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/anyroadcom/pricing_definition/git/refs{/sha}","trees_url":"https://api.github.com/repos/anyroadcom/pricing_definition/git/trees{/sha}","statuses_url":"https://api.github.com/repos/anyroadcom/pricing_definition/statuses/{sha}","languages_url":"https://api.github.com/repos/anyroadcom/pricing_definition/languages","stargazers_url":"https://api.github.com/repos/anyroadcom/pricing_definition/stargazers","contributors_url":"https://api.github.com/repos/anyroadcom/pricing_definition/contributors","subscribers_url":"https://api.github.com/repos/anyroadcom/pricing_definition/subscribers","subscription_url":"https://api.github.com/repos/anyroadcom/pricing_definition/subscription","commits_url":"https://api.github.com/repos/anyroadcom/pricing_definition/commits{/sha}","git_commits_url":"https://api.github.com/repos/anyroadcom/pricing_definition/git/commits{/sha}","comments_url":"https://api.github.com/repos/anyroadcom/pricing_definition/comments{/number}","issue_comment_url":"https://api.github.com/repos/anyroadcom/pricing_definition/issues/comments/{number}","contents_url":"https://api.github.com/repos/anyroadcom/pricing_definition/contents/{+path}","compare_url":"https://api.github.com/repos/anyroadcom/pricing_definition/compare/{base}...{head}","merges_url":"https://api.github.com/repos/anyroadcom/pricing_definition/merges","archive_url":"https://api.github.com/repos/anyroadcom/pricing_definition/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/anyroadcom/pricing_definition/downloads","issues_url":"https://api.github.com/repos/anyroadcom/pricing_definition/issues{/number}","pulls_url":"https://api.github.com/repos/anyroadcom/pricing_definition/pulls{/number}","milestones_url":"https://api.github.com/repos/anyroadcom/pricing_definition/milestones{/number}","notifications_url":"https://api.github.com/repos/anyroadcom/pricing_definition/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/anyroadcom/pricing_definition/labels{/name}","releases_url":"https://api.github.com/repos/anyroadcom/pricing_definition/releases{/id}","created_at":"2015-02-10T15:17:06Z","updated_at":"2015-02-20T11:16:25Z","pushed_at":"2015-02-20T11:19:06Z","git_url":"git://github.com/anyroadcom/pricing_definition.git","ssh_url":"git@github.com:anyroadcom/pricing_definition.git","clone_url":"https://github.com/anyroadcom/pricing_definition.git","svn_url":"https://github.com/anyroadcom/pricing_definition","homepage":null,"size":151,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":4,"forks":0,"open_issues":4,"watchers":0,"default_branch":"master"}},"base":{"label":"master","ref":"master","sha":"5c5114bade8b9623fbb86d15cc1794952e7fce42","user":{"login":"anyroadcom","id":7911613,"avatar_url":"https://avatars.githubusercontent.com/u/7911613?v=3","gravatar_id":"","url":"https://api.github.com/users/anyroadcom","html_url":"https://github.com/anyroadcom","followers_url":"https://api.github.com/users/anyroadcom/followers","following_url":"https://api.github.com/users/anyroadcom/following{/other_user}","gists_url":"https://api.github.com/users/anyroadcom/gists{/gist_id}","starred_url":"https://api.github.com/users/anyroadcom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anyroadcom/subscriptions","organizations_url":"https://api.github.com/users/anyroadcom/orgs","repos_url":"https://api.github.com/users/anyroadcom/repos","events_url":"https://api.github.com/users/anyroadcom/events{/privacy}","received_events_url":"https://api.github.com/users/anyroadcom/received_events","type":"Organization","site_admin":false},"repo":{"id":30598056,"name":"pricing_definition","full_name":"anyroadcom/pricing_definition","owner":{"login":"anyroadcom","id":7911613,"avatar_url":"https://avatars.githubusercontent.com/u/7911613?v=3","gravatar_id":"","url":"https://api.github.com/users/anyroadcom","html_url":"https://github.com/anyroadcom","followers_url":"https://api.github.com/users/anyroadcom/followers","following_url":"https://api.github.com/users/anyroadcom/following{/other_user}","gists_url":"https://api.github.com/users/anyroadcom/gists{/gist_id}","starred_url":"https://api.github.com/users/anyroadcom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anyroadcom/subscriptions","organizations_url":"https://api.github.com/users/anyroadcom/orgs","repos_url":"https://api.github.com/users/anyroadcom/repos","events_url":"https://api.github.com/users/anyroadcom/events{/privacy}","received_events_url":"https://api.github.com/users/anyroadcom/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/anyroadcom/pricing_definition","description":"Waka waka... money","fork":false,"url":"https://api.github.com/repos/anyroadcom/pricing_definition","forks_url":"https://api.github.com/repos/anyroadcom/pricing_definition/forks","keys_url":"https://api.github.com/repos/anyroadcom/pricing_definition/keys{/key_id}","collaborators_url":"https://api.github.com/repos/anyroadcom/pricing_definition/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/anyroadcom/pricing_definition/teams","hooks_url":"https://api.github.com/repos/anyroadcom/pricing_definition/hooks","issue_events_url":"https://api.github.com/repos/anyroadcom/pricing_definition/issues/events{/number}","events_url":"https://api.github.com/repos/anyroadcom/pricing_definition/events","assignees_url":"https://api.github.com/repos/anyroadcom/pricing_definition/assignees{/user}","branches_url":"https://api.github.com/repos/anyroadcom/pricing_definition/branches{/branch}","tags_url":"https://api.github.com/repos/anyroadcom/pricing_definition/tags","blobs_url":"https://api.github.com/repos/anyroadcom/pricing_definition/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/anyroadcom/pricing_definition/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/anyroadcom/pricing_definition/git/refs{/sha}","trees_url":"https://api.github.com/repos/anyroadcom/pricing_definition/git/trees{/sha}","statuses_url":"https://api.github.com/repos/anyroadcom/pricing_definition/statuses/{sha}","languages_url":"https://api.github.com/repos/anyroadcom/pricing_definition/languages","stargazers_url":"https://api.github.com/repos/anyroadcom/pricing_definition/stargazers","contributors_url":"https://api.github.com/repos/anyroadcom/pricing_definition/contributors","subscribers_url":"https://api.github.com/repos/anyroadcom/pricing_definition/subscribers","subscription_url":"https://api.github.com/repos/anyroadcom/pricing_definition/subscription","commits_url":"https://api.github.com/repos/anyroadcom/pricing_definition/commits{/sha}","git_commits_url":"https://api.github.com/repos/anyroadcom/pricing_definition/git/commits{/sha}","comments_url":"https://api.github.com/repos/anyroadcom/pricing_definition/comments{/number}","issue_comment_url":"https://api.github.com/repos/anyroadcom/pricing_definition/issues/comments/{number}","contents_url":"https://api.github.com/repos/anyroadcom/pricing_definition/contents/{+path}","compare_url":"https://api.github.com/repos/anyroadcom/pricing_definition/compare/{base}...{head}","merges_url":"https://api.github.com/repos/anyroadcom/pricing_definition/merges","archive_url":"https://api.github.com/repos/anyroadcom/pricing_definition/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/anyroadcom/pricing_definition/downloads","issues_url":"https://api.github.com/repos/anyroadcom/pricing_definition/issues{/number}","pulls_url":"https://api.github.com/repos/anyroadcom/pricing_definition/pulls{/number}","milestones_url":"https://api.github.com/repos/anyroadcom/pricing_definition/milestones{/number}","notifications_url":"https://api.github.com/repos/anyroadcom/pricing_definition/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/anyroadcom/pricing_definition/labels{/name}","releases_url":"https://api.github.com/repos/anyroadcom/pricing_definition/releases{/id}","created_at":"2015-02-10T15:17:06Z","updated_at":"2015-02-20T11:16:25Z","pushed_at":"2015-02-20T11:19:06Z","git_url":"git://github.com/anyroadcom/pricing_definition.git","ssh_url":"git@github.com:anyroadcom/pricing_definition.git","clone_url":"https://github.com/anyroadcom/pricing_definition.git","svn_url":"https://github.com/anyroadcom/pricing_definition","homepage":null,"size":151,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":4,"forks":0,"open_issues":4,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/anyroadcom/pricing_definition/pulls/4"},"html":{"href":"https://github.com/anyroadcom/pricing_definition/pull/4"},"issue":{"href":"https://api.github.com/repos/anyroadcom/pricing_definition/issues/4"},"comments":{"href":"https://api.github.com/repos/anyroadcom/pricing_definition/issues/4/comments"},"review_comments":{"href":"https://api.github.com/repos/anyroadcom/pricing_definition/pulls/4/comments"},"review_comment":{"href":"https://api.github.com/repos/anyroadcom/pricing_definition/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/anyroadcom/pricing_definition/pulls/4/commits"},"statuses":{"href":"https://api.github.com/repos/anyroadcom/pricing_definition/statuses/1dffa235f83967ec4af3c191e73eedef3a55ca0a"}},"merged":false,"mergeable":true,"mergeable_state":"clean","merged_by":null,"comments":0,"review_comments":0,"commits":1,"additions":370,"deletions":3,"changed_files":8}}