stockor 0.1.9 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (313) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/Gemfile.lock +254 -72
  4. data/Guardfile +1 -1
  5. data/README.md +24 -3
  6. data/app.json +28 -0
  7. data/client/skr/Extension.coffee +18 -0
  8. data/client/skr/components/BankAccountFinder.cjsx +34 -0
  9. data/client/skr/components/Currency.cjsx +19 -0
  10. data/client/skr/components/CustomerFinder.cjsx +37 -0
  11. data/client/skr/components/CustomerLink.cjsx +13 -0
  12. data/client/skr/components/CustomerProjectFinder.cjsx +49 -0
  13. data/client/skr/components/GlAccountChooser.cjsx +38 -0
  14. data/client/skr/components/InvoiceFinder.cjsx +37 -0
  15. data/client/skr/components/InvoiceLink.cjsx +13 -0
  16. data/client/skr/components/LocationChooser.cjsx +37 -0
  17. data/client/skr/components/PaymentCategoryFinder.cjsx +34 -0
  18. data/client/skr/components/PrintFormChooser.cjsx +29 -0
  19. data/client/skr/components/SalesOrderFinder.cjsx +38 -0
  20. data/client/skr/components/ScreenControls.cjsx +20 -0
  21. data/client/skr/components/SkuFinder.cjsx +30 -0
  22. data/client/skr/components/SkuLines.cjsx +76 -0
  23. data/client/skr/components/SystemSettings.cjsx +26 -0
  24. data/client/skr/components/TermsChooser.cjsx +40 -0
  25. data/client/skr/components/ToolbarButton.cjsx +7 -0
  26. data/client/skr/components/TotalsLine.cjsx +21 -0
  27. data/client/skr/components/TriStateIcon.cjsx +12 -0
  28. data/client/skr/components/UOMChooser.cjsx +24 -0
  29. data/client/skr/components/UserPreferences.cjsx +30 -0
  30. data/client/skr/components/VendorFinder.cjsx +40 -0
  31. data/client/skr/components/address/Address.cjsx +10 -10
  32. data/client/skr/components/styles.scss +16 -0
  33. data/client/skr/index.js +3 -1
  34. data/client/skr/models/Address.coffee +9 -1
  35. data/client/skr/models/BankAccount.coffee +17 -0
  36. data/client/skr/models/Base.coffee +6 -0
  37. data/client/skr/models/Customer.coffee +17 -10
  38. data/client/skr/models/CustomerProject.coffee +29 -0
  39. data/client/skr/models/GlAccount.coffee +22 -10
  40. data/client/skr/models/GlManualEntry.coffee +4 -2
  41. data/client/skr/models/GlPeriod.coffee +4 -6
  42. data/client/skr/models/GlPosting.coffee +7 -7
  43. data/client/skr/models/GlTransaction.coffee +3 -3
  44. data/client/skr/models/IaLine.coffee +9 -9
  45. data/client/skr/models/IaReason.coffee +4 -4
  46. data/client/skr/models/InvLine.coffee +30 -11
  47. data/client/skr/models/InventoryAdjustment.coffee +8 -6
  48. data/client/skr/models/Invoice.coffee +89 -18
  49. data/client/skr/models/Location.coffee +27 -6
  50. data/client/skr/models/Payment.coffee +36 -0
  51. data/client/skr/models/PaymentCategory.coffee +12 -0
  52. data/client/skr/models/PaymentTerm.coffee +17 -4
  53. data/client/skr/models/PickTicket.coffee +7 -5
  54. data/client/skr/models/PoLine.coffee +15 -15
  55. data/client/skr/models/PoReceipt.coffee +8 -6
  56. data/client/skr/models/PorLine.coffee +11 -11
  57. data/client/skr/models/PricingProvider.coffee +6 -0
  58. data/client/skr/models/PtLine.coffee +13 -13
  59. data/client/skr/models/PurchaseOrder.coffee +11 -9
  60. data/client/skr/models/SalesOrder.coffee +59 -22
  61. data/client/skr/models/Sku.coffee +17 -15
  62. data/client/skr/models/SkuLoc.coffee +14 -9
  63. data/client/skr/models/SkuTran.coffee +10 -10
  64. data/client/skr/models/SkuVendor.coffee +9 -9
  65. data/client/skr/models/SoLine.coffee +27 -20
  66. data/client/skr/models/TimeEntry.coffee +75 -0
  67. data/client/skr/models/Uom.coffee +27 -6
  68. data/client/skr/models/Vendor.coffee +14 -12
  69. data/client/skr/models/VoLine.coffee +11 -11
  70. data/client/skr/models/Voucher.coffee +7 -5
  71. data/client/skr/models/mixins/HasVisibleId.coffee +7 -0
  72. data/client/skr/models/mixins/PrintSupport.coffee +6 -0
  73. data/client/skr/models/mixins/SkuLine.coffee +61 -0
  74. data/client/skr/screens/Commands.coffee +29 -0
  75. data/client/skr/screens/bank-maint/BankMaint.cjsx +43 -0
  76. data/client/skr/screens/bank-maint/index.js +5 -0
  77. data/client/skr/screens/chart-of-accounts/ChartOfAccounts.cjsx +40 -0
  78. data/client/skr/screens/chart-of-accounts/index.js +1 -0
  79. data/client/skr/screens/chart-of-accounts/index.scss +12 -0
  80. data/client/skr/screens/customer-maint/CustomerMaint.cjsx +35 -36
  81. data/client/skr/screens/customer-projects/CustomerProjects.cjsx +70 -0
  82. data/client/skr/screens/customer-projects/index.js +5 -0
  83. data/client/skr/screens/customer-projects/index.scss +25 -0
  84. data/client/skr/screens/fresh-books-import/ApiInfo.cjsx +35 -0
  85. data/client/skr/screens/fresh-books-import/ChooseRecords.cjsx +116 -0
  86. data/client/skr/screens/fresh-books-import/FreshBooksImport.cjsx +31 -0
  87. data/client/skr/screens/fresh-books-import/Import.coffee +52 -0
  88. data/client/skr/screens/fresh-books-import/ViewRecords.cjsx +96 -0
  89. data/client/skr/screens/fresh-books-import/index.js +1 -0
  90. data/client/skr/screens/fresh-books-import/index.scss +39 -0
  91. data/client/skr/screens/gl-accounts/GlAccounts.cjsx +31 -0
  92. data/client/skr/screens/gl-accounts/index.js +5 -0
  93. data/client/skr/screens/gl-transactions/GlTransactions.cjsx +46 -0
  94. data/client/skr/screens/gl-transactions/index.js +1 -0
  95. data/client/skr/screens/gl-transactions/index.scss +12 -0
  96. data/client/skr/screens/invoice/Invoice.cjsx +92 -0
  97. data/client/skr/screens/invoice/Payment.cjsx +28 -0
  98. data/client/skr/screens/invoice/index.js +5 -0
  99. data/client/skr/screens/locations/Locations.cjsx +31 -0
  100. data/client/skr/screens/locations/index.js +5 -0
  101. data/client/skr/screens/payment-category/PaymentCategory.cjsx +28 -0
  102. data/client/skr/screens/payment-category/index.js +5 -0
  103. data/client/skr/screens/payment-category/index.scss +9 -0
  104. data/client/skr/screens/payment-terms/PaymentTerms.cjsx +28 -0
  105. data/client/skr/screens/payment-terms/index.js +5 -0
  106. data/client/skr/screens/payment-terms/index.scss +9 -0
  107. data/client/skr/screens/payments/Payments.cjsx +59 -0
  108. data/client/skr/screens/payments/index.js +5 -0
  109. data/client/skr/screens/sales-order/SalesOrder.cjsx +68 -0
  110. data/client/skr/screens/sales-order/index.js +1 -5
  111. data/client/skr/screens/sku-maint/SkuMaint.cjsx +53 -0
  112. data/client/skr/screens/sku-maint/SkuUomList.cjsx +209 -0
  113. data/client/skr/screens/sku-maint/index.js +2 -5
  114. data/client/skr/screens/sku-maint/index.scss +37 -6
  115. data/client/skr/screens/time-invoicing/TimeInvoicing.cjsx +156 -0
  116. data/client/skr/screens/time-invoicing/index.js +5 -0
  117. data/client/skr/screens/time-invoicing/index.scss +7 -0
  118. data/client/skr/screens/time-tracking/EditEntry.cjsx +54 -0
  119. data/client/skr/screens/time-tracking/Entries.coffee +132 -0
  120. data/client/skr/screens/time-tracking/Header.cjsx +71 -0
  121. data/client/skr/screens/time-tracking/Popover.cjsx +70 -0
  122. data/client/skr/screens/time-tracking/PopoverMiniControls.cjsx +25 -0
  123. data/client/skr/screens/time-tracking/TimeTracking.cjsx +63 -0
  124. data/client/skr/screens/time-tracking/WeekSummary.cjsx +16 -0
  125. data/client/skr/screens/time-tracking/index.js +1 -0
  126. data/client/skr/screens/time-tracking/index.scss +126 -0
  127. data/client/skr/screens/vendor-maint/VendorMaint.cjsx +45 -0
  128. data/client/skr/screens/vendor-maint/index.js +1 -5
  129. data/client/skr/styles.scss +1 -13
  130. data/config/puma.rb +4 -0
  131. data/config/routes.rb +21 -9
  132. data/config/screens.rb +147 -32
  133. data/db/migrate/20140202194700_create_skr_gl_transaction_details.rb +35 -0
  134. data/db/migrate/20140220031800_create_skr_locations.rb +2 -0
  135. data/db/migrate/20140220190836_create_skr_vendors.rb +1 -0
  136. data/db/migrate/20140220203029_create_skr_customers.rb +3 -2
  137. data/db/migrate/20140224034759_create_skr_skus.rb +2 -3
  138. data/db/migrate/20140322223912_create_skr_sales_orders.rb +4 -3
  139. data/db/migrate/20140322223920_create_skr_so_lines.rb +4 -5
  140. data/db/migrate/20140323001446_create_so_details_view.rb +7 -5
  141. data/db/migrate/20140327202209_create_skr_pt_lines.rb +2 -2
  142. data/db/migrate/20140327214000_create_customer_project.rb +16 -0
  143. data/db/migrate/20140327223002_create_time_entries.rb +17 -0
  144. data/db/migrate/20140327224000_create_skr_invoices.rb +5 -1
  145. data/db/migrate/20140327224002_create_skr_inv_lines.rb +3 -1
  146. data/db/migrate/20140422024010_create_skr_inv_details_view.rb +1 -1
  147. data/db/migrate/20151121211323_create_customer_project_details_views.rb +31 -0
  148. data/db/migrate/20160216142845_create_gl_account_balances_view.rb +20 -0
  149. data/db/migrate/20160229002044_create_bank_accounts.rb +18 -0
  150. data/db/migrate/20160229041711_create_payments.rb +33 -0
  151. data/db/migrate/20160307022705_create_create_combined_uom_views.rb +18 -0
  152. data/db/schema.sql +639 -140
  153. data/db/seed/chart_of_accounts.yml +8 -6
  154. data/db/seed/payment_categories.yml +12 -0
  155. data/db/seed/skus.yml +32 -0
  156. data/db/seed.rb +21 -0
  157. data/lib/skr/access_roles.rb +19 -6
  158. data/lib/skr/concerns/has_sku_loc_lines.rb +0 -16
  159. data/lib/skr/concerns/inv_extensions.rb +24 -0
  160. data/lib/skr/concerns/is_sku_loc_line.rb +3 -4
  161. data/lib/skr/concerns/so_extensions.rb +8 -0
  162. data/lib/skr/concerns/visible_id_identifier.rb +1 -1
  163. data/lib/skr/db/migration_helpers.rb +2 -4
  164. data/lib/skr/extension.rb +11 -4
  165. data/lib/skr/handlers/fresh_books_import.rb +20 -0
  166. data/lib/skr/handlers/invoice_from_time_entries.rb +49 -0
  167. data/lib/skr/jobs/fresh_books/base.rb +54 -0
  168. data/lib/skr/jobs/fresh_books/import.rb +151 -0
  169. data/lib/skr/jobs/fresh_books/retrieve.rb +62 -0
  170. data/lib/skr/model.rb +5 -0
  171. data/lib/skr/models/address.rb +1 -1
  172. data/lib/skr/models/bank_account.rb +13 -0
  173. data/lib/skr/models/business_entity.rb +3 -0
  174. data/lib/skr/models/customer.rb +1 -1
  175. data/lib/skr/models/customer_project.rb +22 -0
  176. data/lib/skr/models/gl_account.rb +13 -3
  177. data/lib/skr/models/gl_period.rb +6 -0
  178. data/lib/skr/models/gl_posting.rb +7 -4
  179. data/lib/skr/models/gl_transaction.rb +19 -33
  180. data/lib/skr/models/ia_line.rb +1 -1
  181. data/lib/skr/models/inv_line.rb +33 -15
  182. data/lib/skr/models/invoice.rb +47 -20
  183. data/lib/skr/models/location.rb +7 -1
  184. data/lib/skr/models/payment.rb +49 -0
  185. data/lib/skr/models/payment_category.rb +11 -0
  186. data/lib/skr/models/payment_term.rb +1 -1
  187. data/lib/skr/models/por_line.rb +1 -1
  188. data/lib/skr/models/pt_line.rb +1 -1
  189. data/lib/skr/models/sales_order.rb +9 -9
  190. data/lib/skr/models/sku_loc.rb +1 -1
  191. data/lib/skr/models/sku_tran.rb +6 -11
  192. data/lib/skr/models/so_line.rb +22 -12
  193. data/lib/skr/models/time_entry.rb +36 -0
  194. data/lib/skr/models/uom.rb +11 -10
  195. data/lib/skr/models/user_proxy.rb +1 -1
  196. data/lib/skr/number.rb +25 -0
  197. data/lib/skr/print/form.rb +46 -0
  198. data/lib/skr/print/template.rb +48 -0
  199. data/lib/skr/print.rb +11 -0
  200. data/lib/skr/string.rb +11 -0
  201. data/lib/skr/version.rb +1 -1
  202. data/lib/skr.rb +9 -0
  203. data/spec/fixtures/skr/address.yml +164 -4
  204. data/spec/fixtures/skr/bank_account.yml +8 -0
  205. data/spec/fixtures/skr/customer.yml +30 -4
  206. data/spec/fixtures/skr/customer_project.yml +20 -0
  207. data/spec/fixtures/skr/gl_account.yml +19 -1
  208. data/spec/fixtures/skr/gl_period.yml +3 -0
  209. data/spec/fixtures/skr/gl_posting.yml +22 -1
  210. data/spec/fixtures/skr/gl_transaction.yml +4 -1
  211. data/spec/fixtures/skr/inv_line.yml +35 -0
  212. data/spec/fixtures/skr/invoice.yml +13 -2
  213. data/spec/fixtures/skr/location.yml +5 -0
  214. data/spec/fixtures/skr/payment.yml +10 -0
  215. data/spec/fixtures/skr/payment_category.yml +8 -0
  216. data/spec/fixtures/skr/payment_term.yml +37 -3
  217. data/spec/fixtures/skr/sales_order.yml +12 -1
  218. data/spec/fixtures/skr/sku.yml +78 -1
  219. data/spec/fixtures/skr/sku_loc.yml +42 -1
  220. data/spec/fixtures/skr/sku_tran.yml +24 -1
  221. data/spec/fixtures/skr/so_line.yml +32 -0
  222. data/spec/fixtures/skr/time_entry.yml +82 -0
  223. data/spec/fixtures/skr/uom.yml +52 -1
  224. data/spec/fixtures/skr/vendor.yml +28 -1
  225. data/spec/fixtures/stockor.png +0 -0
  226. data/spec/server/bank_account_spec.rb +10 -0
  227. data/spec/server/customer_project_spec.rb +10 -0
  228. data/spec/server/handlers/invoice_from_time_entries_spec.rb +49 -0
  229. data/spec/server/jobs/fresh_books/import_spec.rb +69 -0
  230. data/spec/server/jobs/fresh_books/retrieve_spec.rb +37 -0
  231. data/spec/server/models/address_spec.rb +4 -3
  232. data/spec/server/models/gl_transaction_spec.rb +3 -3
  233. data/spec/server/models/inv_line_spec.rb +83 -3
  234. data/spec/server/models/invoice_spec.rb +32 -3
  235. data/spec/server/models/payment_spec.rb +40 -0
  236. data/spec/server/models/sales_order_spec.rb +1 -1
  237. data/spec/server/models/so_line_spec.rb +3 -3
  238. data/spec/server/models/spec_helper_spec.rb +1 -1
  239. data/spec/server/payment_spec.rb +10 -0
  240. data/spec/server/print/form_spec.rb +47 -0
  241. data/spec/server/print/template_spec.rb +36 -0
  242. data/spec/server/spec_helper.rb +14 -1
  243. data/spec/server/time_entry_spec.rb +10 -0
  244. data/spec/skr/components/SkuLinesSpec.coffee +61 -0
  245. data/spec/skr/models/BankAccountSpec.coffee +5 -0
  246. data/spec/skr/models/CustomerProjectSpec.coffee +5 -0
  247. data/spec/skr/models/CustomerSpec.coffee +2 -2
  248. data/spec/skr/models/PaymentSpec.coffee +5 -0
  249. data/spec/skr/models/SalesOrderSpec.coffee +21 -5
  250. data/spec/skr/models/SoLineSpec.coffee +7 -2
  251. data/spec/skr/models/TimeEntrySpec.coffee +5 -0
  252. data/spec/skr/screens/bank-maint/BankMaintSpec.coffee +5 -0
  253. data/spec/skr/screens/customer-projects/CustomerProjectsSpec.coffee +5 -0
  254. data/spec/skr/screens/fresh-books-import/FreshBooksImportSpec.coffee +1 -0
  255. data/spec/skr/screens/gl-accounts/GlAccountsSpec.coffee +5 -0
  256. data/spec/skr/screens/invoice/InvoiceSpec.coffee +5 -0
  257. data/spec/skr/screens/locations/LocationsSpec.coffee +5 -0
  258. data/spec/skr/screens/payment-category/PaymentCategorySpec.coffee +5 -0
  259. data/spec/skr/screens/payment-terms/PaymentTermsSpec.coffee +5 -0
  260. data/spec/skr/screens/payments/PaymentsSpec.coffee +5 -0
  261. data/spec/skr/screens/time-invoicing/TimeInvoicingSpec.coffee +5 -0
  262. data/spec/skr/screens/time-tracking/TimeTrackingSpec.coffee +14 -0
  263. data/spec/vcr/freshbooks.yml +698 -0
  264. data/stockor.gemspec +5 -1
  265. data/templates/print/fonts/GnuMICR.otf +0 -0
  266. data/templates/print/layout.tex.erb +39 -0
  267. data/templates/print/packages/booktabs.sty +182 -0
  268. data/templates/print/packages/fancybox.sty +966 -0
  269. data/templates/print/packages/fancyhdr.sty +485 -0
  270. data/templates/print/packages/graphbox.sty +129 -0
  271. data/templates/print/packages/lastpage.sty +283 -0
  272. data/templates/print/packages/lastpage209.sty +70 -0
  273. data/templates/print/packages/marginnote.sty +412 -0
  274. data/templates/print/packages/multirow.sty +159 -0
  275. data/templates/print/packages/rotating.sty +282 -0
  276. data/templates/print/packages/tabu.sty +2557 -0
  277. data/templates/print/packages/textpos.sty +361 -0
  278. data/templates/print/packages/varwidth.sty +318 -0
  279. data/templates/print/partials/address.tex.erb +6 -0
  280. data/templates/print/partials/bill_to_ship_to.tex.erb +13 -0
  281. data/templates/print/partials/header.tex.erb +13 -0
  282. data/templates/print/partials/invoice_paid_state.tex.erb +2 -0
  283. data/templates/print/partials/old/inv_lines_grouping.tex.erb +8 -0
  284. data/templates/print/partials/old/labor_lines_footer.tex.erb +18 -0
  285. data/templates/print/partials/skus_table.tex.erb +32 -0
  286. data/templates/print/partials/skus_table_col_hdr.tex.erb +8 -0
  287. data/templates/print/partials/skus_table_footer.tex.erb +5 -0
  288. data/templates/print/partials/skus_table_group_footer.tex.erb +4 -0
  289. data/templates/print/partials/skus_table_invoice_footer.tex.erb +25 -0
  290. data/templates/print/partials/skus_table_invoice_info_line.tex.erb +16 -0
  291. data/templates/print/partials/skus_table_labor_col_hdr.tex.erb +8 -0
  292. data/templates/print/partials/skus_table_labor_group_footer.tex.erb +7 -0
  293. data/templates/print/partials/skus_table_labor_line.tex.erb +11 -0
  294. data/templates/print/partials/skus_table_line.tex.erb +6 -0
  295. data/templates/print/partials/skus_table_other_charge_lines.tex.erb +7 -0
  296. data/templates/print/partials/so_info_line.tex.erb +14 -0
  297. data/templates/print/types/invoice/default.tex.erb +13 -0
  298. data/templates/print/types/invoice/labor.tex.erb +33 -0
  299. data/templates/print/types/payment/default.tex.erb +64 -0
  300. data/templates/print/types/sales-order/default.tex.erb +8 -0
  301. metadata +252 -15
  302. data/client/skr/components/address/address.html +0 -20
  303. data/client/skr/models/mixins/CodeField.coffee +0 -5
  304. data/client/skr/screens/customer-maint/index.scss +0 -11
  305. data/client/skr/screens/customer-maint/layout.html +0 -32
  306. data/client/skr/screens/sales-order/SalesOrder.coffee +0 -30
  307. data/client/skr/screens/sales-order/index.scss +0 -8
  308. data/client/skr/screens/sales-order/layout.html +0 -30
  309. data/client/skr/screens/sku-maint/SkuMaint.coffee +0 -18
  310. data/client/skr/screens/sku-maint/layout.html +0 -16
  311. data/client/skr/screens/vendor-maint/VendorMaint.coffee +0 -28
  312. data/client/skr/screens/vendor-maint/index.scss +0 -8
  313. data/client/skr/screens/vendor-maint/layout.html +0 -32
