'Retrieve the applicable pricelist for a given partner in a given company.
:param company_id: if passed, used for looking up properties,
instead of current user\'s company'

def _get_partner_pricelist(self, partner_id, company_id=None):

    Partner = self.env['res.partner']
    Property = self.env['ir.property'].with_context(force_company=(company_id or self.env.user.company_id.id))
    p = Partner.browse(partner_id)
    pl = Property.get('property_product_pricelist', Partner._name, ('%s,%s' % (Partner._name, p.id)))
    if pl:
        pl = pl[0].id
    if (not pl):
        if p.country_id.code:
            pls = self.env['product.pricelist'].search([('country_group_ids.country_ids.code', '=', p.country_id.code)], limit=1)
            pl = (pls and pls[0].id)
    if (not pl):
        pls = self.env['product.pricelist'].search([('country_group_ids', '=', False)], limit=1)
        pl = (pls and pls[0].id)
    if (not pl):
        prop = Property.get('property_product_pricelist', 'res.partner')
        pl = (prop and prop[0].id)
    if (not pl):
        pls = self.env['product.pricelist'].search([], limit=1)
        pl = (pls and pls[0].id)
    return pl
