Changeset d096909 in tailbone


Ignore:
Timestamp:
03/08/19 14:33:57 (6 months ago)
Author:
Lance Edgar <ledgar@…>
Branches:
master
Children:
75bddc8
Parents:
15c47fb
Message:

Expose "true cost" and "true margin" columns for products grid

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tailbone/views/products.py

    r15c47fb rd096909  
    9898        'vendor',
    9999        'cost',
     100        'true_cost',
     101        'true_margin',
    100102        'regular_price',
    101103        'current_price',
     
    235237        g.sorters['vendor'] = g.make_sorter(model.Vendor.name)
    236238
     239        ProductTrueCost = orm.aliased(model.ProductVolatile)
     240        ProductTrueMargin = orm.aliased(model.ProductVolatile)
     241
     242        # true_cost
     243        g.set_joiner('true_cost', lambda q: q.outerjoin(ProductTrueCost))
     244        g.set_filter('true_cost', ProductTrueCost.true_cost)
     245        g.set_sorter('true_cost', ProductTrueCost.true_cost)
     246        g.set_renderer('true_cost', self.render_true_cost)
     247
     248        # true_margin
     249        g.set_joiner('true_margin', lambda q: q.outerjoin(ProductTrueMargin))
     250        g.set_filter('true_margin', ProductTrueMargin.true_margin)
     251        g.set_sorter('true_margin', ProductTrueMargin.true_margin)
     252        g.set_renderer('true_margin', self.render_true_margin)
     253
    237254        # on_hand
    238255        g.set_sorter('on_hand', model.ProductInventory.on_hand)
     
    455472            return ""
    456473        return "${:0.2f}".format(cost.unit_cost)
     474
     475    def render_true_cost(self, product, field):
     476        if not product.volatile:
     477            return ""
     478        if product.volatile.true_cost is None:
     479            return ""
     480        return "${:0.3f}".format(product.volatile.true_cost)
     481
     482    def render_true_margin(self, product, field):
     483        if not product.volatile:
     484            return ""
     485        if product.volatile.true_margin is None:
     486            return ""
     487        return "{:0.3f} %".format(product.volatile.true_margin * 100)
    457488
    458489    def render_on_hand(self, product, column):
Note: See TracChangeset for help on using the changeset viewer.