'Create a Warehouse
@param items: Warehouse(s) to create from the data
@TestDoc: https://docs.google.com/spreadsheet/ccc?key=0AmB3hMcgB-3idG1XNGhhRG9QWF81dUlKLXpJaFlCMFE
@Test Wiki: http://eden.sahanafoundation.org/wiki/DeveloperGuidelines/Testing'

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

    tablename = 'inv_warehouse'
    url = 'inv/warehouse/create'
    account = 'admin'
    data = [[('name', 'Bucharest    RFAAT    Central    Warehouse    (Test)'), ('code', '12345679'), ('organisation_id', 'International    Federation    of    Red    Cross    and    Red    Crescent    Societies'), ('comments', 'This    is    a    Test    Warehouse')]]
    for item in items:
        _data = data[item]
        s3db = current.s3db
        db = current.db
        table = s3db[tablename]
        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:
            print ('inv004_create_warehouse    skipped    as    %s    already    exists    in    the    db\n' % value)
            return False
        self.login(account=account, nexturl=url)
        result = self.create(tablename, _data)