@@ -0,0 +1,69 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ class FreshBooksImportSpec < Skr::TestCase
4
+
5
+ def around(&block)
6
+ VCR.use_cassette("freshbooks", VCR_OPTS) do
7
+ block.call
8
+ end
9
+ end
10
+
11
+ def perform_import(options = {})
12
+ Skr::Jobs::FreshBooks::Import.perform_now(
13
+ {
14
+ "domain"=>"testermctest-billing",
15
+ "api_key"=>"ba6642fa8d9b99e113ce0e5a1bf66de0",
16
+ "stage"=>"complete",
17
+ "ignored_ids"=>{
18
+ "clients"=>[], "projects"=>[],
19
+ "invoices"=>[], "time_entries"=>[], "staff"=>[]
20
+ }
21
+ }.merge(options)
22
+ )
23
+ end
24
+
25
+ def test_import
26
+ assert_difference ->{ Skr::Invoice.count }, 1 do
27
+ assert_difference ->{ Skr::Customer.count }, 3 do
28
+ perform_import
29
+ end
30
+ end
31
+ inv = Skr::Invoice.find_by_visible_id('1')
32
+ assert_equal inv.invoice_date.strftime('%Y-%m-%d'), '2016-01-26'
33
+ end
34
+
35
+ def test_invoice_balance
36
+ perform_import
37
+ inv = Skr::Invoice.find_by(visible_id: '1')
38
+ assert_equal 2198.75, inv.total.to_f
39
+ assert inv.fully_paid?
40
+ assert_equal 3, inv.lines.count
41
+ assert_equal 3, inv.lines.map(&:time_entry).compact.length
42
+ end
43
+
44
+ def test_ignored_ids
45
+ perform_import({'ignored_ids'=> {"time_entries" => ['7293'], 'clients' => ['27454'] }})
46
+ assert_nil Skr::TimeEntry.where("options ->>'freshbooks_id' = ?", '7293').first
47
+ assert_nil Customer.where("options ->>'freshbooks_id' = ?", '27454').first
48
+ end
49
+
50
+ def test_user_mappings
51
+ assert_no_difference ->{ Lanes::User.count } do
52
+ perform_import({'user_mappings' => { '1' => '1' }})
53
+ end
54
+ end
55
+
56
+ def test_customer_codes
57
+ customer = skr_customer(:billy)
58
+ assert_difference ->{ Skr::Customer.count }, 2 do
59
+ assert_difference ->{ customer.invoices.count }, 1 do
60
+ perform_import({'customer_codes' => {
61
+ '27454' => 'FOO',
62
+ '14694' => 'GOAT'
63
+ }})
64
+ assert Skr::Customer.find_by_code('FOO')
65
+ end
66
+ end
67
+ end
68
+
69
+ end
@@ -0,0 +1,37 @@
1
+ require_relative '../../spec_helper'
2
+ require 'skr/jobs/fresh_books/retrieve'
3
+
4
+ class FreshBooksRetrieveSpec < Skr::TestCase
5
+
6
+ def around(&block)
7
+ VCR.use_cassette("freshbooks", record: :none) do
8
+ block.call
9
+ end
10
+ end
11
+
12
+ def test_record_retrieval
13
+ job = Skr::Jobs::FreshBooks::Retrieve.perform_now(
14
+ 'testermctest-billing',
15
+ 'ba6642fa8d9b99e113ce0e5a1bf66de0'
16
+ )
17
+ data = job.job_status.data['output']
18
+
19
+ assert_equal ['testermctest@argosity.com'],
20
+ data['staff'].map{|c| c['username'] }
21
+
22
+ assert_equal ["ClientThree", "Organization Two", "Organization One"],
23
+ data['clients'].map{|c| c['organization'] }
24
+
25
+ assert_equal ["Project1", "Project2"],
26
+ data['projects'].map{|c| c['name'] }
27
+
28
+ assert_equal ['0000001'],
29
+ data['invoices'].map{|c| c['number'] }
30
+
31
+ assert_equal ["7293", "7292", "2432", "2430"],
32
+ data['time_entries'].map{|c| c['time_entry_id'] }
33
+
34
+ end
35
+
36
+
37
+ end
@@ -2,9 +2,10 @@ require_relative '../spec_helper'
2
2
 
3
3
  class AddressSpec < Skr::TestCase
4
4
 
5
- it "can be instantiated" do
6
- model = Address.new
7
- model.must_be_instance_of(Address)
5
+
6
+ it "can be converted to plain string" do
7
+ address = skr_address(:hg_billing).to_s(include: [:email,:phone])
8
+ assert_equal(address, "Hansel and Gretel\n499 Julianne Radial\nSouth Timmyville WI, 38200\nschuyler@krajcik.name\n379-772-4947 x945")
8
9
  end
9
10
 
10
11
  end
@@ -2,9 +2,9 @@ require_relative '../spec_helper'
2
2
 
3
3
  class GlTransactionSpec < Skr::TestCase
4
4
 
5
- it "can be instantiated" do
6
- model = GlTransaction.new
7
- model.must_be_instance_of(GlTransaction)
5
+ it "can be queried with details" do
6
+ models = GlTransaction.with_details
7
+ assert models
8
8
  end
9
9
 
10
10
  end
@@ -2,9 +2,89 @@ require_relative '../spec_helper'
2
2
 
3
3
  class InvLineSpec < Skr::TestCase
4
4
 
5
- it "can be instantiated" do
6
- model = InvLine.new
7
- model.must_be_instance_of(InvLine)
5
+ it "adjusts inventory" do
6
+ inv = skr_invoice(:tiny)
7
+ yarn = skr_sku_loc(:yarn_def)
8
+ line = inv.lines.build(:sku_loc => yarn, qty: 2)
9
+ assert_difference ->{ yarn.qty }, -2 do
10
+ assert line.save, 'line failed to save'
11
+ end
8
12
  end
