Currency management in Plone

15 Messages Forum Options Options
Embed this topic
Permalink
Wichert Akkerman
Currency management in Plone
Reply Threaded MoreMore options
Print post
Permalink
I just released version 1.0b1 of a new product: simplon.plone.currency.
This is a simple product for Plone 3 that allows you to manage different
currencies in your site: you can add and remove currencies and manage
their conversion rates. It includes a database with description and symbols
for all currencies as well.

By itself this product is not very useful. It is intended to be used
as a component in products that need to use currencies in some way. If
anyone is working on such a product I would love to hear some feedback.

You can find more information and a downloadable package in the
python package index:
http://cheeseshop.python.org/pypi/simplon.plone.currency/1.0b1

Wichert.

--
Wichert Akkerman <wichert@...>    It is simple to make things.
http://www.wiggy.net/                   It is hard to make things simple.

_______________________________________________
Product-Developers mailing list
Product-Developers@...
http://lists.plone.org/mailman/listinfo/product-developers
Hanno Schlichting-2
Re: Currency management in Plone
Reply Threaded MoreMore options
Print post
Permalink
Wichert Akkerman wrote:

> I just released version 1.0b1 of a new product: simplon.plone.currency.
> This is a simple product for Plone 3 that allows you to manage different
> currencies in your site: you can add and remove currencies and manage
> their conversion rates. It includes a database with description and symbols
> for all currencies as well.
>
> By itself this product is not very useful. It is intended to be used
> as a component in products that need to use currencies in some way. If
> anyone is working on such a product I would love to hear some feedback.
>
> You can find more information and a downloadable package in the
> python package index:
> http://cheeseshop.python.org/pypi/simplon.plone.currency/1.0b1

I have looked at it briefly and wonder why you didn't reuse the currency
information available in zope.i18n.locales?

While in Zope2 the current locale is not directly available from
REQUEST.locale as in Zope3, with Plone3 it is available from the portal
globals view (plone.app.layout.globals.portal):

  >>> portal_state = queryMultiAdapter((context, request),
  ...     name=u'plone_portal_state')
  >>> locale = portal_state.locale()

If you don't want to have the locale in the currently negotiated
language you can also get a specific one:

  >>> from zope.i18n.locales import locales
  >>> en = locales.getLocale('en', 'us', None)

  >>> pp len(en.numbers.currencies)
  382

  >>> pp en.numbers.currencies[u'USD'].__dict__
  {'displayName': u'US Dollar',
   'symbol': u'US$',
   'symbolChoice': False,
   'type': u'USD'}

If you use this information for the currency information you can also
get currency names translated into every language for free :)

For an example of the latter you can look at the otherwise a bit hairy
LanguageTableWidget in plone.app.controlpanel.widgets. It defines
self.languages in the __init__ and latter on uses it in the textForValue
method. Basically it uses the key of the language to look it up in the
current locale and gets the displayName for it.

HTH,
Hanno


_______________________________________________
Product-Developers mailing list
Product-Developers@...
http://lists.plone.org/mailman/listinfo/product-developers
Hanno Schlichting-2
Re: Currency management in Plone
Reply Threaded MoreMore options
Print post
Permalink
Hanno Schlichting wrote:

