Skip to content

Conversion from price to price_cents using :with_currency is inaccurate for currencies without subunits #696

Open
@basabin54

Description

@basabin54

This is fairly niche and I have work arounds, but I figured I'd bring this up just in case there is an easy fix

Assuming the following models:

Class Product < ApplicationRecord
  # has attribute currency

  has_many :variants
end
Class Variant < ApplicationRecord
  belongs_to :product

  monetize :price_cents, with_currency: ->(variant) { variant.product.currency }
end

then when creating a variant through the relationship like this assuming a product with currency = "KRW" (South Korean Won - a currency without subunits):

@product.variants.new(price: 20)

I get back a variant with price_cents set to 2000 when it should only be 20 since KRW units and subunits should be equal.

Seems like :price_cents is being converted from :price with the default system currency when the currency through the relationship to product should be used

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions