'Create an Office
@case: org002
@param items: Office(s) to create from the data
@ToDo: currently optimised for a single record
@TestDoc: https://docs.google.com/spreadsheet/ccc?key=0AmB3hMcgB-3idG1XNGhhRG9QWF81dUlKLXpJaFlCMFE
@Test Wiki: http://eden.sahanafoundation.org/wiki/DeveloperGuidelines/Testing'

def test_org002_create_office(self, items=[0]):

    print '\n'
    tablename = 'org_office'
    url = 'org/office/create'
    account = 'admin'
    data = [[('name', 'Bucharest    RFAAT    Centre    (Test)'), ('code', '12345678'), ('organisation_id', 'International    Federation    of    Red    Cross    and    Red    Crescent    Societies'), ('office_type_id', 'Headquarters'), ('comments', 'This    is    a    Test    Office'), ('L0', 'Romania', 'gis_location'), ('street', '102    Diminescu    St', 'gis_location')]]
    db = current.db
    s3db = current.s3db
    table = s3db[tablename]
    for item in items:
        _data = data[item]
        fieldname = _data[0][0]
        value = _data[0][1]
        query = ((table[fieldname] == value) & (table.deleted == 'F'))
        record = db(query).select(table.id, limitby=(0, 1)).first()
        if record:
            debug = ('org_create_office    skipped    as    %s    already    exists    in    the    db\n' % value)
            print debug
            self.s3_debug(debug)
            return False
        self.login(account=account, nexturl=url)
        result = self.create(tablename, _data)
