'Test translation of datatable filter/sorting for fields in
filtered components'

@unittest.skipIf((not current.deployment_settings.has_module('org')), 'org    module    disabled')
def testDataTableFilterWithFilteredComponent(self):

    assertEqual = self.assertEqual
    s3db = current.s3db
    org_organisation = s3db.org_organisation
    org_office_type = s3db.org_office_type
    org_test_office = s3db.org_office.with_alias('org_test_office')
    s3db.add_components('org_organisation', org_office={'name': 'test', 'joinby': 'organisation_id', 'filterby': {'office_type_id': 5}})
    resource = s3db.resource('org_organisation')
    fields = ['id', 'name', 'test.name', 'test.office_type_id$name']
    vars = Storage({'bSortable_0': 'false', 'bSortable_1': 'true', 'bSortable_2': 'true', 'bSortable_3': 'true', 'sSortDir_0': 'asc', 'iSortCol_0': '2', 'sSortDir_1': 'desc', 'iSortCol_1': '3', 'iColumns': '4', 'iSortingCols': '2', 'sSearch': 'test'})
    (searchq, orderby, left) = resource.datatable_filter(fields, vars)
    expected = ((org_organisation.name.lower().like('%test%') | org_test_office.name.lower().like('%test%')) | org_office_type.name.lower().like('%test%'))
    assertEqual(str(searchq), str(expected))
    assertEqual(orderby, 'org_test_office.name    asc,    org_office_type.name    desc')
    del current.model.components['org_organisation']['test']
