[IMP] improve methods for counting opportunities, meetings, sale orders, and pickings
bzr revid: rco@openerp.com-20120504145551-66l6wy2qumc59r82
This commit is contained in:
+10
-22
@@ -26,21 +26,14 @@ class res_partner(osv.osv):
|
||||
""" Inherits partner and adds CRM information in the partner form """
|
||||
_inherit = 'res.partner'
|
||||
|
||||
def _opportunity_count(self, cr, uid, ids, field_name, arg, context=None):
|
||||
count = dict.fromkeys(ids, 0)
|
||||
opportunity_pool=self.pool.get('crm.lead')
|
||||
opportunity_ids = opportunity_pool.search(cr, uid, [('partner_id', 'in', ids)])
|
||||
for opportunity in opportunity_pool.browse(cr, uid, opportunity_ids):
|
||||
count[opportunity.partner_id.id] += 1
|
||||
return count
|
||||
|
||||
def _meeting_count(self, cr, uid, ids, field_name, arg, context=None):
|
||||
count = dict.fromkeys(ids, 0)
|
||||
meeting_pool=self.pool.get('crm.meeting')
|
||||
meeting_ids = meeting_pool.search(cr, uid, [('partner_id', 'in', ids)])
|
||||
for meeting in meeting_pool.browse(cr, uid, meeting_ids):
|
||||
count[meeting.partner_id.id] += 1
|
||||
return count
|
||||
def _opportunity_meeting_count(self, cr, uid, ids, field_name, arg, context=None):
|
||||
res = {}
|
||||
for partner in self.browse(cr, uid, ids, context):
|
||||
res[partner.id] = {
|
||||
'opportunity_count': len(partner.opportunity_ids),
|
||||
'meeting_count': len(partner.meeting_ids),
|
||||
}
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
'section_id': fields.many2one('crm.case.section', 'Sales Team'),
|
||||
@@ -50,13 +43,8 @@ class res_partner(osv.osv):
|
||||
'Meetings'),
|
||||
'phonecall_ids': fields.one2many('crm.phonecall', 'partner_id',\
|
||||
'Phonecalls'),
|
||||
'opportunity_count': fields.function(_opportunity_count , type='integer',string="Opportunity"),
|
||||
'meeting_count': fields.function(_meeting_count , type='integer',string="Meeting"),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
'opportunity_count': 0,
|
||||
'meeting_count': 0,
|
||||
'opportunity_count': fields.function(_opportunity_meeting_count, string="Opportunity", type='integer', multi='opp_meet'),
|
||||
'meeting_count': fields.function(_opportunity_meeting_count, string="Meeting", type='integer', multi='opp_meet'),
|
||||
}
|
||||
|
||||
def redirect_partner_form(self, cr, uid, partner_id, context=None):
|
||||
|
||||
@@ -24,19 +24,16 @@ from tools.translate import _
|
||||
|
||||
class res_partner(osv.osv):
|
||||
_inherit = 'res.partner'
|
||||
|
||||
|
||||
def _sale_order_count(self, cr, uid, ids, field_name, arg, context=None):
|
||||
count = dict.fromkeys(ids, 0)
|
||||
sale_order_pool=self.pool.get('sale.order')
|
||||
sale_order_ids = sale_order_pool.search(cr, uid, [('partner_id', 'in', ids)])
|
||||
for sale_order in sale_order_pool.browse(cr, uid, sale_order_ids):
|
||||
count[sale_order.partner_id.id] += 1
|
||||
return count
|
||||
|
||||
res = {}
|
||||
for partner in self.browse(cr, uid, ids, context):
|
||||
res[partner.id] = len(partner.sale_order_ids)
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
'sale_order_count': fields.function(_sale_order_count , type='integer',string="Sale Order"),
|
||||
}
|
||||
_defaults = {
|
||||
'sale_order_count': 0,
|
||||
'sale_order_ids': fields.one2many('sale.order', 'partner_id', 'Quotations and Sale Orders'),
|
||||
'sale_order_count': fields.function(_sale_order_count, string='Sale Order', type='integer'),
|
||||
}
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
+12
-13
@@ -27,15 +27,16 @@ class product_product(osv.osv):
|
||||
_inherit = "product.product"
|
||||
|
||||
def _stock_picking_count(self, cr, uid, ids, field_name, arg, context=None):
|
||||
count = dict.fromkeys(ids, 0)
|
||||
stock_picking_pool=self.pool.get('stock.picking')
|
||||
if field_name == 'reception_count':
|
||||
stock_picking_ids = stock_picking_pool.search(cr, uid, [('move_lines.product_id','in',ids),('type','=','in')])
|
||||
else:
|
||||
stock_picking_ids = stock_picking_pool.search(cr, uid, [('move_lines.product_id','in',ids),('type','=','out')])
|
||||
for stock_picking in stock_picking_pool.browse(cr, uid, stock_picking_ids):
|
||||
count[stock_picking.move_lines[0].product_id.id] += 1
|
||||
return count
|
||||
res = dict([(id, {'reception_count': 0, 'delivery_count': 0}) for id in ids])
|
||||
picking_pool=self.pool.get('stock.picking')
|
||||
picking_ids = picking_pool.search(cr, uid, [('move_lines.product_id', 'in', ids)])
|
||||
for picking in picking_pool.browse(cr, uid, picking_ids, context):
|
||||
field = 'reception_count' if picking.type == 'in' else 'delivery_count'
|
||||
product_ids = set([line.product_id.id for line in picking.move_lines])
|
||||
for product_id in product_ids:
|
||||
if product_id in ids:
|
||||
res[product_id][field] += 1
|
||||
return res
|
||||
|
||||
def get_product_accounts(self, cr, uid, product_id, context=None):
|
||||
""" To get the stock input account, stock output account and stock journal related to product.
|
||||
@@ -342,8 +343,8 @@ class product_product(osv.osv):
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
'reception_count': fields.function(_stock_picking_count , type='integer',string="Reception"),
|
||||
'delivery_count': fields.function(_stock_picking_count , type='integer',string="Delivery"),
|
||||
'reception_count': fields.function(_stock_picking_count, string="Reception", type='integer', multi='pickings'),
|
||||
'delivery_count': fields.function(_stock_picking_count, string="Delivery", type='integer', multi='pickings'),
|
||||
'qty_available': fields.function(_product_available, multi='qty_available',
|
||||
type='float', digits_compute=dp.get_precision('Product UoM'),
|
||||
string='Quantity On Hand',
|
||||
@@ -415,8 +416,6 @@ class product_product(osv.osv):
|
||||
|
||||
_defaults = {
|
||||
'valuation': 'manual_periodic',
|
||||
'reception_count': 0,
|
||||
'delivery_count': 0,
|
||||
}
|
||||
|
||||
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
|
||||
|
||||
Reference in New Issue
Block a user