add progress bar on purchase order tree view
bzr revid: hda@tinyerp.com-20080827112637-lvcujd4wdpted0ry
This commit is contained in:
parent
b8a0b23e64
commit
9e2c13ff15
|
@ -86,6 +86,48 @@ class purchase_order(osv.osv):
|
|||
res[id] = cur_obj.round(cr, uid, cur, untax.get(id, 0.0) + tax.get(id, 0.0))
|
||||
return res
|
||||
|
||||
def _invoiced_rate(self, cursor, user, ids, name, arg, context=None):
|
||||
res = {}
|
||||
for purchase in self.browse(cursor, user, ids, context=context):
|
||||
tot = 0.0
|
||||
|
||||
if purchase.invoice_id.state not in ('draft','cancel'):
|
||||
tot += purchase.invoice_id.amount_untaxed
|
||||
if tot:
|
||||
res[purchase.id] = tot * 100.0 / purchase.amount_untaxed
|
||||
else:
|
||||
res[purchase.id] = 0.0
|
||||
return res
|
||||
|
||||
def _shipped_rate(self, cr, uid, ids, name, arg, context=None):
|
||||
if not ids: return {}
|
||||
res = {}
|
||||
for id in ids:
|
||||
res[id] = [0.0,0.0]
|
||||
cr.execute('''SELECT
|
||||
p.purchase_id,sum(m.product_qty), m.state
|
||||
FROM
|
||||
stock_move m
|
||||
LEFT JOIN
|
||||
stock_picking p on (p.id=m.picking_id)
|
||||
WHERE
|
||||
p.purchase_id in ('''+','.join(map(str,ids))+''')
|
||||
GROUP BY m.state, p.purchase_id''')
|
||||
for oid,nbr,state in cr.fetchall():
|
||||
if state=='cancel':
|
||||
continue
|
||||
if state=='done':
|
||||
res[oid][0] += nbr or 0.0
|
||||
res[oid][1] += nbr or 0.0
|
||||
else:
|
||||
res[oid][1] += nbr or 0.0
|
||||
for r in res:
|
||||
if not res[r][1]:
|
||||
res[r] = 0.0
|
||||
else:
|
||||
res[r] = 100.0 * res[r][0] / res[r][1]
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
'name': fields.char('Order Reference', size=64, required=True, select=True),
|
||||
'origin': fields.char('Origin', size=64),
|
||||
|
@ -108,7 +150,9 @@ class purchase_order(osv.osv):
|
|||
'invoice_id': fields.many2one('account.invoice', 'Invoice', readonly=True),
|
||||
'picking_ids': fields.one2many('stock.picking', 'purchase_id', 'Picking List', readonly=True, help="This is the list of picking list that have been generated for this purchase"),
|
||||
'shipped':fields.boolean('Received', readonly=True, select=True),
|
||||
'shipped_rate': fields.function(_shipped_rate, method=True, string='Received', type='float'),
|
||||
'invoiced':fields.boolean('Invoiced & Paid', readonly=True, select=True),
|
||||
'invoiced_rate': fields.function(_invoiced_rate, method=True, string='Invoiced', type='float'),
|
||||
'invoice_method': fields.selection([('manual','Manual'),('order','From order'),('picking','From picking')], 'Invoicing Control', required=True),
|
||||
|
||||
'amount_untaxed': fields.function(_amount_untaxed, method=True, string='Untaxed Amount'),
|
||||
|
|
|
@ -118,8 +118,8 @@
|
|||
<field name="date_order"/>
|
||||
<field name="partner_id"/>
|
||||
<field name="location_id"/>
|
||||
<field name="invoiced" string="Paid"/>
|
||||
<field name="shipped"/>
|
||||
<field name="invoiced_rate" widget="progressbar"/>
|
||||
<field name="shipped_rate" widget="progressbar"/>
|
||||
<field name="amount_untaxed"/>
|
||||
<field name="origin"/>
|
||||
<field name="state"/>
|
||||
|
|
|
@ -124,7 +124,6 @@ class sale_order(osv.osv):
|
|||
res[oid][1] += nbr or 0.0
|
||||
else:
|
||||
res[oid][1] += nbr or 0.0
|
||||
print res
|
||||
for r in res:
|
||||
if not res[r][1]:
|
||||
res[r] = 0.0
|
||||
|
|
Loading…
Reference in New Issue