> Wichert Akkerman wrote:
>> I just released version 1.0b1 of a new product: simplon.plone.currency.
>> This is a simple product for Plone 3 that allows you to manage different
>> currencies in your site: you can add and remove currencies and manage
>> their conversion rates. It includes a database with description and symbols
>> for all currencies as well.
>>
>> By itself this product is not very useful. It is intended to be used
>> as a component in products that need to use currencies in some way. If
>> anyone is working on such a product I would love to hear some feedback.
>>
>> You can find more information and a downloadable package in the
>> python package index:
>> http://cheeseshop.python.org/pypi/simplon.plone.currency/1.0b1
>
> I have looked at it briefly and wonder why you didn't reuse the currency
> information available in zope.i18n.locales?
>
> While in Zope2 the current locale is not directly available from
> REQUEST.locale as in Zope3, with Plone3 it is available from the portal
> globals view (plone.app.layout.globals.portal):
>
>   >>> portal_state = queryMultiAdapter((context, request),
>   ...     name=u'plone_portal_state')
>   >>> locale = portal_state.locale()
>
> If you don't want to have the locale in the currently negotiated
> language you can also get a specific one:
>
>   >>> from zope.i18n.locales import locales
>   >>> en = locales.getLocale('en', 'us', None)
>
>   >>> pp len(en.numbers.currencies)
>   382
>
>   >>> pp en.numbers.currencies[u'USD'].__dict__
>   {'displayName': u'US Dollar',
>    'symbol': u'US$',
>    'symbolChoice': False,
>    'type': u'USD'}
>
> If you use this information for the currency information you can also
> get currency names translated into every language for free :)
>
> For an example of the latter you can look at the otherwise a bit hairy
> LanguageTableWidget in plone.app.controlpanel.widgets. It defines
> self.languages in the __init__ and latter on uses it in the textForValue
> method. Basically it uses the key of the language to look it up in the
> current locale and gets the displayName for it.

One more thing I forgot to mention. If you want to format some actual
values in the currencies, you might find the following useful:

  >>> from zope.i18n.locales import locales
  >>> nl = locales.getLocale('nl')
  >>> en = locales.getLocale('en')
  >>> nl.numbers.getFormatter('currency').format(1000.14)
  u'\xa4 1.000,14'
  >>> en.numbers.getFormatter('currency').format(1000.14)
  u'\xa41,000.14'

Hanno


_______________________________________________
Product-Developers mailing list
Product-Developers@...
http://lists.plone.org/mailman/listinfo/product-developers
Wichert Akkerman
Re: Currency management in Plone
Reply Threaded MoreMore options
Print post
Permalink
In reply to this post by Hanno Schlichting-2
Previously Hanno Schlichting wrote:

> Wichert Akkerman wrote:
> > I just released version 1.0b1 of a new product: simplon.plone.currency.
> > This is a simple product for Plone 3 that allows you to manage different
> > currencies in your site: you can add and remove currencies and manage
> > their conversion rates. It includes a database with description and symbols
> > for all currencies as well.
> >
> > By itself this product is not very useful. It is intended to be used
> > as a component in products that need to use currencies in some way. If
> > anyone is working on such a product I would love to hear some feedback.
> >
> > You can find more information and a downloadable package in the
> > python package index:
> > http://cheeseshop.python.org/pypi/simplon.plone.currency/1.0b1
>
> I have looked at it briefly and wonder why you didn't reuse the currency
> information available in zope.i18n.locales?

Probably because it had not occured to me. I do notice that the symbol
information in zope.i18n.locales is incorrect for a large number of
currencies which makes it unusable at the moment. However it should
definitely be possible to pull the description for a currency from
there.

I'll see if using zope.i18n.locales is doable.

Wichert.

--
Wichert Akkerman <wichert@...>    It is simple to make things.
http://www.wiggy.net/                   It is hard to make things simple.

_______________________________________________
Product-Developers mailing list
Product-Developers@...
http://lists.plone.org/mailman/listinfo/product-developers
Hanno Schlichting-2
Re: Currency management in Plone
Reply Threaded MoreMore options
Print post
Permalink
Wichert Akkerman wrote:

> Previously Hanno Schlichting wrote:
>> Wichert Akkerman wrote:
>>> I just released version 1.0b1 of a new product: simplon.plone.currency.
>>> This is a simple product for Plone 3 that allows you to manage different
>>> currencies in your site: you can add and remove currencies and manage
>>> their conversion rates. It includes a database with description and symbols
>>> for all currencies as well.
>>>
>>> By itself this product is not very useful. It is intended to be used
>>> as a component in products that need to use currencies in some way. If
>>> anyone is working on such a product I would love to hear some feedback.
>>>
>>> You can find more information and a downloadable package in the
>>> python package index:
>>> http://cheeseshop.python.org/pypi/simplon.plone.currency/1.0b1
>> I have looked at it briefly and wonder why you didn't reuse the currency
>> information available in zope.i18n.locales?
>
> Probably because it had not occured to me. I do notice that the symbol
> information in zope.i18n.locales is incorrect for a large number of
> currencies which makes it unusable at the moment. However it should
> definitely be possible to pull the description for a currency from
> there.

I haven't used the currency part of zope.i18n so far, so I missed the
wrong symbols. When you still want to use the formatting, you can also
set a custom format (or change the default one not to include the
symbol). But the list of all available currencies including their
descriptions and translations might still be interesting.

> I'll see if using zope.i18n.locales is doable.

Re-use not reinvent, love that :)

Hanno

P.S. The locales information in there are based on an ICU version from
2002 or so, so they might be outdated in some areas. I've been meaning
to update that stuff to a current release but had other priorities so far ;)


_______________________________________________
Product-Developers mailing list
Product-Developers@...
http://lists.plone.org/mailman/listinfo/product-developers
Wichert Akkerman
Re: Currency management in Plone
Reply Threaded MoreMore options
Print post
Permalink
Previously Hanno Schlichting wrote:

> Wichert Akkerman wrote:
> > Previously Hanno Schlichting wrote:
> >> Wichert Akkerman wrote:
> >>> I just released version 1.0b1 of a new product: simplon.plone.currency.
> >>> This is a simple product for Plone 3 that allows you to manage different
> >>> currencies in your site: you can add and remove currencies and manage
> >>> their conversion rates. It includes a database with description and symbols
> >>> for all currencies as well.
> >>>
> >>> By itself this product is not very useful. It is intended to be used
> >>> as a component in products that need to use currencies in some way. If
> >>> anyone is working on such a product I would love to hear some feedback.
> >>>
> >>> You can find more information and a downloadable package in the
> >>> python package index:
> >>> http://cheeseshop.python.org/pypi/simplon.plone.currency/1.0b1
> >> I have looked at it briefly and wonder why you didn't reuse the currency
> >> information available in zope.i18n.locales?
> >
> > Probably because it had not occured to me. I do notice that the symbol
> > information in zope.i18n.locales is incorrect for a large number of
> > currencies which makes it unusable at the moment. However it should
> > definitely be possible to pull the description for a currency from
> > there.
>
> I haven't used the currency part of zope.i18n so far, so I missed the
> wrong symbols. When you still want to use the formatting, you can also
> set a custom format (or change the default one not to include the
> symbol). But the list of all available currencies including their
> descriptions and translations might still be interesting.

The only place I have been able to find the symbols so far is
http://www.xe.com/symbols.php.

Wichert.

--
Wichert Akkerman <wichert@...>    It is simple to make things.
http://www.wiggy.net/                   It is hard to make things simple.

_______________________________________________
Product-Developers mailing list
Product-Developers@...
http://lists.plone.org/mailman/listinfo/product-developers
Kai Diefenbach
Re: Currency management in Plone
Reply Threaded MoreMore options
Print post
Permalink
In reply to this post by Wichert Akkerman
Hi Wichert,

Wichert Akkerman <wichert@...>
wrote:

> I just released version 1.0b1 of a new product: simplon.plone.currency.

[snip]

> By itself this product is not very useful. It is intended to be used
> as a component in products that need to use currencies in some way. If
> anyone is working on such a product I would love to hear some feedback.

I'm developing EasyShop (http://plone.org/products/easyshop) at the
moment (it is almost feature complete and will be beta soon). The
currency management is very simple a the moment and has to be
re-thought. Hence this is good news for me and I will definitely take a
look on your product asap.

Bye
Kai

--
Kai Diefenbach - http://diefenba.ch
iqplusplus - http://iqpp.de


