{"action":"created","comment":{"url":"https://api.github.com/repos/Parsimotion/syncer-andreani/pulls/comments/78612082","id":78612082,"diff_hunk":"@@ -0,0 +1,72 @@\n+_ = require(\"lodash\")\n+moment = require('moment')\n+similarity = require('similarity')\n+Queue = require('../services/queue')\n+Location = include(\"api/location/location.model\")\n+Promise = require(\"bluebird\")\n+config = include('config/environment')\n+module.exports =\n+\n+class LogisticaShipmentCreator\n+  constructor: (@user) ->\n+    @queue = Queue.instance()\n+\n+  createShipment: (accountId, contact, product, line) =>\n+    @_validateUser()\n+    @buildShipment(accountId, contact, product, line).then (shipment) =>\n+      @queue.push config.azure.logisticaShipmentsQueue, shipment\n+      shipment.shipmentId\n+\n+  buildShipment: (accountId, contact, product, line) =>\n+    @_validateProduct product\n+    @_validateContact contact\n+\n+    Promise.all [@_getOrInitializeShipmentId(), @_getLocation(contact.location)]\n+    .then ([lastShipmentId, deliveryLocation]) =>\n+      shipmentId: lastShipmentId\n+      andreaniAccount: accountId\n+      deliveryNote: product.integrations[0].integrationId\n+      date: moment().format(\"YYYYMMDD\")\n+      contactPerson: contact.contactPerson\n+      street: \"#{contact.location.streetName} #{contact.location.streetNumber}\"\n+      city: deliveryLocation.city\n+      zipCode: contact.location.zipCode\n+      pieces: product.dimensions.pieces * line.quantity\n+      weight: @_calculateWeight product.dimensions\n+      volume: @_calculateVolume product.dimensions\n+      insuranceValue: line.price * line.quantity\n+      pieceKey: @_buildPieceKey deliveryLocation, lastShipmentId\n+\n+  _getOrInitializeShipmentId: =>\n+    if not @user.logistica.lastShipmentId","path":"server/domain/logisticaShipmentCreator.coffee","position":41,"original_position":41,"commit_id":"2b3a212cd8d91d055675c96a19b33dea65f1fc17","original_commit_id":"2b3a212cd8d91d055675c96a19b33dea65f1fc17","user":{"login":"NahuelP","id":7072017,"avatar_url":"https://avatars.githubusercontent.com/u/7072017?v=3","gravatar_id":"","url":"https://api.github.com/users/NahuelP","html_url":"https://github.com/NahuelP","followers_url":"https://api.github.com/users/NahuelP/followers","following_url":"https://api.github.com/users/NahuelP/following{/other_user}","gists_url":"https://api.github.com/users/NahuelP/gists{/gist_id}","starred_url":"https://api.github.com/users/NahuelP/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NahuelP/subscriptions","organizations_url":"https://api.github.com/users/NahuelP/orgs","repos_url":"https://api.github.com/users/NahuelP/repos","events_url":"https://api.github.com/users/NahuelP/events{/privacy}","received_events_url":"https://api.github.com/users/NahuelP/received_events","type":"User","site_admin":false},"body":"Acá faltaría un `?` al final (no necesario) :P","created_at":"2016-09-13T18:00:35Z","updated_at":"2016-09-13T18:00:35Z","html_url":"https://github.com/Parsimotion/syncer-andreani/pull/25#discussion_r78612082","pull_request_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/pulls/25","_links":{"self":{"href":"https://api.github.com/repos/Parsimotion/syncer-andreani/pulls/comments/78612082"},"html":{"href":"https://github.com/Parsimotion/syncer-andreani/pull/25#discussion_r78612082"},"pull_request":{"href":"https://api.github.com/repos/Parsimotion/syncer-andreani/pulls/25"}}},"pull_request":{"url":"https://api.github.com/repos/Parsimotion/syncer-andreani/pulls/25","id":84206151,"html_url":"https://github.com/Parsimotion/syncer-andreani/pull/25","diff_url":"https://github.com/Parsimotion/syncer-andreani/pull/25.diff","patch_url":"https://github.com/Parsimotion/syncer-andreani/pull/25.patch","issue_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/issues/25","number":25,"state":"open","locked":false,"title":"Poder crear shipments de logistica","user":{"login":"Gustrucco","id":3957637,"avatar_url":"https://avatars.githubusercontent.com/u/3957637?v=3","gravatar_id":"","url":"https://api.github.com/users/Gustrucco","html_url":"https://github.com/Gustrucco","followers_url":"https://api.github.com/users/Gustrucco/followers","following_url":"https://api.github.com/users/Gustrucco/following{/other_user}","gists_url":"https://api.github.com/users/Gustrucco/gists{/gist_id}","starred_url":"https://api.github.com/users/Gustrucco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Gustrucco/subscriptions","organizations_url":"https://api.github.com/users/Gustrucco/orgs","repos_url":"https://api.github.com/users/Gustrucco/repos","events_url":"https://api.github.com/users/Gustrucco/events{/privacy}","received_events_url":"https://api.github.com/users/Gustrucco/received_events","type":"User","site_admin":false},"body":"[Finishes #120949813](https://www.pivotaltracker.com/story/show/120949813)\r\n\r\n- Agrego un `maxCorreoWeight` en el user.\r\n- Si el peso aforado (volumetricWeight) es mayor a ese peso creo un shipment de andreani logística, caso contrario continua el flujo regular.\r\n- Crear un shipment de andreani logística implica crear un mensaje en una cola con ese mismo shipment para luego (en la próxima story) construir el archivo a enviar vía FTP.\r\n- Falta cargar en la base de datos las locations. Yo las tengo en un csv y hay que hacer un mongo import. \r\n- Para buscar la localidad correcta se hace lo siguiente. Si tengo una sola localidad en mongo con el zipCode del contact pongo esa ciudad. en caso contrario busco la que más se asemeje a la city del contact a través de un npm que se llama `similarity`","created_at":"2016-09-06T22:17:23Z","updated_at":"2016-09-13T18:00:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"00afec768e12a4e277c02175d5523186545a82d0","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/pulls/25/commits","review_comments_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/pulls/25/comments","review_comment_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/issues/25/comments","statuses_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/statuses/2b3a212cd8d91d055675c96a19b33dea65f1fc17","head":{"label":"Parsimotion:poder-crear-shipments-de-logistica","ref":"poder-crear-shipments-de-logistica","sha":"2b3a212cd8d91d055675c96a19b33dea65f1fc17","user":{"login":"Parsimotion","id":8582957,"avatar_url":"https://avatars.githubusercontent.com/u/8582957?v=3","gravatar_id":"","url":"https://api.github.com/users/Parsimotion","html_url":"https://github.com/Parsimotion","followers_url":"https://api.github.com/users/Parsimotion/followers","following_url":"https://api.github.com/users/Parsimotion/following{/other_user}","gists_url":"https://api.github.com/users/Parsimotion/gists{/gist_id}","starred_url":"https://api.github.com/users/Parsimotion/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Parsimotion/subscriptions","organizations_url":"https://api.github.com/users/Parsimotion/orgs","repos_url":"https://api.github.com/users/Parsimotion/repos","events_url":"https://api.github.com/users/Parsimotion/events{/privacy}","received_events_url":"https://api.github.com/users/Parsimotion/received_events","type":"Organization","site_admin":false},"repo":{"id":41693841,"name":"syncer-andreani","full_name":"Parsimotion/syncer-andreani","owner":{"login":"Parsimotion","id":8582957,"avatar_url":"https://avatars.githubusercontent.com/u/8582957?v=3","gravatar_id":"","url":"https://api.github.com/users/Parsimotion","html_url":"https://github.com/Parsimotion","followers_url":"https://api.github.com/users/Parsimotion/followers","following_url":"https://api.github.com/users/Parsimotion/following{/other_user}","gists_url":"https://api.github.com/users/Parsimotion/gists{/gist_id}","starred_url":"https://api.github.com/users/Parsimotion/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Parsimotion/subscriptions","organizations_url":"https://api.github.com/users/Parsimotion/orgs","repos_url":"https://api.github.com/users/Parsimotion/repos","events_url":"https://api.github.com/users/Parsimotion/events{/privacy}","received_events_url":"https://api.github.com/users/Parsimotion/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Parsimotion/syncer-andreani","description":"Syncer for Andreani","fork":false,"url":"https://api.github.com/repos/Parsimotion/syncer-andreani","forks_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/forks","keys_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/teams","hooks_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/hooks","issue_events_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/issues/events{/number}","events_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/events","assignees_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/assignees{/user}","branches_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/branches{/branch}","tags_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/tags","blobs_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/git/refs{/sha}","trees_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/statuses/{sha}","languages_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/languages","stargazers_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/stargazers","contributors_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/contributors","subscribers_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/subscribers","subscription_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/subscription","commits_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/commits{/sha}","git_commits_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/git/commits{/sha}","comments_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/comments{/number}","issue_comment_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/issues/comments{/number}","contents_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/contents/{+path}","compare_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/merges","archive_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/downloads","issues_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/issues{/number}","pulls_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/pulls{/number}","milestones_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/milestones{/number}","notifications_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/labels{/name}","releases_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/releases{/id}","deployments_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/deployments","created_at":"2015-08-31T18:45:46Z","updated_at":"2016-01-29T16:07:40Z","pushed_at":"2016-09-08T17:44:19Z","git_url":"git://github.com/Parsimotion/syncer-andreani.git","ssh_url":"git@github.com:Parsimotion/syncer-andreani.git","clone_url":"https://github.com/Parsimotion/syncer-andreani.git","svn_url":"https://github.com/Parsimotion/syncer-andreani","homepage":null,"size":257,"stargazers_count":0,"watchers_count":0,"language":"CoffeeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"development"}},"base":{"label":"Parsimotion:development","ref":"development","sha":"f84b1d9fbf5ce517e7b2726b444751f4c9e9f7e6","user":{"login":"Parsimotion","id":8582957,"avatar_url":"https://avatars.githubusercontent.com/u/8582957?v=3","gravatar_id":"","url":"https://api.github.com/users/Parsimotion","html_url":"https://github.com/Parsimotion","followers_url":"https://api.github.com/users/Parsimotion/followers","following_url":"https://api.github.com/users/Parsimotion/following{/other_user}","gists_url":"https://api.github.com/users/Parsimotion/gists{/gist_id}","starred_url":"https://api.github.com/users/Parsimotion/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Parsimotion/subscriptions","organizations_url":"https://api.github.com/users/Parsimotion/orgs","repos_url":"https://api.github.com/users/Parsimotion/repos","events_url":"https://api.github.com/users/Parsimotion/events{/privacy}","received_events_url":"https://api.github.com/users/Parsimotion/received_events","type":"Organization","site_admin":false},"repo":{"id":41693841,"name":"syncer-andreani","full_name":"Parsimotion/syncer-andreani","owner":{"login":"Parsimotion","id":8582957,"avatar_url":"https://avatars.githubusercontent.com/u/8582957?v=3","gravatar_id":"","url":"https://api.github.com/users/Parsimotion","html_url":"https://github.com/Parsimotion","followers_url":"https://api.github.com/users/Parsimotion/followers","following_url":"https://api.github.com/users/Parsimotion/following{/other_user}","gists_url":"https://api.github.com/users/Parsimotion/gists{/gist_id}","starred_url":"https://api.github.com/users/Parsimotion/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Parsimotion/subscriptions","organizations_url":"https://api.github.com/users/Parsimotion/orgs","repos_url":"https://api.github.com/users/Parsimotion/repos","events_url":"https://api.github.com/users/Parsimotion/events{/privacy}","received_events_url":"https://api.github.com/users/Parsimotion/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Parsimotion/syncer-andreani","description":"Syncer for Andreani","fork":false,"url":"https://api.github.com/repos/Parsimotion/syncer-andreani","forks_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/forks","keys_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/teams","hooks_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/hooks","issue_events_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/issues/events{/number}","events_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/events","assignees_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/assignees{/user}","branches_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/branches{/branch}","tags_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/tags","blobs_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/git/refs{/sha}","trees_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/statuses/{sha}","languages_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/languages","stargazers_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/stargazers","contributors_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/contributors","subscribers_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/subscribers","subscription_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/subscription","commits_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/commits{/sha}","git_commits_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/git/commits{/sha}","comments_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/comments{/number}","issue_comment_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/issues/comments{/number}","contents_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/contents/{+path}","compare_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/merges","archive_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/downloads","issues_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/issues{/number}","pulls_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/pulls{/number}","milestones_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/milestones{/number}","notifications_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/labels{/name}","releases_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/releases{/id}","deployments_url":"https://api.github.com/repos/Parsimotion/syncer-andreani/deployments","created_at":"2015-08-31T18:45:46Z","updated_at":"2016-01-29T16:07:40Z","pushed_at":"2016-09-08T17:44:19Z","git_url":"git://github.com/Parsimotion/syncer-andreani.git","ssh_url":"git@github.com:Parsimotion/syncer-andreani.git","clone_url":"https://github.com/Parsimotion/syncer-andreani.git","svn_url":"https://github.com/Parsimotion/syncer-andreani","homepage":null,"size":257,"stargazers_count":0,"watchers_count":0,"language":"CoffeeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"development"}},"_links":{"self":{"href":"https://api.github.com/repos/Parsimotion/syncer-andreani/pulls/25"},"html":{"href":"https://github.com/Parsimotion/syncer-andreani/pull/25"},"issue":{"href":"https://api.github.com/repos/Parsimotion/syncer-andreani/issues/25"},"comments":{"href":"https://api.github.com/repos/Parsimotion/syncer-andreani/issues/25/comments"},"review_comments":{"href":"https://api.github.com/repos/Parsimotion/syncer-andreani/pulls/25/comments"},"review_comment":{"href":"https://api.github.com/repos/Parsimotion/syncer-andreani/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Parsimotion/syncer-andreani/pulls/25/commits"},"statuses":{"href":"https://api.github.com/repos/Parsimotion/syncer-andreani/statuses/2b3a212cd8d91d055675c96a19b33dea65f1fc17"}}}}
{"actor":{"display_login":"NahuelP"}}