add price field renderers
This commit is contained in:
parent
3a015be690
commit
5deb198846
|
@ -34,7 +34,7 @@ from edbob.pyramid import Session
|
||||||
import rattail
|
import rattail
|
||||||
|
|
||||||
|
|
||||||
__all__ = ['UpcFieldRenderer']
|
__all__ = ['PriceFieldRenderer', 'RegularPriceFieldRenderer', 'UpcFieldRenderer']
|
||||||
|
|
||||||
|
|
||||||
class BatchIdFieldRenderer(formalchemy.FieldRenderer):
|
class BatchIdFieldRenderer(formalchemy.FieldRenderer):
|
||||||
|
@ -58,6 +58,56 @@ class BatchIdFieldRenderer(formalchemy.FieldRenderer):
|
||||||
# def render(self, options, **kwargs):
|
# def render(self, options, **kwargs):
|
||||||
|
|
||||||
|
|
||||||
|
class PriceFieldRenderer(formalchemy.fields.FloatFieldRenderer):
|
||||||
|
"""
|
||||||
|
Generic renderer for price (currency) fields.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def render_readonly(self, **kwargs):
|
||||||
|
value = self.raw_value
|
||||||
|
if value is None:
|
||||||
|
return ''
|
||||||
|
return '$ %0.2f' % value
|
||||||
|
|
||||||
|
|
||||||
|
class RegularPriceFieldRenderer(PriceFieldRenderer):
|
||||||
|
"""
|
||||||
|
Custom renderer for the :attr:`rattail.Product.regular_price` field.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def render_readonly(self, **kwargs):
|
||||||
|
prod = self.field.model
|
||||||
|
|
||||||
|
if prod.regular_price and prod.package_price:
|
||||||
|
return '$ %0.2f ($ %0.2f / %u)' % (
|
||||||
|
prod.regular_price, prod.package_price, prod.package_price_quantity)
|
||||||
|
|
||||||
|
elif prod.regular_price:
|
||||||
|
return '$ %0.2f' % prod.regular_price
|
||||||
|
|
||||||
|
elif prod.package_price:
|
||||||
|
return '$ %0.2f / %u' % (
|
||||||
|
prod.package_price, prod.package_price_quantity)
|
||||||
|
|
||||||
|
return ''
|
||||||
|
|
||||||
|
|
||||||
|
class SalePriceFieldRenderer(PriceFieldRenderer):
|
||||||
|
"""
|
||||||
|
Custom renderer for the :attr:`rattail.Product.sale_price` field.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def render_readonly(self, **kwargs):
|
||||||
|
prod = self.field.model
|
||||||
|
|
||||||
|
if prod.sale_price:
|
||||||
|
if prod.sale_price_quantity and prod.sale_price_quantity != 1:
|
||||||
|
return '$ %0.2f / %u' % (
|
||||||
|
prod.sale_price, prod.sale_price_quantity)
|
||||||
|
return '$ %0.2f' % prod.sale_price
|
||||||
|
|
||||||
|
return ''
|
||||||
|
|
||||||
|
|
||||||
class UpcFieldRenderer(formalchemy.TextFieldRenderer):
|
class UpcFieldRenderer(formalchemy.TextFieldRenderer):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue