Skip to content

Commit

Permalink
Merge pull request solidusio#503 from athal7/update-null-line-items-p…
Browse files Browse the repository at this point in the history
…re-tax-amounts

Also backfill spree_line_items pre_tax_amount for impending null constraint.
  • Loading branch information
Andrew Thal committed Nov 13, 2015
2 parents 6eb08a0 + 575b6b2 commit b97a374
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ def change
WHERE pre_tax_amount IS NULL;
SQL

# set pre_tax_amount on line_items to discounted_amount - included_tax_total
# so that the null: false option on the line_item pre_tax_amount doesn't generate
# errors.
#
execute(<<-SQL)
UPDATE spree_line_items
SET pre_tax_amount = (price * quantity + promo_total) - included_tax_total
WHERE pre_tax_amount IS NULL;
SQL

change_column :spree_line_items, :pre_tax_amount, :decimal, precision: 12, scale: 4, default: 0.0, null: false
change_column :spree_shipments, :pre_tax_amount, :decimal, precision: 12, scale: 4, default: 0.0, null: false
end
Expand Down

0 comments on commit b97a374

Please sign in to comment.