_______________________________________________
Product-Developers mailing list
Product-Developers@...
http://lists.plone.org/mailman/listinfo/product-developers
Héctor Velarde
Re: Currency management in Plone
Reply Threaded MoreMore options
Print post
Permalink
In reply to this post by Wichert Akkerman
what about having the currencies updated for other web services?


_______________________________________________
Product-Developers mailing list
Product-Developers@...
http://lists.plone.org/mailman/listinfo/product-developers
Wichert Akkerman
Re: Currency management in Plone
Reply Threaded MoreMore options
Print post
Permalink
Previously Héctor Velarde wrote:
> what about having the currencies updated for other web services?

What do you mean?

Wichert.

--
Wichert Akkerman <wichert@...>    It is simple to make things.
http://www.wiggy.net/                   It is hard to make things simple.

_______________________________________________
Product-Developers mailing list
Product-Developers@...
http://lists.plone.org/mailman/listinfo/product-developers
Hanno Schlichting-2
Re: Currency management in Plone
Reply Threaded MoreMore options
Print post
Permalink
In reply to this post by Hanno Schlichting-2
Hi,

moving this back to product-developers, as this is not about Plone itself ;)

Wichert Akkerman wrote:

> Hanno Schlichting wrote:
>> Wichert Akkerman wrote:
>>> I just released version 1.0b1 of a new product: simplon.plone.currency.
>>> This is a simple product for Plone 3 that allows you to manage different
>>> currencies in your site: you can add and remove currencies and manage
>>> their conversion rates. It includes a database with description and symbols
>>> for all currencies as well.
>>>
>>> By itself this product is not very useful. It is intended to be used
>>> as a component in products that need to use currencies in some way. If
>>> anyone is working on such a product I would love to hear some feedback.
>>>
>>> You can find more information and a downloadable package in the
>>> python package index:
>>> http://cheeseshop.python.org/pypi/simplon.plone.currency/1.0b1
>> I have looked at it briefly and wonder why you didn't reuse the currency
>> information available in zope.i18n.locales?
>>
>> While in Zope2 the current locale is not directly available from
>> REQUEST.locale as in Zope3, with Plone3 it is available from the portal
>> globals view (plone.app.layout.globals.portal):
>>
>>   >>> portal_state = queryMultiAdapter((context, request),
>>   ...     name=u'plone_portal_state')
>>   >>> locale = portal_state.locale()
>
> There is a problem here: I do not have access to the request at the
> place where I would need it. The way the API works is that you have a
> currency object which is stored in a (local) utility. The description is
> a read-only property on that instance.
>
> Forcing users to pass the request in would make for a pretty bad API so
> I do not want to do that. I see one possible option though: create a
> message dynamically. At that point we have the id and we can get the
> English text from zope.i18n.locales, so I can do something like this:
>
>      from zope.i18n.ocales import locales
>
>      english=locales.getLocale("en", "gb", None)
>      return _(self.code, default=english.numbers.currencies[self.code])
>
> that would push the point where the translation machinery is invoked to
> a later point when the request is available. I have not tested this, but
> I am hoping that if I use the Zope message factory this will still
> pickup the correct translation.
>
> Does that sound a bit sane?

Sorry, but this won't work. The information in the locales has nothing
to do with the gettext-based translation machinery. There are no message
factories involved in this.

This means that you cannot mark the currency in the data-centric part of
your code as translatable but you need to take care of it in the
user-visible part which has access to the request. The example I shown
is a Zope3 formlib widget. Other widgets or views can use the same
information.

The basic recipe is to use a distinct key for the info (like u'USD') and
to look up the displayName of this key in the current locale (which is
in the negotiated language).

Hanno


_______________________________________________
Product-Developers mailing list
Product-Developers@...
http://lists.plone.org/mailman/listinfo/product-developers
Jean Jordaan
Re: Currency management in Plone
Reply Threaded MoreMore options
Print post
Permalink
'lo all

Something else to check out:
  http://www.upfrontsystems.co.za/Members/roche/FinanceFields-0.6.tar.gz/view