9
13
 
14
+ it "can set price" do
15
+ tp = BigDecimal.new('112.54')
16
+ inv = Invoice.new( location: skr_location(:default), customer: skr_customer( :hubbard ) )
17
+ inv.lines.build(
18
+ sku_loc: skr_sku_loc(:hat_def),
19
+ qty: 1, price: tp
20
+ )
21
+ assert inv.save
22
+ line = inv.lines(true).first
23
+ assert_equal tp, line.price
24
+ assert_equal tp, line.extended_price
25
+ end
26
+
27
+ it "adjusts so_line qty" do
28
+ so = SalesOrder.new(customer: skr_customer(:billy))
29
+ so_line = so.lines.build( sku_loc: skr_sku_loc(:hat_def), qty: 2)
30
+ assert so.save
31
+ assert_equal 2, so_line.qty_allocated
32
+ inv = Invoice.new(sales_order: so)
33
+ inv.lines.from_sales_order!
34
+ assert inv.save
35
+ assert_equal 2, inv.lines.first.qty
36
+ assert_equal 2, so_line.reload.qty_invoiced
37
+ assert_equal 0, so_line.qty_allocated
38
+ end
39
+
40
+ it "posts to GL" do
41
+ inv = skr_invoice(:tiny)
42
+ yarn = skr_sku_loc(:yarn_def)
43
+ line = inv.lines.build(sku_loc: yarn, qty: 2)
44
+ assert_difference ->{ yarn.qty }, -2 do
45
+ assert line.save, 'line failed to save'
46
+ end
47
+ end
48
+
49
+ it "can be reversed" do
50
+ inv = Invoice.new( location: skr_location(:default), customer: skr_customer(:hubbard) )
51
+ line = inv.lines.build( sku_loc: skr_sku_loc(:hat_def), qty: 2, price: 10.0 )
52
+ total = line.total
53
+ account = line.sku.gl_asset_account
54
+ assert_difference ->{ account.trial_balance }, (total * -1) do
55
+ assert inv.save, 'invoice failed to save'
56
+ end
57
+ assert_difference ->{ account.trial_balance }, BigDecimal.new('0.44') do
58
+ line.price -= BigDecimal.new('0.22')
59
+ assert line.save, 'failed to update inv line'
60
+ end
61
+ assert_difference ->{ account.trial_balance }, line.price do
62
+ line.qty -= 1
63
+ assert line.save, 'failed to update inv line'
64
+ end
65
+ end
66
+
67
+ it 'cannot be deleted' do
68
+ line = skr_inv_line(:tiny_hat)
69
+ line.destroy
70
+ assert line.errors.any?
71
+ assert_raise ActiveRecord::RecordNotFound do
72
+ line.reload
73
+ end
74
+ end
75
+
76
+ it 'sets position when set from attributes' do
77
+ inv = Invoice.new( location: skr_location(:default),
78
+ customer: skr_customer( :hubbard ),
79
+ lines_attributes: [
80
+ {sku_loc_id: skr_sku_loc(:hat_def).id, qty: 1, price: 0.22},
81
+ {sku_loc_id: skr_sku_loc(:glove_def).id, qty: 2, price: 1.5},
82
+ {sku_loc_id: skr_sku_loc(:misc_def).id, qty: 3, price: 2.5}
83
+ ])
84
+ assert inv.save, 'invoice failed to save'
85
+ inv.lines.pluck(:qty, :position).each do |qty, position|
86
+ assert_equal(qty.to_i, position, "Line #{qty} does not equal position")
87
+ end
88
+ end
89
+
10
90
  end
