# -*- coding: utf-8 -*-
##############################################################################
#
#    Odoo, Open Source Management Solution
#    Copyright (C) 2016 Prime Consulting SA, Cape Verde (<http://prime.cv>).
#
##############################################################################

from odoo import models, fields, api

class Partner(models.Model):
    _inherit = "res.partner"

    @api.model
    def search(self, args, offset=0, limit=None, order=None, count=False):
        """From Customers list view; show only Partners that are Customers
        From Suppliers list view; show only Partners that are Suppliers
        """
        context = self.env.context
        if 'search_default_customer' in context:
            if not args:
                args = [['customer','=',True]]
            else:
                args.append(['customer', '=', True])

        if 'search_default_supplier' in context:
            if not args:
                args = [['supplier','=',True]]
            else:
                args.append(['supplier', '=', True])

        return super(Partner, self).search(args, offset, limit, order, count)