Created
March 25, 2014 16:54
-
-
Save czj/9766239 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module LineWithTaxes | |
extend ActiveSupport::Concern | |
included do | |
validates_length_of :label, within: 2..254 | |
validates_length_of :comment, within: 0..254, allow_blank: true | |
validates_numericality_of :amount_with_taxes, :amount_without_taxes | |
validates_numericality_of :quantity, minimum: 1, only_integer: true | |
validates_numericality_of :ecotax, minimum: 0 | |
normalize_attributes :label, with: :squish | |
normalize_attributes :comment | |
end | |
# Amount of taxes for each unit of this line (VAT amount = TVA in France) | |
# We don't store percentage to avoid rounding errors | |
def taxes | |
amount_with_taxes - amount_without_taxes | |
end | |
# Total amount of VAT for this line | |
def total_taxes | |
taxes * quantity | |
end | |
# French "TTC" = "toutes taxes comprises" amount for this line | |
def total_with_taxes | |
amount_with_taxes * quantity | |
end | |
# French "HT" = "hors taxes" amount for this line | |
def total_without_taxes | |
amount_without_taxes * quantity | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment