lucadeal 0.2.18 → 0.2.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d8159099446dcdae1b4c928d4eac5861cd35fe13f8d37155cdf28dafb30fc21e
4
- data.tar.gz: 3c086a2ea6c4c9ec6bc9014fa9500ab9fde0a07c1778a5817fbb64e7409b5670
3
+ metadata.gz: 36ce9f92d92079f0049ec346da2921116e7cde669314bccca3653c28dca33b51
4
+ data.tar.gz: b2f591e9bfb9710fa45cdb1d3582f19997d392e84e639531e4b15e77d6b284c7
5
5
  SHA512:
6
- metadata.gz: 0a26cec96f1a0805044470f8710b36b60aacf344bad53527c2a9fd4ff64557a06836e4eefec21f083e0b51bc48a9854dbe2fdd6fed4d4754aba9fe51fa5890ce
7
- data.tar.gz: 8a611e016833673fb1e7fcab747a24d4bfdb4152a60086791a1377d8576feb181255c8b2a0dfeca2f6807a4d11d4d2f579be6353ca62a7996a5f960d8b4f1311
6
+ metadata.gz: 8e2ca7f2a7063d44d29013cdd7448f807c58dbabca341cdeb1a8a118e24ca826ca94ac608f1c4a56eb16cb41cb039a0b39d2b07cb011fdd4a57e4b04c24a7d92
7
+ data.tar.gz: 692b888b1209de7fa6329ffbc7edd1ef7ad84be530b2dad7fcaad64b5c621d0da424e3ac90f21e9db7113057599497c91b61d70f479cf48bdea6bee2c49e1f0e
@@ -1,3 +1,8 @@
1
+ ## LucaDeal 0.2.19
2
+
3
+ * CLI id completion on Customer delete, Contract create/delete
4
+ * add `describe` to Customer / Contract
5
+
1
6
  ## LucaDeal 0.2.18
2
7
 
3
8
  * Breaking change: restructure CLI in sub-sub command format.
@@ -18,12 +18,41 @@ module LucaCmd
18
18
  end
19
19
  end
20
20
 
21
- def self.delete(args = nil, params = {})
22
- if args
23
- id = LucaDeal::Customer.delete(args[0])
21
+ def self.describe(args = nil, params = {})
22
+ if args.empty?
23
+ list = LucaDeal::Customer.id_completion('')
24
+ puts 'requires customer\'s id. exit'
25
+ list.each { |item| puts " #{item[:id]} #{item[:label]}" }
26
+ exit 1
24
27
  else
28
+ list = LucaDeal::Customer.id_completion(args[0])
29
+ case list.length
30
+ when 1
31
+ id = LucaDeal::Customer.new.describe(list.first)
32
+ else
33
+ puts 'found multiple contract id. exit'
34
+ list.each { |item| puts " #{item[:id]} #{item[:label]}" }
35
+ exit 1
36
+ end
37
+ end
38
+ end
39
+
40
+ def self.delete(args = nil, params = {})
41
+ if args.empty?
42
+ list = LucaDeal::Customer.id_completion('')
25
43
  puts 'requires customer\'s id. exit'
44
+ list.each { |item| puts " #{item[:id]} #{item[:label]}" }
26
45
  exit 1
46
+ else
47
+ list = LucaDeal::Customer.id_completion(args[0])
48
+ case list.length
49
+ when 1
50
+ id = LucaDeal::Customer.delete(list.first)
51
+ else
52
+ puts 'found multiple customer\'s id. exit'
53
+ list.each { |item| puts " #{item[:id]} #{item[:label]}" }
54
+ exit 1
55
+ end
27
56
  end
28
57
  end
29
58
 
@@ -34,22 +63,61 @@ module LucaCmd
34
63
 
35
64
  class Contract
36
65
  def self.create(args = nil, params = {})
37
- if args
38
- id = LucaDeal::Contract.new.generate!(args[0], params['category'])
39
- puts "Successfully generated Contract #{id}" if id
40
- puts 'Conditions are tentative. Edit contract detail.' if id
41
- else
66
+ if args.empty?
67
+ list = LucaDeal::Customer.id_completion('')
42
68
  puts 'requires customer\'s id. exit'
69
+ list.each { |item| puts " #{item[:id]} #{item[:label]}" }
43
70
  exit 1
