smerp-quotation 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c2cb34cdeb9ad8ef119a801316aa9d874cbd0565f8ad246e91a5311fcae2a8af
4
- data.tar.gz: 944120a5dca8e07e6b1b3f9dcf7724e32c5ca586ffe18fc84bb6a394bf59c4ed
3
+ metadata.gz: 8c8ccbdb5928d32132abbd47b040135e7b119765e37357aca2a5decb984d53b9
4
+ data.tar.gz: '0977180c69458fd15b22787c3a7f169fdf8b2002d0ad636571ba1257b99ec40c'
5
5
  SHA512:
6
- metadata.gz: c9b447f31c94f7fe6ec928556f2e92a85af3569eebc459a0b5efee5041ecab2c70ba8a1c34bc8be9b832839698b0840e1d83bd3f5e0e39ec81ec1236b2cef9fe
7
- data.tar.gz: 1f08fe39a26bd4f74a6598ff4a2d699acd3eee5d431e9e4b9923f418a766cf57516e9378f9f062f1a88d319ca8e9f743695392092845d1417bbfa6286115c450
6
+ metadata.gz: cf286bbbcb7ef09a08acb48ae2f4749e4f2079a5f4866e14116a026e96126383ef96422e9bf14a124e4050def1ca9e6c05aa6c0c619b82a85028a7485e00d7a0
7
+ data.tar.gz: cff193ff53153f5c892194668afda4bd4c4568a9dc5a187db801a6264d43bf01b4ca4adf690eef6b9a279f9d37962d28a5b65577ac3715a7e026f82512b32f35
data/.release_history.yml CHANGED
@@ -4,3 +4,5 @@ smerp-quotation:
4
4
  :timestamp: 1664514502.3722005
5
5
  - :version: 0.2.0
6
6
  :timestamp: 1664783292.2046304
7
+ - :version: 0.2.1
8
+ :timestamp: 1664817326.603613
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- smerp-quotation (0.2.1)
4
+ smerp-quotation (0.2.2)
5
5
  acts_as_list
6
6
  acts_as_tree
7
7
  ca-data_store
@@ -100,9 +100,10 @@ module Smerp
100
100
  end
101
101
 
102
102
  def recalculate
103
- # call by calculator after processing
103
+ # call by calculator after rounding
104
104
  end
105
105
 
106
+
106
107
  end # class Quotation
107
108
  end
108
109
 
@@ -36,8 +36,10 @@ module Smerp
36
36
  before_save :update_total
37
37
  after_save :update_group_total, :update_quotation_total
38
38
 
39
- before_destroy :update_total
40
- after_destroy :update_group_total, :update_quotation_total, :remove_total_from_destination_quotation_items
39
+ #before_destroy :update_total, :update_group_total, :update_quotation_total, :remove_total_from_destination_quotation_items
40
+ #after_destroy :update_group_total, :update_quotation_total, :remove_total_from_destination_quotation_items
41
+ #after_destroy :update_quotation_total, :remove_total_from_destination_quotation_items
42
+ around_destroy :destroy_hook
41
43
 
42
44
  def update_total
43
45
 
@@ -158,9 +160,92 @@ module Smerp
158
160
 
159
161
  end
160
162
 
163
+ # Only for destroy operation
164
+ def destroy_hook
165
+
166
+ parent = self.parent.clone
167
+ qi_dist = self.quotation_item_distributions
168
+ quotation = self.quotation
169
+
170
+ # record deleteion here
171
+ yield
172
+
173
+ if not parent.nil?
174
+
175
+ if parent.is_children_linked?
176
+
177
+ teLogger.debug "Parent #{parent.inspect} IS children linked"
178
+ #
179
+ # Children of another QuotationItem
180
+ #
181
+ if parent.quantity > 0
182
+ # for children item that has a parent
183
+ # update parent line_total
184
+ parent.line_total = parent.children.sum(:line_total)
185
+ parent.consolidated_line_total = parent.children.sum(:consolidated_line_total)
186
+
187
+ # update unit_price since line_total is sum of children's line_total
188
+ parent.unit_price = parent.consolidated_line_total / parent.quantity
189
+
190
+ parent.discount = parent.children.sum(:discount)
191
+ parent.line_total_after_discount = parent.children.sum(:line_total_after_discount)
192
+ parent.tax = parent.children.sum(:tax)
193
+ parent.line_total_with_tax = parent.children.sum(:line_total_with_tax)
194
+
195
+ #teLogger.debug "After update from children : #{self.parent.inspect}"
196
+
197
+ else
198
+
199
+ parent.line_total = 0.0
200
+ parent.consolidated_line_total = 0.0
201
+ parent.unit_price = 0.0
202
+ parent.discount = 0.0
203
+ parent.line_total_after_discount = 0.0
204
+ parent.tax = 0.0
205
+ parent.line_total_with_tax = 0.0
206
+ end
207
+
208
+ parent.save
209
+
210
+ else
211
+ teLogger.debug "Parent #{parent.inspect} is NOT children linked. Skipping children update to parent."
212
+ end
213
+
214
+ end # if parent exist
215
+
216
+ # remove the distributed figure from other record if this record is the source item
217
+ qi_dist.each do |qid|
218
+
219
+ citm = qid.distributed_quotation_item
220
+
221
+ next if citm.nil?
222
+
223
+ cal = YAML.load(qid.distribution_calculations)
224
+ extRes = cal.result.clone
225
+
226
+ citm.consolidated_line_total = (citm.consolidated_line_total - extRes[Smerp::Quotation::DistributionCalculator::DistributedAmount])
227
+
228
+ qid.destroy
229
+
230
+ citm.source_quotation_items_link.reload
231
+
232
+ citm.save
233
+
234
+ end
235
+
236
+ quotation.total = quotation.quotation_items.where(["parent_id is null"]).sum(:line_total)
237
+ quotation.total_discount = quotation.quotation_items.where(["parent_id is null"]).sum(:discount)
238
+ quotation.total_after_discount = quotation.quotation_items.where(["parent_id is null"]).sum(:line_total_after_discount)
239
+ quotation.total_tax = quotation.quotation_items.where(["parent_id is null"]).sum(:tax)
240
+ quotation.total_with_tax = quotation.quotation_items.where(["parent_id is null"]).sum(:line_total_with_tax)
241
+
242
+ quotation.save
243
+
244
+ end
245
+
161
246
  def update_quotation_total