FinanceFields has code to do maths with amounts without losing cents ..
The svn would be newer, hassle Roché to get it into the collective if
you're interested ;-)

--
jean                                              . .. .... //\\\oo///\\

_______________________________________________
Product-Developers mailing list
Product-Developers@...
http://lists.plone.org/mailman/listinfo/product-developers
Martin Aspeli-2
Re: Currency management in Plone
Reply Threaded MoreMore options
Print post
Permalink
Jean Jordaan wrote:
> 'lo all
>
> Something else to check out:
>   http://www.upfrontsystems.co.za/Members/roche/FinanceFields-0.6.tar.gz/view
>
> FinanceFields has code to do maths with amounts without losing cents ..

You tight man, you...

Martin

--
Acquisition is a jealous mistress


_______________________________________________
Product-Developers mailing list
Product-Developers@...
http://lists.plone.org/mailman/listinfo/product-developers
Héctor Velarde
Re: Currency management in Plone
Reply Threaded MoreMore options
Print post
Permalink
In reply to this post by Wichert Akkerman
Wichert Akkerman wrote:
> Previously Héctor Velarde wrote:
>> what about having the currencies updated for other web services?
>
> What do you mean?

like this one: http://oanda.com/products/fxml/index.shtml


_______________________________________________
Product-Developers mailing list
Product-Developers@...
http://lists.plone.org/mailman/listinfo/product-developers
Kai Diefenbach
Re: Currency management in Plone
Reply Threaded MoreMore options
Print post
Permalink
In reply to this post by Kai Diefenbach
Kai Diefenbach <usenet@...> wrote:

> Wichert Akkerman <wichert@...>
> wrote:
>
> > I just released version 1.0b1 of a new product: simplon.plone.currency.
>
> [snip]
>
> > By itself this product is not very useful. It is intended to be used
> > as a component in products that need to use currencies in some way. If
> > anyone is working on such a product I would love to hear some feedback.
>
> I'm developing EasyShop (http://plone.org/products/easyshop) at the
> moment (it is almost feature complete and will be beta soon). The
> currency management is very simple a the moment and has to be
> re-thought. Hence this is good news for me and I will definitely take a
> look on your product asap.

I checked s.p.c out within a very fresh Plone 3.0 instance using this
buildout:

        http://pastie.textmate.org/91651

After installation via QI I tried to add a new currency and got:

        http://pastie.textmate.org/91650

Kai

--
Kai Diefenbach - http://diefenba.ch
iqplusplus - http://iqpp.de


_______________________________________________
Product-Developers mailing list
Product-Developers@...
http://lists.plone.org/mailman/listinfo/product-developers
Kai Diefenbach
Re: Currency management in Plone
Reply Threaded MoreMore options
Print post
Permalink
In reply to this post by Kai Diefenbach
Hi,

(seems that gmane has swallowed my previous post, so apologize in
advance if it will arrive twice)

Kai Diefenbach <usenet@...> wrote:

> Wichert Akkerman <wichert@...>
> wrote:
>
> > I just released version 1.0b1 of a new product: simplon.plone.currency.
>
> [snip]
>
> > By itself this product is not very useful. It is intended to be used
> > as a component in products that need to use currencies in some way. If
> > anyone is working on such a product I would love to hear some feedback.
>
> I'm developing EasyShop (http://plone.org/products/easyshop) at the
> moment (it is almost feature complete and will be beta soon). The
> currency management is very simple a the moment and has to be
> re-thought. Hence this is good news for me and I will definitely take a
> look on your product asap.

I checked s.p.c out within a very fresh Plone 3.0 instance using this
buildout:

        http://pastie.textmate.org/91651

After installation via QI I tried to add a new currency and got:

        http://pastie.textmate.org/91650

Kai

--
Kai Diefenbach - http://diefenba.ch
iqplusplus - http://iqpp.de


_______________________________________________
Product-Developers mailing list
Product-Developers@...
http://lists.plone.org/mailman/listinfo/product-developers