71
+ else
72
+ list = LucaDeal::Customer.id_completion(args[0])
73
+ case list.length
74
+ when 1
75
+ id = LucaDeal::Contract.new.generate!(list.first, params['category'])
76
+ puts "Successfully generated Contract #{id}" if id
77
+ puts 'Conditions are tentative. Edit contract detail.' if id
78
+ else
79
+ puts 'found multiple customer\'s id. exit'
80
+ list.each { |item| puts " #{item[:id]} #{item[:label]}" }
81
+ exit 1
82
+ end
44
83
  end
45
84
  end
46
85
 
47
- def self.delete(args = nil, params = {})
48
- if args
49
- id = LucaDeal::Contract.delete(args[0])
86
+ def self.describe(args = nil, params = {})
87
+ if args.empty?
88
+ list = LucaDeal::Contract.id_completion('', label: 'customer_name')
89
+ puts 'requires contract id. exit'
90
+ list.each { |item| puts " #{item[:id]} #{item[:label]}" }
91
+ exit 1
50
92
  else
93
+ list = LucaDeal::Contract.id_completion(args[0])
94
+ case list.length
95
+ when 1
96
+ id = LucaDeal::Contract.new.describe(list.first)
97
+ else
98
+ puts 'found multiple contract id. exit'
99
+ list.each { |item| puts " #{item[:id]} #{item[:label]}" }
100
+ exit 1
101
+ end
102
+ end
103
+ end
104
+
105
+ def self.delete(args = nil, params = {})
106
+ if args.empty?
107
+ list = LucaDeal::Contract.id_completion('', label: 'customer_name')
51
108
  puts 'requires contract id. exit'
109
+ list.each { |item| puts " #{item[:id]} #{item[:label]}" }
52
110
  exit 1
111
+ else
112
+ list = LucaDeal::Contract.id_completion(args[0])
113
+ case list.length
114
+ when 1
115
+ id = LucaDeal::Contract.delete(list.first)
116
+ else
117
+ puts 'found multiple contract id. exit'
118
+ list.each { |item| puts " #{item[:id]} #{item[:label]}" }
119
+ exit 1
120
+ end
53
121
  end
54
122
  end
55
123
  end
@@ -128,10 +196,19 @@ when /customers?/
128
196
  args = opt.parse(ARGV)
129
197
  LucaCmd::Customer.create(args, params)
130
198
  end
199
+ when 'describe'
200
+ LucaCmd::Customer.describe(ARGV)
131
201
  when 'delete'
132
202
  LucaCmd::Customer.delete(ARGV)
133
203
  else
134
- puts 'Usage: luca-deal customers sub-commands'
204
+ puts 'Proper subcommand needed.'
205
+ puts
206
+ puts 'Usage: luca-deal customer[s] subcommands [--help|options]'
207
+ puts ' create'
208
+ puts ' list'
209
+ puts ' describe: show customer with contracts info'
210
+ puts ' delete'
211
+ exit 1
135
212
  end
136
213
  when /contracts?/
137
214
  subcmd = ARGV.shift
@@ -145,10 +222,18 @@ when /contracts?/
145
222
  args = opt.parse(ARGV)
146
223
  LucaCmd::Contract.create(args, params)
147
224
  end
225
+ when 'describe'
226
+ LucaCmd::Contract.describe(ARGV)
148
227
  when 'delete'
149
228
  LucaCmd::Contract.delete(ARGV)
150
229
  else
151
- puts 'Usage: luca-deal contracts Subcommand'
230
+ puts 'Proper subcommand needed.'
231
+ puts
232
+ puts 'Usage: luca-deal contract[s] subcommand [--help|options]'
233
+ puts ' create'
234
+ puts ' describe: show contract with puroducts or items info'
235
+ puts ' delete'
236
+ exit 1
152
237
  end
153
238
  when 'export'
154
239
  LucaCmd::Invoice.export(ARGV)
@@ -158,7 +243,7 @@ when /invoices?/, 'i'
158
243
  when 'create'
159
244
  OptionParser.new do |opt|
160
245
  opt.banner = 'Usage: luca-deal invoices create [options] year month [date]'
161
- opt.on('--monthly', 'generate monthly data') { |v| params['mode'] = 'monthly' }
246
+ opt.on('--monthly', 'generate monthly data') { |_v| params['mode'] = 'monthly' }
162
247
  args = opt.parse(ARGV)
