I am trying to create a method that will assign a random supplier when you place the order.
I know that this is the code that openerp uses to choose the default supplier,
def _get_main_product_supplier(self, cr, uid, product, context=None):
"""Determines the main (best) product supplier for ``product``,
returning the corresponding ``supplierinfo`` record, or False
if none were found. The default strategy is to select the
supplier with the highest priority (i.e. smallest sequence).:param browse_record product: product to supply
:rtype: product.supplierinfo browse_record or False
"""
sellers = [(seller_info.sequence, seller_info)
for seller_info in product.seller_ids or []
if seller_info and isinstance(seller_info.sequence, (int, long))]
return sellers and sellers[0][1] or Falsedef _calc_seller(self, cr, uid, ids, fields, arg, context=None):
result = {}
for product in self.browse(cr, uid, ids, context=context):
main_supplier = self._get_main_product_supplier(cr, uid, product, context=context)
result[product.id] = {
'seller_info_id': main_supplier and main_supplier.id or False,
'seller_delay': main_supplier.delay if main_supplier else 1,
'seller_qty': main_supplier and main_supplier.qty or 0.0,
'seller_id': main_supplier and main_supplier.name.id or False
}
return result
and i need it to change it to choose it randomly.
what is your question?
i need choose a random supplier instead of the one with the highest priority.
I know that this is the code that openerp uses to choose the default supplier, def _get_main_product_supplier(self, cr, uid, product, context=None): """Determines the main (best) product supplier for ``product``, returning the corresponding ``supplierinfo`` record, or False if none were found. The default strategy is to select the supplier with the highest priority (i.e. smallest sequence). :param browse_record product: product to supply :rtype: product.supplierinfo browse_record or False """ sellers = [(seller_info.sequence, seller_info) for seller_info in product.seller_ids or [] if seller_info and isinstance(seller_info.sequence, (int, long))] return sellers and sellers[0][1] or False def _calc_seller(self, cr, uid, ids, fields, arg, context=None): result = {} for product in self.browse(cr, uid, ids, context=context): main_supplier = self._get_main_product_supplier(cr, uid, product, context=context) result[product.id] = { 'seller_info_id': main_supplier and main_supplier.id or False, 'seller_delay': main_supplier.delay if main_supplier else 1, 'seller_qty': main_supplier and main_supplier.qty or 0.0, 'seller_id': main_supplier and main_supplier.name.id or False } return result and i need it to change it to choose it randomly.