162
247
 
163
- if not self.parent.nil?
248
+ if not self.parent.nil?
164
249
 
165
250
  self.parent.reload
166
251
 
@@ -208,6 +293,8 @@ module Smerp
208
293
  # calculate if I'm the source to be embedded into other items
209
294
  recalculate_total_to_destination_quotation_items
210
295
 
296
+ #self.quotation.update_total_from_children
297
+
211
298
  self.quotation.total = self.quotation.quotation_items.where(["parent_id is null"]).sum(:line_total)
212
299
  self.quotation.total_discount = self.quotation.quotation_items.where(["parent_id is null"]).sum(:discount)
213
300
  self.quotation.total_after_discount = self.quotation.quotation_items.where(["parent_id is null"]).sum(:line_total_after_discount)
@@ -218,6 +305,52 @@ module Smerp
218
305
 
219
306
  end
220
307
 
308
+ # this called after child is destroy
309
+ def update_self_as_parent
310
+
311
+ self.reload
312
+
313
+ if self.is_children_linked?
314
+
315
+ teLogger.debug "Parent #{self.inspect} IS children linked"
316
+ #
317
+ # Children of another QuotationItem
318
+ #
319
+ if self.quantity > 0
320
+ # for children item that has a parent
321
+ # update parent line_total
322
+ self.line_total = self.children.sum(:line_total)
323
+ self.consolidated_line_total = self.children.sum(:consolidated_line_total)
324
+
325
+ # update unit_price since line_total is sum of children's line_total
326
+ self.unit_price = self.consolidated_line_total / self.quantity
327
+
328
+ self.discount = self.children.sum(:discount)
329
+ self.line_total_after_discount = self.children.sum(:line_total_after_discount)
330
+ self.tax = self.children.sum(:tax)
331
+ self.line_total_with_tax = self.children.sum(:line_total_with_tax)
332
+
333
+ #teLogger.debug "After update from children : #{self.parent.inspect}"
334
+
335
+ else
336
+
337
+ self.line_total = 0.0
338
+ self.consolidated_line_total = 0.0
339
+ self.unit_price = 0.0
340
+ self.discount = 0.0
341
+ self.line_total_after_discount = 0.0
342
+ self.tax = 0.0
343
+ self.line_total_with_tax = 0.0
344
+ end
345
+
346
+ self.save
347
+
348
+ else
349
+ teLogger.debug "Parent #{self.inspect} is NOT children linked. Skipping children update to parent."
350
+ end
351
+
352
+ end
353
+
221
354
 
222
355
  def recalculate
223
356
 
@@ -320,36 +453,6 @@ module Smerp
320
453
 
321
454
  end
322
455
 
323
- # item that is being distributed to other
324
- # quotation items is being destroyed
325
- # Remove those portion from each and every items
326
- def remove_total_from_destination_quotation_items
327
-
328
- self.quotation_item_distributions.each do |qid|
329
-
330
- citm = qid.distributed_quotation_item
331
-
332
- next if citm.nil?
333
-
334
- cal = YAML.load(qid.distribution_calculations)
335
- extRes = cal.result.clone
336
-
337
- #teLogger.debug "before citm #{citm.inspect} / #{citm.consolidated_line_total}"
338
- citm.consolidated_line_total = (citm.consolidated_line_total - extRes[Smerp::Quotation::DistributionCalculator::DistributedAmount])
339
- #teLogger.debug "after deduction citm #{citm.inspect} / #{citm.consolidated_line_total}"
340
-
341
- #teLogger.debug "qid : #{qid.inspect}"
342
- qid.destroy
343
-
344
- citm.source_quotation_items_link.reload
345
-
346
- citm.save
347
- #teLogger.debug "after citm #{citm.inspect} / #{citm.consolidated_line_total}"
348
-
349
- end
350
-
351
- end
352
-
353
456
  def total_distributed
354
457
 
355
458
  ttl = 0.0
@@ -49,7 +49,7 @@ module Smerp
49
49
  end
50
50
 
51
51
  res[:output] = @output_field
52
- mdl.recalculate
52
+ #mdl.recalculate
53
53
  end
54
54
 
55
55
  @result = res
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Smerp
4
4
  module Quotation
5
- VERSION = "0.2.1"
5
+ VERSION = "0.2.2"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smerp-quotation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-03 00:00:00.000000000 Z
11
+ date: 2022-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: toolrack