'When a inv send record is created then create the send_ref.'

@staticmethod
def inv_send_onaccept(form):

    db = current.db
    vars = form.vars
    id = vars.id
    type = vars.type
    if type:
        inv_track_item_onaccept = current.s3db.inv_track_item_onaccept
        site_id = vars.site_id
        itable = db.inv_inv_item
        tracktable = db.inv_track_item
        query = ((itable.site_id == site_id) & (itable.status == int(type)))
        rows = db(query).select()
        for row in rows:
            if (row.quantity != 0):
                inv_track_id = tracktable.insert(send_id=id, send_inv_item_id=row.id, item_id=row.item_id, quantity=row.quantity, currency=row.currency, pack_value=row.pack_value, expiry_date=row.expiry_date, owner_org_id=row.owner_org_id, supply_org_id=row.supply_org_id, item_source_no=row.item_source_no, item_pack_id=row.item_pack_id, inv_item_status=row.status)
                vars = Storage()
                vars.id = inv_track_id
                vars.quantity = row.quantity
                vars.item_pack_id = row.item_pack_id
                vars.send_inv_item_id = row.id
                inv_track_item_onaccept(Storage(vars=vars))
    stable = db.inv_send
    record = stable[id]
    if (not record.send_ref):
        code = current.s3db.supply_get_shipping_code(current.deployment_settings.get_inv_send_shortname(), record.site_id, stable.send_ref)
        db((stable.id == id)).update(send_ref=code)
