smerp-quotation 0.2.0 → 0.2.2
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 +4 -4
- data/.release_history.yml +4 -0
- data/Gemfile.lock +2 -2
- data/lib/smerp/quotation/ar_model/quotation.rb +2 -1
- data/lib/smerp/quotation/ar_model/quotation_item.rb +160 -38
- data/lib/smerp/quotation/calculators/discount_calculator.rb +1 -1
- data/lib/smerp/quotation/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c8ccbdb5928d32132abbd47b040135e7b119765e37357aca2a5decb984d53b9
|
4
|
+
data.tar.gz: '0977180c69458fd15b22787c3a7f169fdf8b2002d0ad636571ba1257b99ec40c'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf286bbbcb7ef09a08acb48ae2f4749e4f2079a5f4866e14116a026e96126383ef96422e9bf14a124e4050def1ca9e6c05aa6c0c619b82a85028a7485e00d7a0
|
7
|
+
data.tar.gz: cff193ff53153f5c892194668afda4bd4c4568a9dc5a187db801a6264d43bf01b4ca4adf690eef6b9a279f9d37962d28a5b65577ac3715a7e026f82512b32f35
|
data/.release_history.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
smerp-quotation (0.2.
|
4
|
+
smerp-quotation (0.2.2)
|
5
5
|
acts_as_list
|
6
6
|
acts_as_tree
|
7
7
|
ca-data_store
|
@@ -148,7 +148,7 @@ GEM
|
|
148
148
|
tzinfo (2.0.5)
|
149
149
|
concurrent-ruby (~> 1.0)
|
150
150
|
wisper (2.0.1)
|
151
|
-
zeitwerk (2.6.
|
151
|
+
zeitwerk (2.6.1)
|
152
152
|
|
153
153
|
PLATFORMS
|
154
154
|
x86_64-linux
|
@@ -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
|
|
@@ -173,6 +258,7 @@ module Smerp
|
|
173
258
|
if self.parent.quantity > 0
|
174
259
|
# for children item that has a parent
|
175
260
|
# update parent line_total
|
261
|
+
self.parent.line_total = self.parent.children.sum(:line_total)
|
176
262
|
self.parent.consolidated_line_total = self.parent.children.sum(:consolidated_line_total)
|
177
263
|
|
178
264
|
# update unit_price since line_total is sum of children's line_total
|
@@ -207,7 +293,9 @@ module Smerp
|
|
207
293
|
# calculate if I'm the source to be embedded into other items
|
208
294
|
recalculate_total_to_destination_quotation_items
|
209
295
|
|
210
|
-
self.quotation.
|
296
|
+
#self.quotation.update_total_from_children
|
297
|
+
|
298
|
+
self.quotation.total = self.quotation.quotation_items.where(["parent_id is null"]).sum(:line_total)
|
211
299
|
self.quotation.total_discount = self.quotation.quotation_items.where(["parent_id is null"]).sum(:discount)
|
212
300
|
self.quotation.total_after_discount = self.quotation.quotation_items.where(["parent_id is null"]).sum(:line_total_after_discount)
|
213
301
|
self.quotation.total_tax = self.quotation.quotation_items.where(["parent_id is null"]).sum(:tax)
|
@@ -217,6 +305,52 @@ module Smerp
|
|
217
305
|
|
218
306
|
end
|
219
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
|
+
|
220
354
|
|
221
355
|
def recalculate
|
222
356
|
|
@@ -224,7 +358,7 @@ module Smerp
|
|
224
358
|
self.line_total = self.quantity * self.unit_price
|
225
359
|
# reset consolidated total and calculate again
|
226
360
|
self.consolidated_line_total = self.line_total
|
227
|
-
|
361
|
+
recalculate_total_from_source_quotation_items
|
228
362
|
end
|
229
363
|
|
230
364
|
if self.discount_changed?
|
@@ -233,6 +367,16 @@ module Smerp
|
|
233
367
|
|
234
368
|
end
|
235
369
|
|
370
|
+
def is_consolidation_destination_item?
|
371
|
+
self.source_quotation_items_link.reload
|
372
|
+
self.source_quotation_items_link.count > 0
|
373
|
+
end
|
374
|
+
|
375
|
+
def is_consolidation_source_item?
|
376
|
+
self.quotation_item_distributions.reload
|
377
|
+
self.quotation_item_distributions.count > 0
|
378
|
+
end
|
379
|
+
|
236
380
|
# recalculate becauase destionation line_total changed
|
237
381
|
# triggered before_save
|
238
382
|
def recalculate_total_from_source_quotation_items
|
@@ -251,7 +395,11 @@ module Smerp
|
|
251
395
|
|
252
396
|
teLogger.debug "Distribution calculation : #{cal.result}"
|
253
397
|
|
254
|
-
|
398
|
+
distAmt = cal.result[Smerp::Quotation::DistributionCalculator::DistributedAmount]
|
399
|
+
|
400
|
+
ttl += distAmt
|
401
|
+
|
402
|
+
srcItm.consolidated_line_total -= distAmt
|
255
403
|
|
256
404
|
iqi.distribution_calculations = YAML.dump(cal.for_storage)
|
257
405
|
iqi.save
|
@@ -259,6 +407,10 @@ module Smerp
|
|
259
407
|
end
|
260
408
|
|
261
409
|
self.consolidated_line_total = ttl
|
410
|
+
# if there is discount calculator defined
|
411
|
+
# this value shall be reset
|
412
|
+
# If there is none, this value should be same as consolidated_line_total
|
413
|
+
self.line_total_after_discount = ttl
|
262
414
|
|
263
415
|
end
|
264
416
|
|
@@ -301,36 +453,6 @@ module Smerp
|
|
301
453
|
|
302
454
|
end
|
303
455
|
|
304
|
-
# item that is being distributed to other
|
305
|
-
# quotation items is being destroyed
|
306
|
-
# Remove those portion from each and every items
|
307
|
-
def remove_total_from_destination_quotation_items
|
308
|
-
|
309
|
-
self.quotation_item_distributions.each do |qid|
|
310
|
-
|
311
|
-
citm = qid.distributed_quotation_item
|
312
|
-
|
313
|
-
next if citm.nil?
|
314
|
-
|
315
|
-
cal = YAML.load(qid.distribution_calculations)
|
316
|
-
extRes = cal.result.clone
|
317
|
-
|
318
|
-
#teLogger.debug "before citm #{citm.inspect} / #{citm.consolidated_line_total}"
|
319
|
-
citm.consolidated_line_total = (citm.consolidated_line_total - extRes[Smerp::Quotation::DistributionCalculator::DistributedAmount])
|
320
|
-
#teLogger.debug "after deduction citm #{citm.inspect} / #{citm.consolidated_line_total}"
|
321
|
-
|
322
|
-
#teLogger.debug "qid : #{qid.inspect}"
|
323
|
-
qid.destroy
|
324
|
-
|
325
|
-
citm.source_quotation_items_link.reload
|
326
|
-
|
327
|
-
citm.save
|
328
|
-
#teLogger.debug "after citm #{citm.inspect} / #{citm.consolidated_line_total}"
|
329
|
-
|
330
|
-
end
|
331
|
-
|
332
|
-
end
|
333
|
-
|
334
456
|
def total_distributed
|
335
457
|
|
336
458
|
ttl = 0.0
|
@@ -546,10 +668,10 @@ module Smerp
|
|
546
668
|
|
547
669
|
|
548
670
|
def distribute_to(distTo, val)
|
549
|
-
|
671
|
+
|
550
672
|
dist = QuotationItemDistribution.new
|
551
673
|
dist.quotation_item = self
|
552
|
-
dist.
|
674
|
+
dist.distributed_quotation_item = distTo
|
553
675
|
cal = Smerp::Quotation::DistributionCalculator.new(val)
|
554
676
|
cal.input_field = :consolidated_line_total
|
555
677
|
dist.distribution_calculations = YAML.dump(cal.for_storage)
|
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.
|
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-
|
11
|
+
date: 2022-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: toolrack
|