@@ -2,9 +2,38 @@ require_relative '../spec_helper'
2
2
 
3
3
  class InvoiceSpec < Skr::TestCase
4
4
 
5
- it "can be instantiated" do
6
- model = Invoice.new
7
- model.must_be_instance_of(Invoice)
5
+ it 'disallows location changes' do
6
+ inv = Skr::Invoice.new(sales_order: skr_sales_order(:tiny))
7
+ assert inv.save, 'failed to save'
8
+ inv.location = skr_location(:surplus)
9
+ refute inv.save
10
+ assert inv.errors[:location].any?
11
+ end
12
+
13
+ it 'cannot be posted to locked period' do
14
+ GlPeriod.create(year: Time.now.year, period: Time.now.month, is_locked: true)
15
+ inv = Skr::Invoice.new(customer: skr_customer(:billy))
16
+ refute inv.save, 'invoice saved even though period was locked'
17
+ assert inv.errors[:invoice_date].any?
18
+ end
19
+
20
+
21
+ it 'groups gl transactions together' do
22
+ inv = Skr::Invoice.new(customer: skr_customer(:billy))
23
+ inv.lines.build(sku_loc: skr_sku_loc(:glove_def), qty: 1, price: 10)
24
+ inv.lines.build(sku_loc: skr_sku_loc(:hat_def), qty: 1, price: 20)
25
+ inv.lines.build(sku_loc: skr_sku_loc(:yarn_def), qty: 1, price: 15)
26
+ ar_account = skr_gl_account(:ar)
27
+ invt_account = skr_gl_account(:inventory)
28
+ assert_difference ->{ ar_account.trial_balance }, BigDecimal.new('45.0') do
29
+ assert_difference ->{ invt_account.trial_balance }, BigDecimal.new('-45.0') do
30
+ assert_difference ->{ SkuTran.count }, 3 do
31
+ assert_difference ->{ GlTransaction.count }, 1 do
32
+ assert inv.save, 'failed to save'
33
+ end
34
+ end
35
+ end
36
+ end
8
37
  end
9
38
 
10
39
  end
@@ -0,0 +1,40 @@
1
+ require_relative '../spec_helper'
2
+
3
+ class PaymentSpec < Skr::TestCase
4
+
5
+ it "can be created" do
6
+ assert Payment.create(
7
+ amount: 42.42,
8
+ name: 'Test One, Two, Three',
9
+ category: skr_payment_category(:labor),
10
+ bank_account: skr_bank_account(:checking),
11
+ notes: 'A test payment'
12
+ ), "failed to create payment"
13
+ end
14
+
15
+ it "posts to general ledger" do
16
+ bank_account = skr_bank_account(:checking)
17
+ category = skr_payment_category(:labor)
18
+
19
+ assert_difference ->{
20
+ category.gl_account.trial_balance
21
+ }, BigDecimal.new('42.42') do
22
+
23
+ assert_difference ->{
24
+ bank_account.gl_account.trial_balance
25
+ }, BigDecimal.new('-42.42') do
26
+
27
+ Payment.create(
28
+ amount: 42.42,
29
+ name: 'Test One, Two, Three',
30
+ category: category,
31
+ bank_account: bank_account,
32
+ notes: 'A test payment'
33
+ )
34
+
35
+ end
36
+ end
37
+
38
+ end
39
+
40
+ end
@@ -6,7 +6,7 @@ class SalesOrderSpec < Skr::TestCase
6
6
  it "can be saved" do
7
7
  user = Lanes::User.find_by(login:'admin')
