zipdatev 0.1.3 → 0.1.4
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/lib/zipdatev/invoice.rb +1 -2
- data/lib/zipdatev/validators/consolidation_validator.rb +4 -0
- data/lib/zipdatev/validators/date_range_validator.rb +8 -0
- data/lib/zipdatev/validators/decimal_precision_validator.rb +6 -0
- data/lib/zipdatev/validators/discount_dates_validator.rb +11 -4
- data/lib/zipdatev/validators/payment_conditions_validator.rb +5 -0
- data/lib/zipdatev/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7e98150333d568e203ad3f8bea658bdfed75a411d116ec79e17de683a320c14e
|
|
4
|
+
data.tar.gz: feebaad2cd0de26f16f5d09e1049776a68549618d93fff64f37042ad13f3bb38
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e62f20679ffcc4ab682a7b376944bac39850c15d319e04befbaecf47cb3e2a3305ea40ac07c371a9ddec42f3414a648952c03d63255f8f49b5bbf171d22c59bb
|
|
7
|
+
data.tar.gz: b8c49308ff909e730adb7a2ea664030dfcc501cf8d8179dbea9f9dc0722abb28c0a2b07e25fe0a4b05dbc29f0378510daf4180a22c74b0015ec3a00b6b98cad4
|
data/lib/zipdatev/invoice.rb
CHANGED
|
@@ -45,7 +45,7 @@ module ZipDatev
|
|
|
45
45
|
# discount_payment_date_2: Date.new(2023, 1, 22),
|
|
46
46
|
# due_date: Date.new(2023, 1, 26)
|
|
47
47
|
# )
|
|
48
|
-
# rubocop:disable Metrics/ClassLength
|
|
48
|
+
# rubocop:disable-next Metrics/ClassLength
|
|
49
49
|
class Invoice
|
|
50
50
|
include ActiveModel::Model
|
|
51
51
|
include ActiveModel::Attributes
|
|
@@ -344,5 +344,4 @@ module ZipDatev
|
|
|
344
344
|
attributes.compact.transform_keys(&:to_sym)
|
|
345
345
|
end
|
|
346
346
|
end
|
|
347
|
-
# rubocop:enable Metrics/ClassLength
|
|
348
347
|
end
|
|
@@ -16,6 +16,10 @@ module ZipDatev
|
|
|
16
16
|
# @example Apply to Invoice
|
|
17
17
|
# validates_with ConsolidationValidator
|
|
18
18
|
class ConsolidationValidator < ActiveModel::Validator
|
|
19
|
+
# Validates consolidation rules for multi-line invoices.
|
|
20
|
+
#
|
|
21
|
+
# @param record [Invoice] The invoice record to validate
|
|
22
|
+
# @return [void]
|
|
19
23
|
def validate(record)
|
|
20
24
|
# Only validate if there are line items
|
|
21
25
|
return unless record.respond_to?(:multi_line?) && record.multi_line?
|
|
@@ -14,9 +14,17 @@ require "date"
|
|
|
14
14
|
# @example Allow nil values
|
|
15
15
|
# validates :due_date, date_range: true, allow_nil: true
|
|
16
16
|
class DateRangeValidator < ActiveModel::EachValidator
|
|
17
|
+
# Minimum date accepted by DATEV (matches SQL Server datetime lower bound)
|
|
17
18
|
MIN_DATE = Date.new(1753, 1, 1)
|
|
19
|
+
# Maximum date accepted by DATEV
|
|
18
20
|
MAX_DATE = Date.new(9999, 12, 31)
|
|
19
21
|
|
|
22
|
+
# Validates that the date value falls within the DATEV-allowed range.
|
|
23
|
+
#
|
|
24
|
+
# @param record [Object] The model record being validated
|
|
25
|
+
# @param attribute [Symbol] The attribute name being validated
|
|
26
|
+
# @param value [Date] The date value to validate
|
|
27
|
+
# @return [void]
|
|
20
28
|
def validate_each(record, attribute, value)
|
|
21
29
|
return if value.nil?
|
|
22
30
|
|
|
@@ -17,6 +17,12 @@ require "bigdecimal"
|
|
|
17
17
|
# @example Allow nil values
|
|
18
18
|
# validates :tax, decimal_precision: { places: 2 }, allow_nil: true
|
|
19
19
|
class DecimalPrecisionValidator < ActiveModel::EachValidator
|
|
20
|
+
# Validates that the decimal value has exactly the required number of decimal places.
|
|
21
|
+
#
|
|
22
|
+
# @param record [Object] The model record being validated
|
|
23
|
+
# @param attribute [Symbol] The attribute name being validated
|
|
24
|
+
# @param value [BigDecimal, Numeric] The decimal value to validate
|
|
25
|
+
# @return [void]
|
|
20
26
|
def validate_each(record, attribute, value)
|
|
21
27
|
return if value.nil?
|
|
22
28
|
|
|
@@ -6,16 +6,23 @@ module ZipDatev
|
|
|
6
6
|
module Validators
|
|
7
7
|
# Validates the chronological ordering of discount-related dates.
|
|
8
8
|
#
|
|
9
|
-
#
|
|
9
|
+
# Discount dates must be in a specific order:
|
|
10
10
|
# 1. invoice date < discount_payment_date
|
|
11
11
|
# 2. discount_payment_date < discount_payment_date_2
|
|
12
|
-
# 3. discount_payment_date_2
|
|
12
|
+
# 3. last discount date (discount_payment_date_2, else discount_payment_date) <= due_date
|
|
13
|
+
#
|
|
14
|
+
# The due date may equal the last discount date to support "discount only"
|
|
15
|
+
# terms (e.g. "7 Tage 3 % Skonto") where both fall on the same day.
|
|
13
16
|
#
|
|
14
17
|
# Also validates that delivery_date is not after invoice date.
|
|
15
18
|
#
|
|
16
19
|
# @example Apply to Invoice or LineItem
|
|
17
20
|
# validates_with ZipDatev::Validators::DiscountDatesValidator
|
|
18
21
|
class DiscountDatesValidator < ActiveModel::Validator
|
|
22
|
+
# Validates the chronological ordering of discount-related dates.
|
|
23
|
+
#
|
|
24
|
+
# @param record [Invoice, LineItem] The record to validate
|
|
25
|
+
# @return [void]
|
|
19
26
|
def validate(record)
|
|
20
27
|
validate_delivery_date(record)
|
|
21
28
|
validate_dates_after_invoice(record)
|
|
@@ -63,9 +70,9 @@ module ZipDatev
|
|
|
63
70
|
discount_2 = record.discount_payment_date_2
|
|
64
71
|
discount_1 = record.discount_payment_date
|
|
65
72
|
|
|
66
|
-
if discount_2 && discount_2
|
|
73
|
+
if discount_2 && discount_2 > due_date
|
|
67
74
|
record.errors.add(:due_date, "must be after discount_payment_date_2")
|
|
68
|
-
elsif discount_1 && !discount_2 && discount_1
|
|
75
|
+
elsif discount_1 && !discount_2 && discount_1 > due_date
|
|
69
76
|
record.errors.add(:due_date, "must be after discount_payment_date")
|
|
70
77
|
end
|
|
71
78
|
end
|
|
@@ -19,6 +19,7 @@ module ZipDatev
|
|
|
19
19
|
# @example Apply to Invoice or LineItem
|
|
20
20
|
# validates_with PaymentConditionsValidator
|
|
21
21
|
class PaymentConditionsValidator < ActiveModel::Validator
|
|
22
|
+
# Manual discount fields that are mutually exclusive with payment_conditions_id
|
|
22
23
|
DISCOUNT_FIELDS = %i[
|
|
23
24
|
discount_amount
|
|
24
25
|
discount_percentage
|
|
@@ -29,6 +30,10 @@ module ZipDatev
|
|
|
29
30
|
due_date
|
|
30
31
|
].freeze
|
|
31
32
|
|
|
33
|
+
# Validates that payment_conditions_id and manual discount fields are mutually exclusive.
|
|
34
|
+
#
|
|
35
|
+
# @param record [Invoice, LineItem] The record to validate
|
|
36
|
+
# @return [void]
|
|
32
37
|
def validate(record)
|
|
33
38
|
return unless record.payment_conditions_id
|
|
34
39
|
|
data/lib/zipdatev/version.rb
CHANGED