163
248
  LucaCmd::Invoice.create(args, params)
164
249
  end
@@ -173,23 +258,35 @@ when /invoices?/, 'i'
173
258
  when 'mail'
174
259
  OptionParser.new do |opt|
175
260
  opt.banner = 'Usage: luca-deal invoices mail [options] year month [date]'
176
- opt.on('--preview', 'send to preview user') { |v| params['mode'] = 'preview' }
261
+ opt.on('--preview', 'send to preview user') { |_v| params['mode'] = 'preview' }
177
262
  args = opt.parse(ARGV)
178
263
  LucaCmd::Invoice.mail(args, params)
179
264
  end
180
265
  else
181
- puts 'Usage: luca-deal invoices SubCommand'
266
+ puts 'Proper subcommand needed.'
267
+ puts
268
+ puts 'Usage: luca-deal invoices subcommand [--help|options]'
269
+ puts ' create'
270
+ puts ' delete'
271
+ puts ' list'
272
+ puts ' mail: send mail with invoice'
273
+ exit 1
182
274
  end
183
275
  when 'new'
184
276
  params = {}
185
277
  OptionParser.new do |opt|
278
+ opt.banner = 'Usage: luca-deal new DIR'
186
279
  args = opt.parse(ARGV)
187
280
  new_pj(args, params)
188
281
  end
189
282
  else
190
- puts 'Usage: luca-deal sub-command [--help|options]'
283
+ puts 'Proper subcommand needed.'
284
+ puts
285
+ puts 'Usage: luca-deal subcommand [options]'
191
286
  puts ' customers'
192
287
  puts ' contracts'
193
288
  puts ' invoices'
194
- puts ' export'
289
+ puts ' new: initialize project dir'
290
+ puts ' export: puts invoice data for LucaBook import'
291
+ exit 1
195
292
  end
@@ -43,6 +43,16 @@ module LucaDeal
43
43
  end
44
44
  end
45
45
 
46
+ def describe(id)
47
+ contract = parse_current(self.class.find(id))
48
+ if contract['products']
49
+ contract['products'] = contract['products'].map do |product|
50
+ LucaDeal::Product.find(product['id'])
51
+ end
52
+ end
53
+ YAML.dump(readable(contract)).tap{ |d| puts d }
54
+ end
55
+
46
56
  def generate!(customer_id, mode = 'subscription')
47
57
  LucaDeal::Customer.find(customer_id) do |customer|
48
58
  current_customer = parse_current(customer)
@@ -18,10 +18,25 @@ module LucaDeal
18
18
  end
19
19
 
20
20
  def list_name
21
- list = self.class.all.map { |dat| parse_current(dat) }
21
+ list = self.class.all.map { |dat| parse_current(dat).sort.to_h }
22
22
  YAML.dump(list).tap { |l| puts l }
23
23
  end
24
24
 
25
+ def describe(id)
26
+ customer = parse_current(self.class.find(id))
27
+ contracts = LucaDeal::Contract.all.select { |contract| contract['customer_id'] == customer['id'] }
28
+ if !contracts.empty?
29
+ customer['contracts'] = contracts.map do |c|
30
+ {
31
+ 'id' => c['id'],
32
+ 'effective' => c['terms']['effective'],
33
+ 'defunct' => c['terms']['defunct']
34
+ }
35
+ end
36
+ end
37
+ YAML.dump(readable(customer)).tap{ |d| puts d }
38
+ end
39
+
25
40
  def self.create(obj)
26
41
  raise ':name is required' if obj[:name].nil?
27
42
 
@@ -88,7 +88,8 @@ module LucaDeal
88
88
  'customer' => invoice.dig('customer', 'name'),
89
89
  'subtotal' => amount,
90
90
  'tax' => tax,
91
- 'due' => invoice.dig('due_date')
91
+ 'due' => invoice.dig('due_date'),
92
+ 'mail' => invoice.dig('status')&.select { |a| a.keys.include?('mail_delivered') }&.first
92
93
  }
93
94
  end
94
95
  stat['issue_date'] = scan_date.to_s
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LucaDeal
4
- VERSION = '0.2.18'
4
+ VERSION = '0.2.19'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lucadeal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.18
4
+ version: 0.2.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chuma Takahiro
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-10 00:00:00.000000000 Z
11
+ date: 2020-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lucarecord