8
8
  model = SalesOrder.from_attribute_data({
9
- terms_id: skr_payment_term(:cashy).id,
9
+ terms_id: skr_payment_term(:cash).id,
10
10
  location_id: skr_location(:default).id,
11
11
  customer_id: skr_customer(:billy).id,
12
12
  billing_address: {
@@ -2,9 +2,9 @@ require_relative '../spec_helper'
2
2
 
3
3
  class SoLineSpec < Skr::TestCase
4
4
 
5
- it "can be instantiated" do
6
- model = SoLine.new
7
- model.must_be_instance_of(SoLine)
5
+ it "can load uom_choices" do
6
+ line = skr_so_line(:tiny_glove)
7
+ assert_equal ['PR', 'CS' ], line.uom_choices.pluck(:code)
8
8
  end
9
9
 
10
10
  end
@@ -10,7 +10,7 @@ module FixtureHelpers
10
10
  results = table_rows_without_custom_autoset_fields
11
11
  if model_class
12
12
  results[ table_name ].each do | row |
13
- row['visible_id'] = Lanes::SequentialId.next_for( model_class ) if model_class.column_names.include?('visible_id')
13
+ row['visible_id'] ||= Skr::SequentialId.next_for( model_class ) if model_class.column_names.include?('visible_id')
14
14
  row['hash_code' ] = Lanes::Strings.random if model_class.column_names.include?('hash_code')
15
15
  row['created_at'] = Time.now if model_class.column_names.include?('created_at')
16
16
  row['updated_at'] = Time.now if model_class.column_names.include?('updated_at')
@@ -0,0 +1,10 @@
1
+ require_relative 'spec_helper'
2
+
3
+ class PaymentSpec < Skr::TestCase
4
+
5
+ it "can be instantiated" do
6
+ model = Payment.new
7
+ model.must_be_instance_of(Payment)
8
+ end
9
+
10
+ end
@@ -0,0 +1,47 @@
1
+ require_relative '../spec_helper'
2
+
3
+ class PrintSpec < Skr::TestCase
4
+
5
+ # for debugging add a generate(pdf) to one of the specs
6
+ def generate(pdf)
7
+ Lanes::SystemSettings.config.logo = File.open(
8
+ Pathname.new(__FILE__).dirname.join('../../fixtures/stockor.png')
9
+ )
10
+ begin
11
+ File.open('/tmp/skr-test.tex', 'w'){|f| f.write pdf.as_latex }
12
+ File.open('/tmp/skr-test.pdf', 'w'){|f| f.write pdf.as_pdf.read }
13
+ rescue ErbLatex::LatexError=>e
14
+ puts e.log.gsub(/^\*\n/,'')
15
+ assert(false)
16
+ end
17
+ end
18
+
19
+ it "can generate default invoice" do
20
+ inv = skr_invoice(:tiny)
21
+ inv.update_attributes amount_paid: inv.total - 2.22
22
+ assert inv.update_attributes form: 'default'
23
+ pdf = Skr::Print::Form.new('invoice', inv.hash_code)
24
+ assert pdf.as_latex
25
+ end
26
+
27
+ it 'can generate labor invoice' do
28
+ inv = skr_invoice(:tiny)
29
+ assert inv.update_attributes form: 'labor'
30
+ pdf = Skr::Print::Form.new('invoice', inv.hash_code)
31
+ assert pdf.as_latex
32
+ end
33
+
34
+ it 'can generate sales order' do
35
+ so = skr_sales_order(:tiny)
36
+ pdf = Skr::Print::Form.new('sales-order', so.hash_code)
37
+ assert pdf.as_latex
38
+ end
39
+
40
+ it 'can generate checks' do
41
+ pymnt = skr_payment(:bigco)
42
+ pdf = Skr::Print::Form.new('payment', pymnt.hash_code)
43
+ assert pdf.as_latex
44
+ end
45
+
46
+
47
+ end
@@ -0,0 +1,36 @@
1
+ require_relative '../spec_helper'
2
+
3
+ class PrintTemplateSpec < Skr::TestCase
4
+
5
+ let(:template) { Skr::Print::Template.get('sales-order') }
6
+
7
+ it "can list templates" do
8
+ assert_includes Skr::Print::Template.definitions.map(&:name), 'sales-order'
9
+ assert_includes Skr::Print::Template.definitions.map(&:name), 'invoice'
10
+ end
11
+
12
+ it 'lists choices' do
13
+ assert_includes template.choices, 'default'
14
+ end
15
+
16
+ it 'gets model class' do
17
+ assert_equal Skr::SalesOrder, template.model
18
+ end
19
+
20
+ describe 'path' do
21
+
22
+ it 'defaults to "default"' do
23
+ assert_equal Skr::Print::ROOT.join('types','sales-order','default.tex.erb'),
24
+ template.path_for_record(Skr::SalesOrder.first)
25
+ end
26
+
27
+ it 'defaults to default if form doesnt exist' do
28
+ so = Skr::SalesOrder.first
29
+ so.form = 'a-custom-form'
30
+ assert_equal Skr::Print::ROOT.join('types','sales-order','default.tex.erb'),
31
+ template.path_for_record(so)
32
+ end
33
+
34
+ end
35
+
36
+ end
@@ -1,5 +1,7 @@
1
- require_relative '../../lib/stockor'
1
+ require 'skr'
2
2
  require 'lanes/spec_helper'
3
+ require 'webmock/minitest'
4
+ require 'vcr'
3
5
 
4
6
  class Lanes::TestCase
5
7
  include Skr
@@ -39,4 +41,15 @@ module StockorFixtureTestPatches
39
41
  end
40
42
  end
41
43
 
44
+ VCR_OPTS = {
45
+ record: :none
46
+ }
47
+
48
+ VCR.configure do |config|
49
+
50
+ config.cassette_library_dir = "spec/vcr"
51
+ config.hook_into :webmock
52
+ config.allow_http_connections_when_no_cassette = false
53
+ end
54
+
42
55
  ActiveRecord::FixtureSet.send :include, StockorFixtureTestPatches
@@ -0,0 +1,10 @@
1
+ require_relative 'spec_helper'
2
+
3
+ class TimeEntrySpec < Skr::TestCase
4
+
5
+ it "can be instantiated" do
6
+ model = TimeEntry.new
7
+ model.must_be_instance_of(TimeEntry)
8
+ end
9
+
10
+ end
@@ -0,0 +1,61 @@
1
+ renderLines = (props) ->
2
+ new _.Promise (res, rej) ->
3
+ lines = LT.renderComponent(Skr.Components.SkuLines, {props})
4
+ _.delay -> res(lines)
5
+
6
+ LAST_ROW_SELECTOR = '.grid-body .r:last-child'
7
+
8
+ startEdit = (props) ->
9
+ props.screen.setState(isEditing: true)
10
+ new Promise (res, rej) ->
11
+ props.editor = true
12
+ renderLines(props).then (lines) ->
13
+ Lanes.Models.Sync.restorePerform ->
14
+ _.dom(lines).qs(LAST_ROW_SELECTOR).click()
15
+ remaining = 100
16
+ checkRendered = ->
17
+ editors = LT.Utils.scryRenderedComponentsWithType(lines,
18
+ Lanes.Components.Grid.RowEditor)
19
+ if remaining and _.isEmpty(editors)
20
+ remaining -= 1
21
+ console.log remaining
22
+ _.defer(checkRendered)
23
+ else
24
+ res(editor: editors[0], lines: lines)
25
+ checkRendered()
26
+
27
+ describe "Skr.Components.SkuLines", ->
28
+
29
+ beforeEach (done) ->
30
+ screen = LT.makeScreen()
31
+ commands = new Lanes.Screens.Commands(screen, modelName: 'sales_order')
32
+ Lanes.Models.Sync.restorePerform =>
33
+ Skr.Models.SalesOrder.where({visible_id: 1}, include: 'lines')
34
+ .whenLoaded (orders) =>
35
+ @sales_order = orders.first()
36
+ lines = @sales_order.lines
37
+ @props = {lines, commands, screen}
38
+ done()
39
+
40
+ xit "renders lines", (done) ->
41
+ renderLines(@props).then (lines) =>
42
+ expect(_.dom(lines).qsa('.grid-body .r').length).toEqual( @props.lines.length )
43
+ done()
44
+
45
+ # it "displays the editor", (done) ->
46
+ # startEdit(@props).then ({lines, editor}) =>
47
+ # sol = @props.lines.last()
48
+ # expect(_.pluck( _.dom(editor).qsa('input'), 'value'))
49
+ # .toEqual([sol.sku_code, sol.description, sol.uom_code, "#{sol.qty}", sol.price.toString()])
50
+ # done()
51
+
52
+ # it "saves values when edited", (done) ->
53
+ # startEdit(@props).then ({lines, editor}) =>
54
+ # _.dom(editor).qs('input[name=price]').setValue('42.21')
55
+ # _.dom(editor).qs('input[name=qty]').setValue(12)
56
+ # _.dom(editor).qs('button.save').click()
57
+ # _.defer =>
58
+ # sol = @props.lines.last()
59
+ # expect(sol.qty).toEqual(12)
60
+ # expect(sol.price.toString()).toEqual('42.21')
61
+ # done()
@@ -0,0 +1,5 @@
1
+ describe "Skr.Models.BankAccount", ->
2
+
3
+ it "can be instantiated", ->
4
+ model = new Skr.Models.BankAccount()
5
+ expect(model).toEqual(jasmine.any(Skr.Models.BankAccount))
@@ -0,0 +1,5 @@
1
+ describe "Skr.Models.CustomerProject", ->
2
+
3
+ it "can be instantiated", ->
4
+ model = new Skr.Models.CustomerProject()
5
+ expect(model).toEqual(jasmine.any(Skr.Models.CustomerProject))
@@ -3,7 +3,7 @@ describe "Skr.Models.Customer", ->
3
3
  beforeEach ->
4
4
  Lanes.Test.ModelSaver.setUser('admin')
5
5
 
6
- xit "sends failure messages when code isn't set", (done) ->
6
+ it "sends failure messages when code isn't set", (done) ->
7
7
  model = new Skr.Models.Customer()
8
8
  Lanes.Test.ModelSaver.perform(model, done).then (save) ->
9
9
  expect(model.errors?.code).toContain("blank")
@@ -17,4 +17,4 @@ describe "Skr.Models.Customer", ->
17
17
  )
18
18
 
19
19
  Lanes.Test.ModelSaver.perform(model, done).then (save) ->
20
- expect(model.errors).toBeNull()
20
+ expect(model.errors).toBeUndefined()
@@ -0,0 +1,5 @@
1
+ describe "Skr.Models.Payment", ->
2
+
3
+ it "can be instantiated", ->
4
+ model = new Skr.Models.Payment()
5
+ expect(model).toEqual(jasmine.any(Skr.Models.Payment))
@@ -1,7 +1,23 @@
1
1
  describe "Skr.Models.SalesOrder", ->
2
2
 
3
- xit "must have a customer to save", (done)->
4
- model = new Skr.Models.SalesOrder()
5
- Lanes.Test.ModelSaver.perform(model, done).then (save)->
6
- expect(save.error).toHaveBeenCalled()
7
- expect(model.errors.customer).toContain("is not set")
3
+
4
+ it "it calculates total", ->
5
+ so = new Skr.Models.SalesOrder()
6
+ so.lines.add(sku_code: 'TEST', price: 2.12, qty:1)
7
+ expect(so.total).toEqual(jasmine.any(_.bigDecimal))
8
+ expect(so.total.toString()).toEqual('2.12')
9
+ so.order_total = '1.42'
10
+ expect(so.order_total.toString()).toEqual('1.42')
11
+ expect(so.total.toString()).toEqual('1.42')
12
+ expect(so.total).toEqual(jasmine.any(_.bigDecimal))
13
+
14
+ it 'updates total and triggers change when lines change', ->
15
+ so = new Skr.Models.SalesOrder()
16
+ line = so.lines.add(sku_code: 'TEST', price: 2.12, qty:1)
17
+ line.price = 3.42
18
+ expect(so.total.toString()).toEqual('3.42')
19
+ spy = jasmine.createSpy('on change')
20
+ so.on('change', spy)
21
+ line.price = 233.111
22
+ expect(so.total.toString()).toEqual('233.111')
23
+ expect(spy).toHaveBeenCalled()
@@ -1,5 +1,10 @@
1
1
  describe "Skr.Models.SoLine", ->
2
2
 
3
- it "can be instantiated", ->
3
+ it "can sets properties from the uom", ->
4
4
  model = new Skr.Models.SoLine()
5
- expect(model).toEqual(jasmine.any(Skr.Models.SoLine))
5
+ spy = jasmine.createSpy('onuom')
6
+ model.on("change:uom", spy)
7
+ model.set(uom: new Skr.Models.Uom(size: 10, code: 'CS'))
8
+ expect(spy).toHaveBeenCalled()
9
+ expect(model.uom_size).toEqual(10)
10
+ expect(model.uom_code).toEqual('CS')
@@ -0,0 +1,5 @@
1
+ describe "Skr.Models.TimeEntry", ->
2
+
3
+ it "can be instantiated", ->
4
+ model = new Skr.Models.TimeEntry()
5
+ expect(model).toEqual(jasmine.any(Skr.Models.TimeEntry))
@@ -0,0 +1,5 @@
1
+ describe "Skr.Screens.BankMaint", ->
2
+
3
+ it "can be rendered", ->
4
+ screen = LT.renderComponent(Skr.Screens.BankMaint)
5
+ expect(_.dom(screen).text).toMatch("Hello")
@@ -0,0 +1,5 @@
1
+ describe "Skr.Screens.CustomerProjects", ->
2
+
3
+ xit "can be rendered", ->
4
+ screen = LT.renderComponent(Skr.Screens.CustomerProjects)
5
+ expect(screen.getDOMNode().textContent).toMatch("Hello")
@@ -0,0 +1 @@
1
+ describe "Skr.Screens.FreshBooksImport", ->
@@ -0,0 +1,5 @@
1
+ describe "Skr.Screens.GlAccounts", ->
2
+
3
+ it "can be rendered", ->
4
+ screen = LT.renderComponent(Skr.Screens.GlAccounts)
5
+ expect(_.dom(screen).text).toMatch("Hello")
@@ -0,0 +1,5 @@
1
+ describe "Skr.Screens.Invoice", ->
2
+
3
+ it "can be rendered", ->
4
+ screen = LT.renderComponent(Skr.Screens.Invoice)
5
+ expect(screen).toBeTruthy()